MCPcopy Create free account
hub / github.com/Hound-Media-Server/hound / QueueExternalLibraryFile

Function QueueExternalLibraryFile

server/model/external_library.go:45–190  ·  view source on GitHub ↗
(rootPath string, filePath string, mediaType string)

Source from the content-addressed store, hash-verified

43}
44
45func QueueExternalLibraryFile(rootPath string, filePath string, mediaType string) (*database.IngestTask, *ParsedExternalMedia, error) {
46 cleanRoot := filepath.Clean(rootPath)
47 cleanPath := filepath.Clean(filePath)
48 stat, err := os.Stat(cleanPath)
49 if err != nil {
50 return nil, nil, err
51 }
52 if stat.IsDir() || !IsVideoFile(cleanPath) {
53 return nil, nil, fmt.Errorf("not a video file: %w", internal.BadRequestError)
54 }
55 parsed, err := parseExternalMediaPath(cleanRoot, cleanPath, mediaType)
56 if err != nil {
57 return nil, nil, err
58 }
59 var ingestRecordID int64
60 switch parsed.MediaType {
61 case database.MediaTypeMovie:
62 sourceID := -1
63 if parsed.SourceID != "" {
64 sourceID, err = strconv.Atoi(parsed.SourceID)
65 if err != nil || sourceID <= 0 {
66 return nil, parsed, fmt.Errorf("invalid tmdb id in movie folder name tmdb-%s: %w", parsed.SourceID, internal.BadRequestError)
67 }
68 } else {
69 sourceID, err = findBestMovieTMDBID(parsed.Title, parsed.Year)
70 if err != nil {
71 return nil, parsed, err
72 }
73 parsed.SourceID = strconv.Itoa(sourceID)
74 }
75 has, record, err := database.GetMediaRecord(database.RecordTypeMovie, sources.MediaSourceTMDB, parsed.SourceID)
76 if err == nil && has && record != nil {
77 ingestRecordID = record.RecordID
78 } else {
79 record, err = sources.UpsertMediaRecordTMDB(database.MediaTypeMovie, sourceID)
80 if err != nil {
81 // Retry fetching just in case another worker succeeded in upserting concurrently
82 has, retryRecord, retryErr := database.GetMediaRecord(database.RecordTypeMovie,
83 sources.MediaSourceTMDB, parsed.SourceID)
84 if retryErr == nil && has && retryRecord != nil {
85 record = retryRecord
86 ingestRecordID = record.RecordID
87 } else {
88 return nil, parsed, err
89 }
90 } else {
91 ingestRecordID = record.RecordID
92 }
93 }
94 loggers.IngestLogger().Info("[Matched Movie]", "path", filePath, "source_id", sourceID,
95 "title", record.MediaTitle, "release_date", record.ReleaseDate)
96 case database.MediaTypeTVShow:
97 sourceID := -1
98 if parsed.SourceID != "" {
99 sourceID, err = strconv.Atoi(parsed.SourceID)
100 if err != nil || sourceID <= 0 {
101 return nil, parsed, fmt.Errorf("invalid tmdb id in tv show folder name tmdb-%s: %w", parsed.SourceID, internal.BadRequestError)
102 }

Callers

nothing calls this directly

Calls 4

IsVideoFileFunction · 0.85
parseExternalMediaPathFunction · 0.85
findBestMovieTMDBIDFunction · 0.85
findBestTVTMDBIDFunction · 0.85

Tested by

no test coverage detected