Esempio n. 1
0
 /// <summary>
 /// Creates a new Tvdb handler
 /// </summary>
 /// <param name="_apiKey"></param>
 public TvdbHandler(String _apiKey)
 {
     m_apiKey = _apiKey; //store api key
       TvdbLinkCreator.ActiveMirror = new TvdbMirror(0, new Uri(TvdbLinkCreator.BASE_SERVER), 7);
       m_downloader = new TvdbDownloader(m_apiKey);
       m_cacheProvider = null;
 }
Esempio n. 2
0
 public IEnumerable<Episode> GetEpisodes(int serieId)
 {
     _downloader = new TvdbDownloader(_apiKey);
     var episodes = _downloader.DownloadEpisodes(serieId, _language).Where(x => !x.IsSpecial);
     return episodes.Select(x => new Episode
         {
             AbsoluteEpisodeNumber = x.AbsoluteNumber,
             AirDate = x.FirstAired,
             SeasonNumber = x.SeasonNumber,
             EpisodeNumber = x.EpisodeNumber,
             Overview = x.Overview
         });
 }
Esempio n. 3
0
 private void cmdTestGetSeriesByExternalId_Click(object sender, EventArgs e)
 {
     TvdbDownloader downloader = new TvdbDownloader(File.ReadAllText("api_key.txt"));
       TvdbSearchResult s = downloader.DownloadSeriesSearchByExternalId(ExternalId.ImdbId, txtExternalId.Text);
 }
Esempio n. 4
0
        private void UpdateShow(TVShow Show)
        {
            Reporting.Log("Updating show: " + Show.Title);

            string[] VideoPaths = Directory.GetFiles(Show.Location, "*.*", SearchOption.AllDirectories);

            List<VideoFileInfo> Videos = new List<VideoFileInfo>();
            foreach (string VidPath in VideoPaths)
            {
                if (!ConfigurationManager.CurrentConfiguration.VideoExtensions.Contains(new FileInfo(VidPath).Extension.Trim('.')))
                {
                    continue;
                }

                Reporting.Log(VidPath);
                VideoFileInfo VidFile = new VideoFileInfo(VidPath);

                VideoFileInfo CurrentFile = DataAccess.GetVideoFileFromHash(VidFile.Hash);
                Reporting.Log(VidFile.Hash);

                if (CurrentFile != null)
                {
                    // File has been seen before.
                    Reporting.Log("Already seen");

                    if (CurrentFile.Path != VidFile.Path)
                    {
                        Reporting.Log("Updating location.");
                        // Update video file location.
                        CurrentFile.Path = VidFile.Path;
                        DataAccess.SaveVideoFile(CurrentFile);
                    }
                }
                else
                {
                    // new file.

                    // Save filesize
                    FileInfo Info = new FileInfo(VidFile.Path);
                    VidFile.Size = Info.Length;
                    string RelativePath = VidPath.Replace(Show.Location, "");

                    int SeasonNumber = -1;
                    int EpisodeNumber = -1;
                    foreach (string Regex in ConfigurationManager.CurrentConfiguration.TVRegexes)
                    {
                        Regex R = new Regex(Regex);
                        Match M = R.Match(RelativePath);
                        if (M.Success)
                        {
                            if (M.Groups.Count < 1)
                            {
                                continue;
                            }
                            else if (M.Groups.Count == 2)
                            {
                                EpisodeNumber = Convert.ToInt32(M.Groups[1].Value);
                            }
                            else
                            {
                                SeasonNumber = Convert.ToInt32(M.Groups[1].Value);
                                EpisodeNumber = Convert.ToInt32(M.Groups[2].Value);
                            }
                            break;
                        }
                    }

                    if (EpisodeNumber == 0)
                    {
                        Reporting.Log(RelativePath + " does not match any TV regexes in config file.");
                        return;
                    }

                    // check for presence of season
                    TVSeason Season = DataAccess.GetTVSeason(Show, SeasonNumber);

                    if (Season == null)
                    {
                        // insert season if not present.
                        Season = new TVSeason()
                        {
                            SeasonNumber = SeasonNumber,
                            ShowId = Show.Id
                        };
                        Season = DataAccess.SaveSeason(Season);

                        TvdbDownloader Downloader = new TvdbDownloader(TvdbApiKey);

                        List<TvdbBanner> Banners = Downloader.DownloadBanners(Show.TvdbId);
                        List<TvdbSeasonBanner> SeasonBanners = new List<TvdbSeasonBanner>();

                        foreach (TvdbBanner Banner in Banners)
                        {
                            if (Banner.GetType() == typeof(TvdbSeasonBanner))
                            {
                                TvdbSeasonBanner SeasonBanner = (TvdbSeasonBanner)Banner;
                                if (SeasonBanner.Season == SeasonNumber)
                                {
                                    SeasonBanners.Add(SeasonBanner);
                                }
                            }
                        }

                        Season.Art = CacheManager.SaveArtwork(Season.Id, SeasonBanners[0].BannerPath, ArtworkType.Poster);

                        Season = DataAccess.SaveSeason(Season);
                    }

                    // check for presence of episode
                    TVEpisode Episode = DataAccess.GetTVEpisode(Show, Season, EpisodeNumber);

                    // insert ep if not present
                    if (Episode == null)
                    {
                        TvdbEpisode TvdbEp = LookupEpisode(Show, Season, EpisodeNumber);

                        if (TvdbEp == null)
                        {
                            Reporting.Log(String.Format("Episode not found: {0} - {1}x{2} ({3})", Show.Title, Season.SeasonNumber, EpisodeNumber, VidFile.Path));
                            continue;
                        }
                        Episode = new TVEpisode() {
                            EpisodeNumber = EpisodeNumber,
                            SeasonId = Season.Id,
                            AirDate = TvdbEp.FirstAired,
                            Rating = TvdbEp.Rating,
                            Summary = TvdbEp.Overview,
                            Title = TvdbEp.EpisodeName,
                            TvdbId = TvdbEp.Id,
                        };
                        Episode = DataAccess.SaveEpisode(Episode);

                        Episode.Thumb = CacheManager.SaveArtwork(Episode.Id, TvdbEp.BannerPath, ArtworkType.Banner);
                        DataAccess.SaveEpisode(Episode);
                    }

                    // save video file
                    VidFile.LoadMetaDataFromFile();
                    VidFile = DataAccess.SaveVideoFile(VidFile);

                    // add video file to episode.
                    DataAccess.AssocVideoWithEpisode(VidFile, Episode);
                }

            }

            // TODO: Clean up missing files.
        }
Esempio n. 5
0
        private bool DownloadImage(string serverPath, string title, int season, int episode)
        {
            string apiKey = ConfigurationManager.AppSettings["tvdb.API.key"];
            if (string.IsNullOrWhiteSpace(apiKey))
                return false;

            var handler = new TvdbHandler(apiKey);
            var downloader = new TvdbDownloader(apiKey);

            var searchResult = handler.SearchSeries(title);
            if (searchResult != null && searchResult.Count > 0)
            {
                var result = searchResult.First();
                int sId = result.Id;

                var banner = GetLoadedBanner(downloader, sId, season, episode, result.Banner);

                if (banner == null)
                    return false;

                banner.BannerImage.Save(serverPath);
                return true;
            }

            return false;
        }
Esempio n. 6
0
        private TvdbBanner GetLoadedBanner(TvdbDownloader downloader, int sId, int season, int episode, TvdbBanner fallback)
        {
            TvdbBanner result = GetEpisodeBanner(downloader, sId, season, episode);
            if (result != null && TryLoadBanner(result))
                return result;

            var bannerHits = downloader.DownloadBanners(sId);

            result = GetSeasonBanner(bannerHits, season);
            if (result != null && TryLoadBanner(result))
                return result;

            result = GetSeriesBanner(bannerHits);
            if (result != null && TryLoadBanner(result))
                return result;

            if (fallback != null && TryLoadBanner(fallback))
                return fallback;

            return null;
        }
Esempio n. 7
0
 private TvdbBanner GetEpisodeBanner(TvdbDownloader downloader, int seriesId, int season, int episode)
 {
     try
     {
         var tvEpisode = downloader.DownloadEpisode(seriesId, season, episode, TvdbEpisode.EpisodeOrdering.DefaultOrder, TvdbLanguage.DefaultLanguage);
         return tvEpisode.Banner;
     }
     catch (Exception ex)
     {
         return null;
     }
 }
Esempio n. 8
0
 /// <summary>
 /// <para>Creates a new Tvdb handler</para>
 /// <para>The tvdb handler is used not only for downloading data from thetvdb but also to cache the downloaded data to a persistent storage,
 ///       handle user specific tasks and keep the downloaded data consistent with the online data (via the updates api)</para>
 /// </summary>
 /// <param name="_apiKey">The api key used for downloading data from thetvdb -> see http://thetvdb.com/wiki/index.php/Programmers_API</param>
 public TvdbHandler(String _apiKey)
 {
     m_apiKey = _apiKey; //store api key
       m_downloader = new TvdbDownloader(m_apiKey);
       m_cacheProvider = null;
 }
Esempio n. 9
0
        private void InitTvdblibHandler()
        {
            ICacheProvider provider;
              if (cbCacheType.SelectedIndex == 0 || cbCacheType.SelectedIndex == -1)
              {
            provider = new XmlCacheProvider(txtCacheLocation.Text);
              }
              else
              {
            provider = new BinaryCacheProvider(txtCacheLocation.Text);
              }

              lbCacheSnapshots.Items.Clear();
              foreach (String f in Directory.GetFiles(Directory.GetCurrentDirectory(), "Rev_*.zip"))
              {
            FileInfo file = new FileInfo(f);
            CacheRevision rev = CacheRevision.CreateFromFile(file);

            if (rev != null)
            {
              lbCacheSnapshots.Items.Add(rev);
            }
              }

              m_tvdbHandler = new TvdbHandler(provider, File.ReadAllText("api_key.txt"));
              // m_tvdbHandler.UserInfo = new TvdbLib.Data.TvdbUser("DieBagger", txtUserId.Text);
              m_tvdbHandler.InitCache();
              txtLastUpdated.Text = m_tvdbHandler.GetLastUpdate().ToString();

              List<int> cached = m_tvdbHandler.GetCachedSeries();
              lvCachedSeries.Items.Clear();
              cached.ForEach(delegate(int s)
              {
            ListViewItem item = new ListViewItem(s.ToString());
            item.SubItems.Add("");
            item.Tag = s;
            lvCachedSeries.Items.Add(item);
              });
              m_tvdbDownloader = new TvdbDownloader(File.ReadAllText("api_key.txt"));
              m_tvdbHandler.UpdateFinished += new TvdbHandler.UpdateFinishedDelegate(m_tvdbHandler_UpdateFinished);
        }