Exemplo n.º 1
0
        public static void DownloadMissingArtwork()
        {
            var downloader = new FileDownloader();
            downloader.DownloadProgressNotification += DownloadMissingArtworkProgress;

            foreach (var artwork in ArtworkEntity.GetToDownload())
            {
                var personId = -1;
                string personFullName = null;
                var seriesId = -1;
                string seriesName = null;

                if (artwork.ArtworkToSeries.Any())
                {
                    seriesId = artwork.ArtworkToSeries.First().SeriesId;
                    seriesName = artwork.ArtworkToSeries.First().Series.NameOriginal;
                }
                else if (artwork.ArtworkToSeasons.Any())
                {
                    seriesId = artwork.ArtworkToSeasons.First().Season.SeriesId;
                    seriesName = artwork.ArtworkToSeasons.First().Season.Series.NameOriginal;
                }
                else if (artwork.ArtworkToEpisodes.Any())
                {
                    seriesId = artwork.ArtworkToEpisodes.First().Episode.Season.SeriesId;
                    seriesName = artwork.ArtworkToEpisodes.First().Episode.Season.Series.NameOriginal;
                }
                else if (artwork.ArtworkToRoles.Any())
                {
                    seriesId = artwork.ArtworkToRoles.First().Role.RoleToSeries.First().SeriesId;
                    seriesName = artwork.ArtworkToRoles.First().Role.RoleToSeries.First().Series.NameOriginal;
                }

                if (artwork.ArtworkToPeople.Any())
                {
                    personId = artwork.ArtworkToPeople.First().PersonId;
                    personFullName = artwork.ArtworkToPeople.First().Person.FullName;
                }

                Logger.Trace(
                    "SeriesId: {0} | SeriesName: {1} | PersonId: {2} | PersonName: {3} | URL: {4}",
                    seriesId,
                    seriesName ?? string.Empty,
                    personId,
                    personFullName ?? string.Empty,
                    artwork.OnlineFilePath);
                var folderName = seriesName ?? personFullName;
                if (folderName == null)
                {
                    Logger.Warn("Could not construct a valid foldername. Skipping. {0} | {1}", artwork.ArtworkId, artwork.OnlineFilePath);
                    continue;
                }

                var localName = @"d:\temp\tvjunkie\files";
                localName = Path.Combine(localName, CleanFileName(folderName));
                localName = Path.Combine(localName, Enum.GetName(typeof(ArtworkTypeEnum), artwork.ArtworkTypeId));
                localName = Path.Combine(localName, string.Format("{0}_{1}{2}", Enum.GetName(typeof(ArtworkSourceEnum), artwork.ArtworkSourceId), artwork.ArtworkOriginalId, Path.GetExtension(artwork.OnlineFilePath)));

                if (artwork.ArtworkSourceId == (int)ArtworkSourceEnum.TheTVDBCOM)
                {
                    artwork.OnlineFilePath = string.Format("{0}{1}", "http://www.thetvdb.com/banners/", artwork.OnlineFilePath);
                }

                Logger.Trace("OnlineURL: {0} | LocalURL: {1}", artwork.OnlineFilePath, localName);

                if (!Directory.Exists(Path.GetDirectoryName(localName)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(localName));
                }

                downloader.AddDownload(new Uri(artwork.OnlineFilePath), new FileInfo(localName), artwork.ArtworkId);
            }

            while (!downloader.IsIdle)
            {
                Logger.Trace("Sleeping.");
                Thread.Sleep(5000);
            }
        }
Exemplo n.º 2
0
 private static void DownloadMissingArtworkProgress(FileDownloader s, FileDownloadProgressEventArgs e)
 {
     Logger.Trace("Queue length: {0} | Completed download: {1}", s.ActiveWorkItems + s.WaitingWorkItems, e.FileDownloadInfo.Url);
 }