Exemplo n.º 1
0
        public static async Task GetEpisodeMetadata(TvDbWrapper api, string seasonPath)
        {
            var parent   = new DirectoryInfo(seasonPath).Parent;
            var seriesId = SeriesIOHelper.GetSeriesIdFromFile(parent.FullName);

            await GetEpisodeMetadata(api, seriesId, seasonPath).ConfigureAwait(false);
        }
Exemplo n.º 2
0
        public static async Task GetSeriesInfo(TvDbWrapper api, string seriesPath, bool includeSeasons = false)
        {
            //first get series data
            var seriesId = SeriesIOHelper.GetSeriesIdFromFile(seriesPath);

            await GetSeriesInfo(api, seriesPath, seriesId, includeSeasons).ConfigureAwait(false);
        }
Exemplo n.º 3
0
        public static async Task GetEpisodeMetadata(TvDbWrapper api, string seriesId, string seasonPath)
        {
            var fullRec = await api.GetSeriesFullRecord(seriesId).ConfigureAwait(false);

            var seasonName = new DirectoryInfo(seasonPath).Name;
            var seasonNo   = seasonName.Split(" ".ToCharArray())[1];
            var banners    = await api.GetArtwork(fullRec.Series.Id, BannerType.season).ConfigureAwait(false);

            await GetEpisodeMetadata(api, fullRec, seasonPath, banners, seasonNo).ConfigureAwait(false);
        }
Exemplo n.º 4
0
        public static async Task RenameFiles(TvDbWrapper api, string seriesName, string seasonPath)
        {
            var episodes = await GetEpisodes(api, seasonPath).ConfigureAwait(false);

            var files     = GetEpisodeFiles(seasonPath).Select(f => new FileInfo(f).Name);
            var subtitles = GetSubtitleFiles(seasonPath);

            RenameEpisodeFiles(seriesName, seasonPath, episodes, files);
            RenameEpisodeFiles(seriesName, seasonPath, episodes, subtitles);
        }
Exemplo n.º 5
0
        public static async Task <IEnumerable <Episode> > GetEpisodes(TvDbWrapper api, string seasonPath)
        {
            var parent   = new DirectoryInfo(seasonPath).Parent;
            var seriesId = SeriesIOHelper.GetSeriesIdFromFile(parent.FullName);
            var fullRec  = await api.GetSeriesFullRecord(seriesId).ConfigureAwait(false);

            var seasonName = new DirectoryInfo(seasonPath).Name;
            var seasonNo   = seasonName.Split(" ".ToCharArray())[1];

            var seasonEpisodes = fullRec.Episodes.Where(ep => ep.CombinedSeason == seasonNo);

            return(seasonEpisodes);
        }
Exemplo n.º 6
0
        public static async Task GetSeriesInfo(TvDbWrapper api, string seriesPath, string seriesId, bool includeSeasons = false)
        {
            var fullRec = await api.GetSeriesFullRecord(seriesId).ConfigureAwait(false);

            var banners = await api.GetSeriesBanners(fullRec.Series.Id).ConfigureAwait(false);

            await SetSeriesData(api, seriesPath, fullRec, banners).ConfigureAwait(false);

            //then season data
            if (includeSeasons)
            {
                foreach (var seasonPath in Directory.EnumerateDirectories(seriesPath))
                {
                    var seasonName = new DirectoryInfo(seasonPath).Name;
                    var seasonNo   = seasonName.Split(" ".ToCharArray())[1];
                    await SeasonHelper.GetEpisodeMetadata(api, fullRec, seasonPath, banners, seasonNo).ConfigureAwait(false);
                }
            }
        }
Exemplo n.º 7
0
        private static async Task SetSeriesData(TvDbWrapper api, string seriesPath, SeriesFull fullRec, IEnumerable <Banner> banners)
        {
            //get View.xml
            var viewFile = Path.Combine(seriesPath, Constants.SERIES_VIEW);
            await api.WriteSeriesViewXml(viewFile).ConfigureAwait(false);

            //fanart image
            var fanartImages = await api.GetArtworkPaths(fullRec.Series.Id, BannerType.fanart).ConfigureAwait(false);

            var fanart = Path.Combine(seriesPath, "fanart.jpg");

            if (fanartImages.Any())
            {
                var image = await api.GetImageByUrl(fanartImages.First()).ConfigureAwait(false);

                image = ImageHelper.ReduceImageSize(image);
                File.WriteAllBytes(fanart, image);
            }

            //folder image
            var folderImages = api.BannerImages(banners, BannerType.poster).ToArray();
            var poster       = Path.Combine(seriesPath, "folder.jpg");

            if (folderImages.Length > 0)
            {
                var image = await api.GetImageByUrl(folderImages[0]).ConfigureAwait(false);

                image = ImageHelper.ReduceImageSize(image);
                File.WriteAllBytes(poster, image);
            }

            //series xml
            var xmlPath = Path.Combine(seriesPath, Constants.SERIES_XML);
            var xml     = GetSeriesXml(fullRec.Series);

            File.WriteAllText(xmlPath, xml);
        }
Exemplo n.º 8
0
        public static async Task GetEpisodeMetadata(TvDbWrapper api, SeriesFull fullRec, string seasonPath, IEnumerable <Banner> banners, string seasonNo)
        {
            var thumbs       = GetExistingEpisodeThumbs(seasonPath);
            var bannerImages = api.BannerImages(banners, BannerType.season);

            var seasonEpisodes = fullRec.Episodes.Where(ep => ep.CombinedSeason == seasonNo);

            if (!seasonEpisodes.Any())
            {
                return;
            }

            var bytesSaved = 0;

            foreach (var key in thumbs.Keys)
            {
                //key sample : C:\BT\Series\Ray Donovan\Season 5\Ray Donovan.S05E06.Shelley Duvall.mkv
                var episodeNo = SeriesIOHelper.GetSeasonEpisodeFromName(key);
                //resolve episode from seasonEpisodes
                var episode         = seasonEpisodes.First(ep => ep.EpisodeNumber == episodeNo);
                var episodeFileName = episode.FileName;

                // thumbnails
                if (thumbs[key]?.Length == 0 && !string.IsNullOrEmpty(episodeFileName))
                {
                    //get banner TVDB filename
                    //get image using filename
                    var data = await api.GetImage(episodeFileName).ConfigureAwait(false);

                    if (data?.Length > 0)
                    {
                        var reduced = ImageHelper.ReduceImageSize(data);

                        if (reduced?.Length > 0)
                        {
                            bytesSaved += data.Length - reduced.Length;
                            //save image using episode name
                            var newExtension = Path.GetExtension(episodeFileName);
                            var imgFile      = Path.ChangeExtension(key, newExtension);
                            await File.WriteAllBytesAsync(imgFile, reduced).ConfigureAwait(false);
                        }
                    }
                }

                // xml content
                var xmlPath = Path.ChangeExtension(key, Constants.CONTENT_EXTENSION);
                if (!File.Exists(xmlPath))
                {
                    var xml = GetEpisodeXml(fullRec.Series, episode, bannerImages);
                    await File.WriteAllTextAsync(xmlPath, xml).ConfigureAwait(false);
                }
            }
            Debug.WriteLine($"Total bytes saved on episode images: {bytesSaved}");

            //get season thumb
            var seasonThumb = Path.Combine(seasonPath, Constants.SERIES_SEASON_THUMB);

            if (File.Exists(seasonThumb) && new FileInfo(seasonThumb).Length == 0) //if the save operation failed previously, the file would have been created without content
            {
                File.Delete(seasonThumb);
            }

            if (!File.Exists(seasonPath))
            {
                var epi          = seasonEpisodes.First();
                var seasonBanner = banners.ToList().Find(banner => banner.BannerType == "season" && banner.Season == epi.CombinedSeason);
                if (seasonBanner is not null)
                {
                    var img = await api.GetImage(seasonBanner.BannerPath).ConfigureAwait(false) ?? await api.GetImage(seasonBanner.ThumbnailPath).ConfigureAwait(false);

                    if (img is not null)
                    {
                        var reduced = ImageHelper.ReduceImageSize(img);
                        await File.WriteAllBytesAsync(seasonThumb, reduced).ConfigureAwait(false);
                    }
                }
            }

            //get View.xml
            var viewFile = Path.Combine(seasonPath, Constants.SEASON_VIEW);

            if (!File.Exists(viewFile))
            {
                await api.WriteSeasonViewXml(viewFile).ConfigureAwait(false);
            }
        }