예제 #1
0
        public async Task ProcessExistingMovie(MovieMetadata metadata = null)
        {
            var record = new DynamicParameters();

            //this is an existing movie. Fetch its id
            await this.LoadId();

            //if we have metadata, use that info
            if (metadata != null)
            {
                record.Add("title", metadata.Title);
                record.Add("sortTitle", metadata.SortTitle);
                record.Add("rating", metadata.Rating);
                record.Add("releaseYear", metadata.ReleaseYear);
                record.Add("summary", metadata.Summary);
                record.Add("tmdbId", metadata.TmdbId);
            }

            List <string> posterUrls = null;

            if (metadata != null && metadata.PosterUrls.Count() > 0)
            {
                posterUrls = metadata.PosterUrls;
            }
            else if (PosterPathsFromFileSystem.Count() > 0)
            {
                posterUrls = PosterPathsFromFileSystem.ToList();
            }
            else
            {
                // leave posters the way they are.
            }

            //only copy posters if we have a list of urls to copy
            if (posterUrls != null)
            {
                var posterCount = await CopyImages(posterUrls, this.PosterFolderPath, ImageType.Poster);

                record.Add("posterCount", posterCount);
            }

            List <string> backdropUrls = null;

            if (metadata != null && metadata.BackdropUrls.Count() > 0)
            {
                backdropUrls = metadata.BackdropUrls;
            }
            else if (PosterPathsFromFileSystem.Count() > 0)
            {
                backdropUrls = BackdropPathsFromFileSystem.ToList();
            }
            else
            {
                // leave backdrops the way they are.
            }

            //only copy backdrops if we have a list of backdrops to copy
            if (backdropUrls != null)
            {
                var backdropCount = await CopyImages(backdropUrls, this.BackdropFolderPath, ImageType.Backdrop);

                record.Add("backdropCount", backdropCount);
            }

            record.Add("id", this.Id);
            record.Add("folderPath", this.FolderPath);
            record.Add("videoPath", this.VideoPath);
            record.Add("runtimeSeconds", this.GetRuntimeSeconds());
            record.Add("sourceId", this.SourceId);

            //update the db with all of the fields we collected
            Console.WriteLine($"Update db record: {this.FolderPath}");
            await this.LibGenMovieRepository.Update(record);
        }
예제 #2
0
        public async Task ProcessNewMovie()
        {
            var record = new DynamicParameters();

            Console.WriteLine($"Inserting basic movie record into db: {this.VideoPath}");
            //insert a basic record so we can get an ID
            this.Id = await this.LibGenMovieRepository.InsertBasic(this);

            try
            {
                Console.WriteLine($"Fetching TMDB metadata for {this.VideoPath}");

                //fetch metadata for this movie once, only if it's a new movie, and only keep an exact match for title and release year
                MovieMetadata metadata = await this.GetMetadataFromTmdb();

                //if we have metadata, use that info
                if (metadata != null)
                {
                    record.Add("title", metadata.Title);
                    record.Add("sortTitle", metadata.SortTitle);
                    record.Add("rating", metadata.Rating);
                    record.Add("releaseYear", metadata.ReleaseYear);
                    record.Add("summary", metadata.Summary);
                    record.Add("tmdbId", metadata.TmdbId);
                }
                //we don't have metadata...set some defaults
                else
                {
                    record.Add("title", this.Title);
                    record.Add("sortTitle", this.SortTitle);
                    var year = this.GetYearFromFolderName();
                    if (year != null)
                    {
                        record.Add("releaseYear", year);
                    }
                }
                Console.WriteLine($"Copying posters for {this.VideoPath}");
                //use posters from video folder if possible, fallback to downloading them from metadata
                var posterUrls  = PosterPathsFromFileSystem.Count() > 0 ? PosterPathsFromFileSystem.ToList() : metadata?.PosterUrls;
                var posterCount = await CopyImages(posterUrls, this.PosterFolderPath, ImageType.Poster);

                Console.WriteLine($"Copying backdrops for {this.VideoPath}");
                //use backdrops from video folder if possible, fallback to downloading them from metadata
                var backdropUrls  = this.BackdropPathsFromFileSystem.Count() > 0 ? this.BackdropPathsFromFileSystem.ToList() : metadata?.BackdropUrls;
                var backdropCount = await CopyImages(backdropUrls, this.BackdropFolderPath, ImageType.Backdrop);

                record.Add("posterCount", posterCount);
                record.Add("backdropCount", backdropCount);
                record.Add("id", this.Id);
                record.Add("folderPath", this.FolderPath);
                record.Add("videoPath", this.VideoPath);
                record.Add("runtimeSeconds", this.GetRuntimeSeconds());
                record.Add("sourceId", this.SourceId);

                //update the db with all of the fields we collected
                Console.WriteLine($"Saving enhanced movie info for {this.VideoPath}");
                await this.LibGenMovieRepository.Update(record);
            }
            catch
            {
                //delete the video record...it's just easier to reprocess from scratch once the video has been fixed
                await this.Delete();

                throw;
            }
        }