예제 #1
0
 /// <summary>
 /// Updates all information of this episode from the given
 /// episode...
 /// </summary>
 /// <param name="_episode">new episode</param>
 internal void UpdateEpisodeInfo(TvdbEpisode _episode)
 {
     this.LastUpdated           = _episode.LastUpdated;
     this.Banner                = _episode.Banner;
     this.AbsoluteNumber        = _episode.AbsoluteNumber;
     this.CombinedEpisodeNumber = _episode.CombinedEpisodeNumber;
     this.CombinedSeason        = _episode.CombinedSeason;
     this.Directors             = _episode.Directors;
     this.DvdChapter            = _episode.DvdChapter;
     this.DvdDiscId             = _episode.DvdDiscId;
     this.DvdEpisodeNumber      = _episode.DvdEpisodeNumber;
     this.DvdSeason             = _episode.DvdSeason;
     this.EpisodeName           = _episode.EpisodeName;
     this.EpisodeNumber         = _episode.EpisodeNumber;
     this.FirstAired            = _episode.FirstAired;
     this.GuestStars            = _episode.GuestStars;
     this.ImdbId                = _episode.ImdbId;
     this.Language              = _episode.Language;
     this.Overview              = _episode.Overview;
     this.ProductionCode        = _episode.ProductionCode;
     this.Rating                = _episode.Rating;
     this.SeasonId              = _episode.SeasonId;
     this.SeasonNumber          = _episode.SeasonNumber;
     this.Writer                = _episode.Writer;
 }
        protected bool Matched(GuideEnricherProgram guideProgram, TvdbEpisode episode)
        {
            if (guideProgram == null) throw new ArgumentNullException("guideProgram");
            if (episode == null) throw new ArgumentNullException("episode");
            //
            this.SuccessfulMatches++;
            guideProgram.EpisodeNumber = episode.EpisodeNumber;
            guideProgram.SeriesNumber = episode.SeasonNumber;
            guideProgram.EpisodeNumberDisplay = Enricher.FormatSeasonAndEpisode(episode.SeasonNumber, episode.EpisodeNumber);

            if (bool.Parse(Config.Instance.GetProperty("updateSubtitles")))
            {
                guideProgram.SubTitle = episode.EpisodeName;
            }

            if (bool.Parse(Config.Instance.GetProperty("episodeInDescription")))
            {
                var descriptionWithNoEpisodeNumber = Regex.Replace(guideProgram.Description, "^S[0-9][0-9]E[0-9][0-9] - ", string.Empty);
                guideProgram.Description = string.Format("{0} - {1}", guideProgram.EpisodeNumberDisplay, descriptionWithNoEpisodeNumber);
            }

            this.log.DebugFormat("[{0}] Correctly matched {1} - {2} as {3}", this.MethodName, guideProgram.Title, guideProgram.SubTitle, guideProgram.EpisodeNumberDisplay);
            return true;
        }
예제 #3
0
        /// <summary>
        /// <para>Gets the episodes for the given season in the given order (aired or dvd). Absolute is also possible but makes no sense since
        /// there are no seasons with absoulte ordering. Use GetEpisodesAbsoluteOrder() instead.</para>
        /// 
        /// <para>For more information on episode ordering <see href="http://thetvdb.com/wiki/index.php/Category:Episodes">thetvdb wiki</see></para>
        /// </summary>
        /// <returns>List of episodes</returns>
        public List<TvdbEpisode> GetEpisodes(int _season, TvdbEpisode.EpisodeOrdering _order)
        {
            List<TvdbEpisode> episodes = new List<TvdbEpisode>();
              m_episodes.ForEach(delegate(TvdbEpisode e) { if (e.SeasonNumber == _season) episodes.Add(e); });

              switch (_order)
              {
            case TvdbEpisode.EpisodeOrdering.DefaultOrder:
              episodes.Sort(new EpisodeComparerAired());
              break;
            case TvdbEpisode.EpisodeOrdering.DvdOrder:
              episodes.Sort(new EpisodeComparerDvd());
              break;
            case TvdbEpisode.EpisodeOrdering.AbsoluteOrder:
              episodes.Sort(new EpisodeComparerAbsolute());
              break;
              }
              return episodes;
        }
예제 #4
0
        /// <summary>
        /// Update the series with the episode (Add it to the series if it doesn't already exist or update the episode if the current episode is older than the updated one)
        /// </summary>
        /// <param name="_series">Series of the updating episode</param>
        /// <param name="_episode">Episode that is updated</param>
        /// <param name="_progress">Progress of the update run</param>
        /// <returns>true if episode has been updated, false if not (e.g. timestamp of updated episode older than
        ///          timestamp of existing episode</returns> 
        private bool UpdateEpisode(TvdbSeries _series, TvdbEpisode _episode, int _progress)
        {
            bool updateDone = false;
              TvdbLanguage currentLanguage = _series.Language;
              foreach (KeyValuePair<TvdbLanguage, TvdbSeriesFields> kvp in _series.SeriesTranslations)
              {
            if (_series.EpisodesLoaded)
            {
              bool found = false;
              List<TvdbEpisode> eps = kvp.Value.Episodes;

              if (eps != null && eps.Count > 0)
              {
            //check all episodes if the updated episode is in it
            foreach (TvdbEpisode e in eps)
            {
              if (e.Id == _episode.Id)
              {
                found = true;
                if (e.LastUpdated < _episode.LastUpdated)
                {
                  //download episode which has been updated
                  TvdbEpisode newEpisode = null;
                  try
                  {
                    newEpisode = m_downloader.DownloadEpisode(e.Id, kvp.Key);
                  }
                  catch (TvdbContentNotFoundException)
                  {
                    Log.Warn("Couldn't download episode " + e.Id + "(" + e.EpisodeName + ")");
                  }
                  //update information of episode with new episodes informations
                  if (newEpisode != null)
                  {
                    newEpisode.LastUpdated = _episode.LastUpdated;

                    e.UpdateEpisodeInfo(newEpisode);
                    if (UpdateProgressed != null)
                    {//update has started, we're downloading the updated content from tvdb
                      UpdateProgressed(new UpdateProgressEventArgs(UpdateProgressEventArgs.UpdateStage.episodesupdate,
                                                                   "Updating episode " + _series.SeriesName + " " + e.SeasonNumber +
                                                                   "x" + e.EpisodeNumber + "(id: " + _episode.Id + ")",
                                                                   _progress, 50 + (int)(_progress / 4)));
                    }
                    Log.Info("Updated Episode " + e.SeasonNumber + "x" + e.EpisodeNumber + " for series " + _series.SeriesName +
                             "(id: " + e.Id + ", lang: " + e.Language.Abbriviation + ")");
                    updateDone = true;
                  }
                }
                break;
              }
            }
              }

              if (!found)
              {
            //episode hasn't been found
            //hasn't been found -> add it to series
            TvdbEpisode ep = null;
            try
            {
              ep = m_downloader.DownloadEpisode(_episode.Id, kvp.Key);
            }
            catch (TvdbContentNotFoundException ex)
            {
              Log.Warn("Problem downloading " + _episode.Id + ": " + ex.ToString());
            }
            if (ep != null)
            {
              kvp.Value.Episodes.Add(ep);
              //todo: sort here!!!! -> create episode comparer
              //kvp.Value.Episodes.Sort(new Comparison<TvdbEpisode>(v

              if (UpdateProgressed != null)
              {//update has started, we're downloading the updated content from tvdb
                UpdateProgressed(new UpdateProgressEventArgs(UpdateProgressEventArgs.UpdateStage.episodesupdate,
                                                             "Added episode " + _series.SeriesName + " " + ep.SeasonNumber +
                                                             "x" + ep.EpisodeNumber + "(id: " + ep.Id + ")",
                                                             _progress, 50 + (int)(_progress / 4)));
              }
              Log.Info("Added Episode " + ep.SeasonNumber + "x" + ep.EpisodeNumber + " for series " + _series.SeriesName +
                       "(id: " + ep.Id + ", lang: " + ep.Language.Abbriviation + ")");
              updateDone = true;
            }
              }
            }
            else
            {
              Log.Debug("Not adding episode " + _episode.Id + ", because series " + _series.SeriesName + " hasn't loaded episodes");
              updateDone = false;
            }
              }
              _series.SetLanguage(currentLanguage);
              return updateDone;
        }
예제 #5
0
        /// <summary>
        /// <para>Download the episode (specified by series id, season number, episode number, language and episode order) from http://thetvdb.com.</para>
        /// <para>It is possible to retrieve episodes by aired order (aka default order), DVD order and absolute order. For a detailled description of these
        /// options see: http://thetvdb.com/wiki/index.php/Category:Episodes</para>
        /// </summary>
        /// <param name="_seriesId">series id</param>
        /// <param name="_seasonNr">season nr</param>
        /// <param name="_episodeNr">episode nr</param>
        /// <param name="_language">language</param>
        /// <param name="_order">order</param>
        /// <returns>The episode object or null if the episode could't be found</returns>
        /// <exception cref="TvdbInvalidXmlException"><para>Exception is thrown when there was an error parsing the xml files. </para>
        ///                                           <para>Feel free to post a detailed description of this issue on http://code.google.com/p/tvdblib 
        ///                                           or http://forums.thetvdb.com/</para></exception>  
        /// <exception cref="TvdbContentNotFoundException">The episode/series/banner couldn't be located on the tvdb server.</exception>
        /// <exception cref="TvdbNotAvailableException">Exception is thrown when thetvdb isn't available.</exception>
        public TvdbEpisode DownloadEpisode(int _seriesId, int _seasonNr, int _episodeNr, TvdbEpisode.EpisodeOrdering _order, TvdbLanguage _language)
        {
            String xml = "";
              String link = "";
              String order = null;
              switch (_order)
              {
            case TvdbEpisode.EpisodeOrdering.AbsoluteOrder:
              order = "absolute";
              break;
            case TvdbEpisode.EpisodeOrdering.DefaultOrder:
              order = "default";
              break;
            case TvdbEpisode.EpisodeOrdering.DvdOrder:
              order = "dvd";
              break;
              }

              try
              {
            link = TvdbLinkCreator.CreateEpisodeLink(m_apiKey, _seriesId, _seasonNr, _episodeNr, order, _language);
            xml = m_webClient.DownloadString(link);
            List<TvdbEpisode> epList = m_xmlHandler.ExtractEpisodes(xml);
            if (epList != null && epList.Count == 1)
            {
              return epList[0];
            }
            else
            {
              return null;
            }
              }
              catch (XmlException ex)
              {
            Log.Error("Error parsing the xml file " + link + "\n\n" + xml, ex);
            throw new TvdbInvalidXmlException("Error parsing the xml file " + link + "\n\n" + xml);
              }
              catch (WebException ex)
              {
            Log.Warn("Request not successfull", ex);
            if (ex.Message.Equals("The remote server returned an error: (404) Not Found."))
            {
              throw new TvdbContentNotFoundException("Couldn't download episode " + _seriesId + "/" +
                                                 _order + "/" + _seasonNr + "/" + _episodeNr + "/" + _language.Abbriviation +
                                                 ", maybe the episode or the ordering doesn't exist");
            }
            else
            {
              throw new TvdbNotAvailableException("Couldn't connect to Thetvdb.com to retrieve " + _seriesId + "/" +
                                              _order + "/" + _seasonNr + "/" + _episodeNr + "/" + _language.Abbriviation +
                                              ", check your internet connection and the status of http://thetvdb.com");
            }
              }
        }
예제 #6
0
            public TVShowMetadata(IFileSystem fileSystem, DirectoryInfoBase cacheDirectory, TvdbSeries tvdbSeries, TvdbEpisode tvdbEpisode)
            {
                // Set metadata.
                TVShowName = tvdbSeries.SeriesName;
                SeasonNumber = tvdbEpisode.SeasonNumber;
                EpisodeNumber = tvdbEpisode.EpisodeNumber;
                Name = tvdbEpisode.EpisodeName;
                Description = tvdbEpisode.Overview;
                Genres = tvdbSeries.Genre;
                Cast = tvdbSeries.Actors;
                Directors = tvdbEpisode.Directors;
                Screenwriters = tvdbEpisode.Writer;
                ReleaseDate = tvdbEpisode.FirstAired;
                Network = tvdbSeries.Network;

                // Get artwork.
                if (SeasonNumber.HasValue && tvdbSeries.SeasonBanners.Any(banner => banner.Season == SeasonNumber))
                {
                    Artwork = tvdbSeries.SeasonBanners.Where (banner => banner.Season == SeasonNumber).FirstOrDefault ().GetBannerCacheFile (fileSystem, cacheDirectory, false).ToBase64Image();
                }
                else if(tvdbSeries.PosterBanners.Any())
                {
                    Artwork = tvdbSeries.PosterBanners.FirstOrDefault ().GetBannerCacheFile (fileSystem, cacheDirectory, false).ToBase64Image();
                }
                else if(tvdbSeries.SeriesBanners.Any())
                {
                    Artwork = tvdbSeries.SeriesBanners.FirstOrDefault ().GetBannerCacheFile (fileSystem, cacheDirectory, false).ToBase64Image();
                }
            }
예제 #7
0
        private void FillEpisodeDetail(TvdbEpisode _episode)
        {
            //lbEpisodeInformation.Text = _episode.EpisodeName + "(" + _episode.EpisodeNumber + ")";
              lblEpisodeName.Text = _episode.EpisodeName + "(" + _episode.SeasonNumber + "x" + _episode.EpisodeNumber + ")";

              txtEpisodeLanguage.Text = _episode.Language != null ? _episode.Language.ToString() : "";
              txtEpisodeFirstAired.Text = _episode.FirstAired.ToShortDateString();

              lbGuestStars.Items.Clear();
              foreach (String s in _episode.GuestStars)
              {
            lbGuestStars.Items.Add(s.Trim());
              }

              lbDirectors.Items.Clear();
              foreach (String s in _episode.Directors)
              {
            lbDirectors.Items.Add(s.Trim());
              }

              lbWriters.Items.Clear();
              foreach (String s in _episode.Writer)
              {
            lbWriters.Items.Add(s.Trim());
              }

              txtEpisodeProductionCode.Text = _episode.ProductionCode;
              txtEpisodeOverview.Text = _episode.Overview;
              txtEpisodeDVDId.Text = _episode.DvdDiscId != -99 ? _episode.DvdDiscId.ToString() : "";
              txtEpisodeDVDSeason.Text = _episode.DvdSeason != -99 ? _episode.DvdSeason.ToString() : "";
              txtEpisodeDVDNumber.Text = _episode.DvdEpisodeNumber != -99 ? _episode.DvdEpisodeNumber.ToString() : "";
              txtEpisodeDVDChapter.Text = _episode.DvdChapter != -99 ? _episode.DvdChapter.ToString() : "";
              txtEpisodeAbsoluteNumber.Text = _episode.AbsoluteNumber != -99 ? _episode.AbsoluteNumber.ToString() : "";
              txtEpisodeImdbID.Text = _episode.ImdbId;
        }
예제 #8
0
파일: Util.cs 프로젝트: MichelZ/TheTVDBlib
 /// <summary>
 /// Add the episode to the series
 /// </summary>
 /// <param name="_episode"></param>
 /// <param name="_series"></param>
 internal static void AddEpisodeToSeries(TvdbEpisode _episode, TvdbSeries _series)
 {
     bool episodeFound = false; ;
       for (int i = 0; i < _series.Episodes.Count; i++)
       {
     if (_series.Episodes[i].Id == _episode.Id)
     {//we have already stored this episode -> overwrite it
       _series.Episodes[i].UpdateEpisodeInfo(_episode);
       episodeFound = true;
       break;
     }
       }
       if (!episodeFound)
       {//the episode doesn't exist yet
     _series.Episodes.Add(_episode);
     if (!_series.EpisodesLoaded) _series.EpisodesLoaded = true;
       }
 }
예제 #9
0
        /// <summary>
        /// <para>Download the episode (specified by series id, season number, episode number, language and episode order) from http://thetvdb.com.</para>
        /// <para>It is possible to retrieve episodes by aired order (aka default order), DVD order and absolute order. For a detailled description of these
        /// options see: http://thetvdb.com/wiki/index.php/Category:Episodes</para>
        /// </summary>
        /// <param name="_seriesId">series id</param>
        /// <param name="_seasonNr">season nr</param>
        /// <param name="_episodeNr">episode nr</param>
        /// <param name="_language">language</param>
        /// <param name="_order">order</param>
        /// <returns>The episode object or null if the episode could't be found</returns>
        /// <exception cref="TvdbInvalidXmlException"><para>Exception is thrown when there was an error parsing the xml files. </para>
        ///                                           <para>Feel free to post a detailed description of this issue on http://code.google.com/p/tvdblib 
        ///                                           or http://forums.thetvdb.com/</para></exception>  
        /// <exception cref="TvdbContentNotFoundException">The episode/series/banner couldn't be located on the tvdb server.</exception>
        /// <exception cref="TvdbNotAvailableException">Exception is thrown when thetvdb isn't available.</exception>
        public TvdbEpisode DownloadEpisode(int _seriesId, int _seasonNr, int _episodeNr, TvdbEpisode.EpisodeOrdering _order, TvdbLanguage _language)
        {
            String xml = "";
              String link = "";
              String order = null;
              switch (_order)
              {
            case TvdbEpisode.EpisodeOrdering.AbsoluteOrder:
              order = "absolute";
              break;
            case TvdbEpisode.EpisodeOrdering.DefaultOrder:
              order = "default";
              break;
            case TvdbEpisode.EpisodeOrdering.DvdOrder:
              order = "dvd";
              break;
              }

              try
              {
            link = TvdbLinkCreator.CreateEpisodeLink(m_apiKey, _seriesId, _seasonNr, _episodeNr, order, _language);
            xml = m_webClient.DownloadString(link);
            List<TvdbEpisode> epList = null;
            try
            {
            epList = m_xmlHandler.ExtractEpisodes(xml);
            }
            catch (Exception)
            {
            System.Net.HttpWebRequest _HttpWebRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(link);
            _HttpWebRequest.AllowWriteStreamBuffering = true;

            // set timeout for 20 seconds (Optional)
            _HttpWebRequest.Timeout = 20000;
            _HttpWebRequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;

            // Request response:
            using (System.Net.WebResponse _WebResponse = _HttpWebRequest.GetResponse())
            {
                // Open data stream:
                using (System.IO.Stream _WebStream = _WebResponse.GetResponseStream())
                {
                    using (StreamReader reader = new StreamReader(_WebStream))
                    {
                        xml = reader.ReadToEnd();
                    }
                }
            }
            epList = m_xmlHandler.ExtractEpisodes(xml);
            }
            if (epList != null && epList.Count == 1)
            {
              return epList[0];
            }
            else
            {
              return null;
            }
              }
              catch (XmlException ex)
              {
            Log.Error("Error parsing the xml file " + link + "\n\n" + xml, ex);
            throw new TvdbInvalidXmlException("Error parsing the xml file " + link + "\n\n" + xml);
              }
              catch (WebException ex)
              {
            Log.Warn("Request not successfull", ex);
            if (ex.Message.Equals("The remote server returned an error: (404) Not Found."))
            {
              throw new TvdbContentNotFoundException("Couldn't download episode " + _seriesId + "/" +
                                                 _order + "/" + _seasonNr + "/" + _episodeNr + "/" + _language.Abbriviation +
                                                 ", maybe the episode or the ordering doesn't exist");
            }
            else
            {
              throw new TvdbNotAvailableException("Couldn't connect to Thetvdb.com to retrieve " + _seriesId + "/" +
                                              _order + "/" + _seasonNr + "/" + _episodeNr + "/" + _language.Abbriviation +
                                              ", check your internet connection and the status of http://thetvdb.com");
            }
              }
        }
예제 #10
0
        /// <summary>
        /// Returns true if episodes are different
        /// </summary>
        /// <param name="_ep1"></param>
        /// <param name="_ep2"></param>
        /// <returns></returns>
        private bool EpsiodeChanged(TvdbEpisode _ep1, TvdbEpisode _ep2)
        {
            bool episodeChanged = false;
              if (!_ep1.AbsoluteNumber.Equals(_ep2.AbsoluteNumber)) episodeChanged = true;
              if (!_ep1.AirsAfterSeason.Equals(_ep2.AirsAfterSeason)) episodeChanged = true;
              if (!_ep1.AirsBeforeEpisode.Equals(_ep2.AirsBeforeEpisode)) episodeChanged = true;
              if (!_ep1.AirsBeforeSeason.Equals(_ep2.AirsBeforeSeason)) episodeChanged = true;
              if (!_ep1.BannerPath.Equals(_ep2.BannerPath)) episodeChanged = true;
              //those two will always be wrong because they're not included in the tvdb xml files of single episodes
              //-> see: http://forums.thetvdb.com/viewtopic.php?f=8&t=3993
              //if (!_ep1.CombinedEpisodeNumber.Equals(_ep2.CombinedEpisodeNumber)) episodeChanged = true;
              //if (!_ep1.CombinedSeason.Equals(_ep2.CombinedSeason)) episodeChanged = true;
              if (!_ep1.DirectorsString.Equals(_ep2.DirectorsString)) episodeChanged = true;
              if (!_ep1.DvdChapter.Equals(_ep2.DvdChapter)) episodeChanged = true;
              if (!_ep1.DvdDiscId.Equals(_ep2.DvdDiscId)) episodeChanged = true;
              if (!_ep1.DvdEpisodeNumber.Equals(_ep2.DvdEpisodeNumber)) episodeChanged = true;
              if (!_ep1.DvdSeason.Equals(_ep2.DvdSeason)) episodeChanged = true;
              if (!_ep1.EpisodeName.Equals(_ep2.EpisodeName)) episodeChanged = true;
              if (!_ep1.EpisodeNumber.Equals(_ep2.EpisodeNumber)) episodeChanged = true;
              if (!_ep1.FirstAired.Equals(_ep2.FirstAired)) episodeChanged = true;
              if (!_ep1.GuestStarsString.Equals(_ep2.GuestStarsString)) episodeChanged = true;
              if (!_ep1.Id.Equals(_ep2.Id)) episodeChanged = true;
              if (!_ep1.ImdbId.Equals(_ep2.ImdbId)) episodeChanged = true;
              if (!_ep1.IsSpecial.Equals(_ep2.IsSpecial)) episodeChanged = true;
              //if (!_ep1.LastUpdated.Equals(_ep2.LastUpdated)) episodeChanged = true;
              if (!_ep1.Overview.Equals(_ep2.Overview)) episodeChanged = true;
              if (!_ep1.ProductionCode.Equals(_ep2.ProductionCode)) episodeChanged = true;
              //if (!_ep1.Rating.Equals(_ep2.Rating)) episodeChanged = true;
              if (!_ep1.SeasonId.Equals(_ep2.SeasonId)) episodeChanged = true;
              if (!_ep1.SeasonNumber.Equals(_ep2.SeasonNumber)) episodeChanged = true;
              if (!_ep1.SeriesId.Equals(_ep2.SeriesId)) episodeChanged = true;
              if (!_ep1.WriterString.Equals(_ep2.WriterString)) episodeChanged = true;

              return episodeChanged;
        }
예제 #11
0
        /// <summary>
        /// Update the series with the episode (Add it to the series if it doesn't already exist or update the episode if the current episode is older than the updated one)
        /// </summary>
        /// <param name="_series">Series of the updating episode</param>
        /// <param name="_episode">Episode that is updated</param>
        /// <param name="_progress">Progress of the update run</param>
        /// <param name="_text">Description of the current update</param>
        /// <returns>true if episode has been updated, false if not (e.g. timestamp of updated episode older than
        ///          timestamp of existing episode</returns> 
        private bool UpdateEpisode(TvdbSeries _series, TvdbEpisode _episode, int _progress, out String _text)
        {
            bool updateDone = false;
              _text = "";
              TvdbLanguage currentLanguage = _series.Language;
              foreach (KeyValuePair<TvdbLanguage, TvdbSeriesFields> kvp in _series.SeriesTranslations)
              {
            if (_series.EpisodesLoaded)
            {
              bool found = false;
              List<TvdbEpisode> eps = kvp.Value.Episodes;

              if (eps != null && eps.Count > 0)
              {
            //check all episodes if the updated episode is in it
            foreach (TvdbEpisode e in eps)
            {
              if (e.Id == _episode.Id)
              {
                found = true;
                if (e.LastUpdated < _episode.LastUpdated)
                {
                  //download episode which has been updated
                  TvdbEpisode newEpisode = null;
                  try
                  {
                    newEpisode = m_downloader.DownloadEpisode(e.Id, kvp.Key);
                  }
                  catch (TvdbContentNotFoundException)
                  {
                    Log.Warn("Couldn't download episode " + e.Id + "(" + e.EpisodeName + ")");
                  }
                  //update information of episode with new episodes informations
                  if (newEpisode != null)
                  {
                    newEpisode.LastUpdated = _episode.LastUpdated;

                    #region fix for http://forums.thetvdb.com/viewtopic.php?f=8&t=3993
                    //xml of single episodes doesn't contain  CombinedSeason and CombinedEpisodeNumber, so if
                    //we have values for those, don't override them
                    //-> http://forums.thetvdb.com/viewtopic.php?f=8&t=3993
                    //todo: remove this once tvdb fixed that issue
                    if (e.CombinedSeason != -99 && newEpisode.CombinedSeason == 0)
                    {
                      newEpisode.CombinedSeason = e.CombinedSeason;
                    }
                    if (e.CombinedEpisodeNumber != -99 && newEpisode.CombinedEpisodeNumber == 0)
                    {
                      newEpisode.CombinedEpisodeNumber = e.CombinedEpisodeNumber;
                    }
                    #endregion

                    e.UpdateEpisodeInfo(newEpisode);

                    e.Banner.CacheProvider = m_cacheProvider;
                    e.Banner.SeriesId = _series.Id;

                    e.Banner.UnloadBanner(false);
                    e.Banner.UnloadThumb(false);

                    _text = "Added/Updated episode " + _series.SeriesName + " " + e.SeasonNumber +
                            "x" + e.EpisodeNumber + "(id: " + e.Id + ")";
                    Log.Info("Updated Episode " + e.SeasonNumber + "x" + e.EpisodeNumber + " for series " + _series.SeriesName +
                             "(id: " + e.Id + ", lang: " + e.Language.Abbriviation + ")");
                    updateDone = true;
                  }
                }
                break;
              }
            }
              }

              if (!found)
              {
            //episode hasn't been found
            //hasn't been found -> add it to series
            TvdbEpisode ep = null;
            try
            {
              ep = m_downloader.DownloadEpisode(_episode.Id, kvp.Key);
            }
            catch (TvdbContentNotFoundException ex)
            {
              Log.Warn("Problem downloading " + _episode.Id + ": " + ex.ToString());
            }
            if (ep != null)
            {
              kvp.Value.Episodes.Add(ep);
              //sort the episodes according to default (aired) order
              kvp.Value.Episodes.Sort(new EpisodeComparerAired());
              _text = "Added/Updated episode " + _series.SeriesName + " " + ep.SeasonNumber +
                      "x" + ep.EpisodeNumber + "(id: " + ep.Id + ")";

              Log.Info("Added Episode " + ep.SeasonNumber + "x" + ep.EpisodeNumber + " for series " + _series.SeriesName +
                       "(id: " + ep.Id + ", lang: " + ep.Language.Abbriviation + ")");
              updateDone = true;
            }
              }
            }
            else
            {
              Log.Debug("Not handling episode " + _episode.Id + ", because series " + _series.SeriesName + " hasn't loaded episodes");
              updateDone = false;
            }
              }
              _series.SetLanguage(currentLanguage);
              return updateDone;
        }
예제 #12
0
        /// <summary>
        /// Retrieve the episode with the given parameters. This function will find
        /// episodes that are already cached.
        /// </summary>
        /// <param name="_seriesId">id of the series</param>
        /// <param name="_seasonNr">season number of the episode</param>
        /// <param name="_episodeNr">number of the episode</param>
        /// <param name="_language">language of the episode</param>
        /// <param name="_order">The sorting order that should be user when downloading the episode</param>
        /// <returns>The retrieved episode</returns>
        /// <exception cref="TvdbInvalidXmlException"><para>Exception is thrown when there was an error parsing the xml files. </para>
        ///                                           <para>Feel free to post a detailed description of this issue on http://code.google.com/p/tvdblib 
        ///                                           or http://forums.thetvdb.com/</para></exception>  
        /// <exception cref="TvdbContentNotFoundException">The episode/series/banner couldn't be located on the tvdb server.</exception>
        /// <exception cref="TvdbNotAvailableException">Exception is thrown when thetvdb isn't available.</exception>
        public TvdbEpisode GetEpisode(int _seriesId, int _seasonNr, int _episodeNr,
            TvdbEpisode.EpisodeOrdering _order, TvdbLanguage _language)
        {
            TvdbEpisode episode = null;
              if (m_cacheProvider != null && m_cacheProvider.Initialised)
              {
            if (m_cacheProvider.IsCached(_seriesId, _language, true, false, false))
            {
              TvdbSeries series = m_cacheProvider.LoadSeriesFromCache(_seriesId);
              if (series.Language != _language)
              {
            series.SetLanguage(_language);
              }

              if (series.Episodes != null)
              {
            foreach (TvdbEpisode e in series.Episodes)
            {
              if (e.EpisodeNumber == _episodeNr && e.SeasonNumber == _seasonNr && _order == TvdbEpisode.EpisodeOrdering.DefaultOrder ||
                  e.DvdEpisodeNumber == _episodeNr && e.SeasonNumber == _seasonNr && _order == TvdbEpisode.EpisodeOrdering.DvdOrder ||
                  e.AbsoluteNumber == _episodeNr && _order == TvdbEpisode.EpisodeOrdering.AbsoluteOrder)
              {//We found the episode that matches the episode number according to the given ordering
                episode = e;
                break;
              }
            }
              }
            }
              }

              if (episode == null)
              {//we havn't found the episode -> download it
            episode = m_downloader.DownloadEpisode(_seriesId, _seasonNr, _episodeNr, _order, _language);
              }

              return episode;
        }
예제 #13
0
 private void ReloadEpisode(TvdbSeries series, TvdbEpisode e)
 {
     throw new NotImplementedException();
 }
예제 #14
0
        /// <summary>
        /// Make the update
        /// </summary>
        /// <param name="_interval">interval of update</param>
        /// <param name="_zipped">zipped downloading yes/no</param>
        /// <returns>true if successful, false otherwise</returns>
        private bool MakeUpdate(Interval _interval, bool _zipped, bool _reloadOldContent)
        {
            Log.Info("Started update (" + _interval.ToString() + ")");
              Stopwatch watch = new Stopwatch();
              watch.Start();
              DateTime startUpdate = DateTime.Now;
              if (UpdateProgressed != null)
              {//update has started, we're downloading the updated content from tvdb
            UpdateProgressed(new UpdateProgressEventArgs(UpdateProgressEventArgs.UpdateStage.downloading,
                                                     "Downloading " + (_zipped ? " zipped " : " unzipped") +
                                                     " updated content (" + _interval.ToString() + ")",
                                                     0, 0));
              }

              //update all flagged series
              List<TvdbSeries> updateSeries;
              List<TvdbEpisode> updateEpisodes;
              List<TvdbBanner> updateBanners;

              List<int> updatedSeriesIds = new List<int>();
              List<int> updatedEpisodeIds = new List<int>();
              List<int> updatedBannerIds = new List<int>();

              DateTime updateTime = m_downloader.DownloadUpdate(out updateSeries, out updateEpisodes, out updateBanners, _interval, _zipped);
              List<int> cachedSeries = m_cacheProvider.GetCachedSeries();

              //list of all series that have been loaded from cache
              //and need to be saved to cache at the end of the update
              Dictionary<int, TvdbSeries> seriesToSave = new Dictionary<int, TvdbSeries>();

              if (UpdateProgressed != null)
              {//update has started, we're downloading the updated content from tvdb
            UpdateProgressed(new UpdateProgressEventArgs(UpdateProgressEventArgs.UpdateStage.seriesupdate,
                                                     "Begin updating series",
                                                     0, 25));
              }

              int countUpdatedSeries = updateSeries.Count;
              int countSeriesDone = 0;
              int lastProgress = 0;//send progress event at least every 1 percent
              String updateText = "Updating series";

              if (_reloadOldContent)
              {
            //if the last time an item (series or episode) was updated is longer ago than the timespan
            //we downloaded updates for, it's neccessary to completely reload the object to ensure that
            //the data is up to date.

            DateTime lastupdated = GetLastUpdate();

            TimeSpan span = new TimeSpan();
            switch (_interval)
            {
              case Interval.day:
            span = span.Add(new TimeSpan(1, 0, 0, 0));
            break;
              case Interval.week:
            span = span.Add(new TimeSpan(7, 0, 0, 0));
            break;
              case Interval.month:
            span = span.Add(new TimeSpan(30, 0, 0, 0));
            break;
            }

            if (lastupdated < DateTime.Now - span)
            {//the last update of the cache is longer ago than the timespan we make the update for
              List<int> allSeriesIds = m_cacheProvider.GetCachedSeries();
              foreach (int s in allSeriesIds)
              {
            //TvdbSeries series = m_cacheProvider.LoadSeriesFromCache(s);

            TvdbSeries series = null;
            if (seriesToSave.ContainsKey(s))
            {
              series = seriesToSave[s];
            }
            else
            {
              series = m_cacheProvider.LoadSeriesFromCache(s);
            }

            //ForceReload(series, false);
            if (series.LastUpdated > DateTime.Now - span)
            {
              //the series object is up to date, but some episodes might not be
              foreach (TvdbEpisode e in series.Episodes)
              {
                if (e.LastUpdated < DateTime.Now - span)
                {
                  if (Util.FindEpisodeInList(e.Id, updateEpisodes) == null)
                  {//The episode is not in the updates.xml file
                    TvdbEpisode newEp = new TvdbEpisode();
                    newEp.Id = e.Id;
                    newEp.LastUpdated = DateTime.Now;
                    updateEpisodes.Add(newEp);
                  }
                  if (!seriesToSave.ContainsKey(series.Id)) seriesToSave.Add(series.Id, series);

                }
              }
            }
            else
            {//the series hasn't been updated recently -> we need to do a complete re-download
              ForceReload(series, false);//redownload series and save it to cache
              countUpdatedSeries++;
              countSeriesDone++;
              int currProg = (int)(100.0 / countUpdatedSeries * countSeriesDone);
              updatedSeriesIds.Add(series.Id);
              updateText = "Reloaded series " + series.SeriesName + "(" + series.Id + ")";

              if (UpdateProgressed != null)
              {//update has started, we're downloading the updated content from tvdb
                UpdateProgressed(new UpdateProgressEventArgs(UpdateProgressEventArgs.UpdateStage.seriesupdate,
                                                             updateText, currProg, 25 + (int)(currProg / 4)));
              }
              //if (!seriesToSave.ContainsKey(series.Id)) seriesToSave.Add(series.Id, series);
            }
              }
            }
              }

              foreach (TvdbSeries us in updateSeries)
              {
            if (m_abortUpdate) break;//the update has been aborted
            //Update series that have been already cached
            foreach (int s in cachedSeries)
            {
              if (us.Id == s)
              {//changes occured in series
            TvdbSeries series = null;
            if (seriesToSave.ContainsKey(s))
            {
              series = seriesToSave[s];
            }
            else
            {
              series = m_cacheProvider.LoadSeriesFromCache(s);
            }

            int currProg = (int)(100.0 / countUpdatedSeries * countSeriesDone);

            bool updated = UpdateSeries(series, us.LastUpdated, currProg);
            if (updated)
            {//the series has been updated
              updatedSeriesIds.Add(us.Id);
              updateText = "Updated series " + series.SeriesName + "(" + series.Id + ")";
              //store the updated series to cache
              if (!seriesToSave.ContainsKey(series.Id)) seriesToSave.Add(series.Id, series);
            }

            if (updated || currProg > lastProgress)
            {//the series has been updated OR the last event was fired at least one percent ago
              if (UpdateProgressed != null)
              {//update has started, we're downloading the updated content from tvdb
                UpdateProgressed(new UpdateProgressEventArgs(UpdateProgressEventArgs.UpdateStage.seriesupdate,
                                                             updateText, currProg, 25 + (int)(currProg / 4)));
              }
              lastProgress = currProg;
            }

            break;
              }
            }
            countSeriesDone++;
              }

              int countEpisodeUpdates = updateEpisodes.Count; ;
              int countEpisodesDone = 0;
              lastProgress = 0;
              updateText = "Updating episodes";
              //update all flagged episodes
              foreach (TvdbEpisode ue in updateEpisodes)
              {
            if (m_abortUpdate) break;//the update has been aborted

            foreach (int s in cachedSeries)
            {
              if (ue.SeriesId == s)
              {//changes occured in series
            TvdbSeries series = null;
            if (seriesToSave.ContainsKey(s))
            {
              series = seriesToSave[s];
            }
            else
            {
              series = m_cacheProvider.LoadSeriesFromCache(ue.SeriesId);
            }

            int progress = (int)(100.0 / countEpisodeUpdates * countEpisodesDone);
            String text = "";
            bool updated = UpdateEpisode(series, ue, progress, out text);
            if (updated)
            {//The episode was updated or added
              updatedEpisodeIds.Add(ue.Id);
              if (!seriesToSave.ContainsKey(series.Id)) seriesToSave.Add(series.Id, series);
              updateText = text;
            }
            if (updated || progress > lastProgress)
            {
              if (UpdateProgressed != null)
              {//update has started, we're downloading the updated content from tvdb
                UpdateProgressed(new UpdateProgressEventArgs(UpdateProgressEventArgs.UpdateStage.episodesupdate,
                                                             updateText, progress, 50 + (int)(progress / 4)));
              }
            }
            break;
              }
            }
            countEpisodesDone++;
              }

              int countUpdatedBanner = updateBanners.Count;
              int countBannerDone = 0;
              lastProgress = 0;
              updateText = "Updating banners";
              // todo: update banner information here -> wait for forum response regarding
              // missing banner id within updates (atm. I'm matching banners via path)
              foreach (TvdbBanner b in updateBanners)
              {
            if (m_abortUpdate) break;//the update has been aborted

            foreach (int s in cachedSeries)
            {
              if (b.SeriesId == s)
              {//banner for this series has changed
            int currProg = (int)(100.0 / countUpdatedBanner * countBannerDone);
            TvdbSeries series = null;
            if (seriesToSave.ContainsKey(s))
            {
              series = seriesToSave[s];
            }
            else
            {
              series = m_cacheProvider.LoadSeriesFromCache(b.SeriesId);
            }
            bool updated = UpdateBanner(series, b);
            if (updated)
            {
              updatedBannerIds.Add(b.Id);
              if (!seriesToSave.ContainsKey(series.Id)) seriesToSave.Add(series.Id, series);
            }

            if (updated || currProg > lastProgress)
            {
              if (UpdateProgressed != null)
              {//update has started, we're downloading the updated content from tvdb

                UpdateProgressed(new UpdateProgressEventArgs(UpdateProgressEventArgs.UpdateStage.bannerupdate,
                                                             "Updating banner " + b.BannerPath + "(id=" + b.Id + ")",
                                                             currProg, 75 + (int)(currProg / 4)));
              }
            }
            break;
              }
            }
            countBannerDone++;
              }

              if (!m_abortUpdate)
              {//update has finished successfully
            if (UpdateProgressed != null)
            {
              UpdateProgressed(new UpdateProgressEventArgs(UpdateProgressEventArgs.UpdateStage.finishupdate,
                                                       "Update finished, saving loaded information to cache",
                                                       100, 100));
            }
              }
              else
              {//the update has been aborted
            if (UpdateProgressed != null)
            {
              UpdateProgressed(new UpdateProgressEventArgs(UpdateProgressEventArgs.UpdateStage.finishupdate,
                                                       "Update aborted by user, " +
                                                       (m_abortUpdateSaveChanges ? " saving " : " not saving ") +
                                                       "already loaded information to cache",
                                                       100, 100));
            }
              }

              if (!m_abortUpdate || m_abortUpdateSaveChanges)
              {//store the information we downloaded to cache
            Log.Info("Saving all series to cache that have been modified during the update (" + seriesToSave.Count + ")");
            foreach (KeyValuePair<int, TvdbSeries> kvp in seriesToSave)
            {//Save all series to cache that have been modified during the update
              try
              {
            m_cacheProvider.SaveToCache(kvp.Value);
              }
              catch (Exception ex)
              {
            Log.Warn("Couldn't save " + kvp.Key + " to cache: " + ex.ToString());
              }
            }
              }

              if (!m_abortUpdate)
              {//update finished and wasn't aborted
            //set the last updated time to time of this update
            m_loadedData.LastUpdated = updateTime;
            m_cacheProvider.SaveToCache(m_loadedData);
              }

              watch.Stop();

              Log.Info("Finished update (" + _interval.ToString() + ") in " + watch.ElapsedMilliseconds + " milliseconds");
              if (UpdateFinished != null)
              {
            if (!m_abortUpdate || m_abortUpdateSaveChanges)
            {//we either updated everything successfully or we at least saved the changes made before the update completed
              UpdateFinished(new UpdateFinishedEventArgs(startUpdate, DateTime.Now, updatedSeriesIds, updatedEpisodeIds, updatedBannerIds));
            }
            else
            {//we didn't update anything because the update was aborted
              UpdateFinished(new UpdateFinishedEventArgs(startUpdate, DateTime.Now, new List<int>(), new List<int>(), new List<int>()));

            }
              }
              return true;
        }
예제 #15
0
        private void FillEpisodeDetails(TvdbEpisode _before, TvdbEpisode _after, TvdbEpisode _current)
        {
            lvSeriesDetails.Items.Clear();
              //id
              lvSeriesDetails.Items.Add(CreateItem("Id", _before != null ? _before.Id.ToString() : "",
                                                 _after != null ? _after.Id.ToString() : "",
                                                 _current != null ? _current.Id.ToString() : ""));

              //EpisodeNumber
              lvSeriesDetails.Items.Add(CreateItem("EpisodeNumber", _before != null ? _before.EpisodeNumber.ToString() : "",
                                           _after != null ? _after.EpisodeNumber.ToString() : "",
                                           _current != null ? _current.EpisodeNumber.ToString() : ""));

              //EpisodeName
              lvSeriesDetails.Items.Add(CreateItem("EpisodeName", _before != null ? _before.EpisodeName.ToString() : "",
                                           _after != null ? _after.EpisodeName.ToString() : "",
                                           _current != null ? _current.EpisodeName.ToString() : ""));

              //FirstAired
              lvSeriesDetails.Items.Add(CreateItem("FirstAired", _before != null ? _before.FirstAired.ToString() : "",
                                           _after != null ? _after.FirstAired.ToString() : "",
                                           _current != null ? _current.FirstAired.ToString() : ""));

              //GuestStarsString
              lvSeriesDetails.Items.Add(CreateItem("GuestStarsString", _before != null ? _before.GuestStarsString.ToString() : "",
                                           _after != null ? _after.GuestStarsString.ToString() : "",
                                           _current != null ? _current.GuestStarsString.ToString() : ""));

              //DirectorsString
              lvSeriesDetails.Items.Add(CreateItem("DirectorsString", _before != null ? _before.DirectorsString.ToString() : "",
                                           _after != null ? _after.DirectorsString.ToString() : "",
                                           _current != null ? _current.DirectorsString.ToString() : ""));

              //WriterString
              lvSeriesDetails.Items.Add(CreateItem("WriterString", _before != null ? _before.WriterString.ToString() : "",
                                           _after != null ? _after.WriterString.ToString() : "",
                                           _current != null ? _current.WriterString.ToString() : ""));

              //Overview
              lvSeriesDetails.Items.Add(CreateItem("Overview", _before != null ? _before.Overview.ToString() : "",
                                           _after != null ? _after.Overview.ToString() : "",
                                           _current != null ? _current.Overview.ToString() : ""));

              //ProductionCode
              lvSeriesDetails.Items.Add(CreateItem("ProductionCode", _before != null ? _before.ProductionCode.ToString() : "",
                                           _after != null ? _after.ProductionCode.ToString() : "",
                                           _current != null ? _current.ProductionCode.ToString() : ""));

              //language
              lvSeriesDetails.Items.Add(CreateItem("language", _before != null ? _before.Language.ToString() : "",
                                           _after != null ? _after.Language.ToString() : "",
                                           _current != null ? _current.Language.ToString() : ""));

              //rating
              lvSeriesDetails.Items.Add(CreateItem("rating", _before != null ? _before.Rating.ToString() : "",
                                           _after != null ? _after.Rating.ToString() : "",
                                           _current != null ? _current.Rating.ToString() : ""));

              //banner
              lvSeriesDetails.Items.Add(CreateItem("banner", _before != null ? _before.BannerPath.ToString() : "",
                                           _after != null ? _after.BannerPath.ToString() : "",
                                           _current != null ? _current.BannerPath.ToString() : ""));

              //lastupdated
              lvSeriesDetails.Items.Add(CreateItem("lastupdated", _before != null ? _before.LastUpdated.ToString() : "",
                                           _after != null ? _after.LastUpdated.ToString() : "",
                                           _current != null ? _current.LastUpdated.ToString() : ""));

              //////////////////////////////////

              //DvdDiscId
              lvSeriesDetails.Items.Add(CreateItem("DvdDiscId", _before != null ? _before.DvdDiscId.ToString() : "",
                                           _after != null ? _after.DvdDiscId.ToString() : "",
                                           _current != null ? _current.DvdDiscId.ToString() : ""));

              //DvdSeason
              lvSeriesDetails.Items.Add(CreateItem("DvdSeason", _before != null ? _before.DvdSeason.ToString() : "",
                                           _after != null ? _after.DvdSeason.ToString() : "",
                                           _current != null ? _current.DvdSeason.ToString() : ""));

              //DvdEpisodeNumber
              lvSeriesDetails.Items.Add(CreateItem("DvdEpisodeNumber", _before != null ? _before.DvdEpisodeNumber.ToString() : "",
                                           _after != null ? _after.DvdEpisodeNumber.ToString() : "",
                                           _current != null ? _current.DvdEpisodeNumber.ToString() : ""));

              //DvdChapter
              lvSeriesDetails.Items.Add(CreateItem("DvdChapter", _before != null ? _before.DvdChapter.ToString() : "",
                                           _after != null ? _after.DvdChapter.ToString() : "",
                                           _current != null ? _current.DvdChapter.ToString() : ""));

              //AbsoluteNumber
              lvSeriesDetails.Items.Add(CreateItem("AbsoluteNumber", _before != null ? _before.AbsoluteNumber.ToString() : "",
                                           _after != null ? _after.AbsoluteNumber.ToString() : "",
                                           _current != null ? _current.AbsoluteNumber.ToString() : ""));

              //CombinedEpisodeNumber
              lvSeriesDetails.Items.Add(CreateItem("CombinedEpisodeNumber", _before != null ? _before.CombinedEpisodeNumber.ToString() : "",
                                           _after != null ? _after.CombinedEpisodeNumber.ToString() : "",
                                           _current != null ? _current.CombinedEpisodeNumber.ToString() : ""));

              //CombinedSeason
              lvSeriesDetails.Items.Add(CreateItem("CombinedSeason", _before != null ? _before.CombinedSeason.ToString() : "",
                                           _after != null ? _after.CombinedSeason.ToString() : "",
                                           _current != null ? _current.CombinedSeason.ToString() : ""));

              //AbsoluteNumber
              lvSeriesDetails.Items.Add(CreateItem("AbsoluteNumber", _before != null ? _before.AbsoluteNumber.ToString() : "",
                                           _after != null ? _after.AbsoluteNumber.ToString() : "",
                                           _current != null ? _current.AbsoluteNumber.ToString() : ""));

              //SeriesId
              lvSeriesDetails.Items.Add(CreateItem("SeriesId", _before != null ? _before.SeriesId.ToString() : "",
                                           _after != null ? _after.SeriesId.ToString() : "",
                                           _current != null ? _current.SeriesId.ToString() : ""));

              //ImdbId
              lvSeriesDetails.Items.Add(CreateItem("ImdbId", _before != null ? _before.ImdbId.ToString() : "",
                                           _after != null ? _after.ImdbId.ToString() : "",
                                           _current != null ? _current.ImdbId.ToString() : ""));

              //SeasonNumber
              lvSeriesDetails.Items.Add(CreateItem("SeasonNumber", _before != null ? _before.SeasonNumber.ToString() : "",
                                           _after != null ? _after.SeasonNumber.ToString() : "",
                                           _current != null ? _current.SeasonNumber.ToString() : ""));

              //AirsAfterSeason
              lvSeriesDetails.Items.Add(CreateItem("AirsAfterSeason", _before != null ? _before.AirsAfterSeason.ToString() : "",
                                           _after != null ? _after.AirsAfterSeason.ToString() : "",
                                           _current != null ? _current.AirsAfterSeason.ToString() : ""));

              //AirsBeforeSeason
              lvSeriesDetails.Items.Add(CreateItem("AirsBeforeSeason", _before != null ? _before.AirsBeforeSeason.ToString() : "",
                                           _after != null ? _after.AirsBeforeSeason.ToString() : "",
                                           _current != null ? _current.AirsBeforeSeason.ToString() : ""));

              //AirsBeforeEpisode
              lvSeriesDetails.Items.Add(CreateItem("AirsBeforeEpisode", _before != null ? _before.AirsBeforeEpisode.ToString() : "",
                                           _after != null ? _after.AirsBeforeEpisode.ToString() : "",
                                           _current != null ? _current.AirsBeforeEpisode.ToString() : ""));
        }
예제 #16
0
        /// <summary>
        /// Retrieve the episode with the given parameters
        /// </summary>
        /// <param name="_seriesId">id of the series</param>
        /// <param name="_seasonNr">season number of the episode</param>
        /// <param name="_episodeNr">number of the episode</param>
        /// <param name="_language">language of the episode</param>
        /// <param name="_order">The sorting order that should be user when downloading the episode</param>
        /// <returns>The retrieved episode</returns>
        public TvdbEpisode GetEpisode(int _seriesId, int _seasonNr, int _episodeNr,
            TvdbEpisode.EpisodeOrdering _order, TvdbLanguage _language)
        {
            String order = null;
              switch (_order)
              {
            case TvdbEpisode.EpisodeOrdering.AbsoluteOrder:
              order = "absolut";
              break;
            case TvdbEpisode.EpisodeOrdering.DefaultOrder:
              order = "default";
              break;
            case TvdbEpisode.EpisodeOrdering.DvdOrder:
              order = "dvd";
              break;
              }

              TvdbEpisode episode = m_downloader.DownloadEpisode(_seriesId, _seasonNr, _episodeNr, order, _language);
              return episode;
        }
예제 #17
0
 /// <summary>
 /// Updates all information of this episode from the given
 /// episode...
 /// </summary>
 /// <param name="_episode">new episode</param>
 internal void UpdateEpisodeInfo(TvdbEpisode _episode)
 {
     this.LastUpdated = _episode.LastUpdated;
       this.BannerPath = _episode.BannerPath;
       this.Banner = _episode.Banner;
       this.AbsoluteNumber = _episode.AbsoluteNumber;
       this.CombinedEpisodeNumber = _episode.CombinedEpisodeNumber;
       this.CombinedSeason = _episode.CombinedSeason;
       this.Directors = _episode.Directors;
       this.DvdChapter = _episode.DvdChapter;
       this.DvdDiscId = _episode.DvdDiscId;
       this.DvdEpisodeNumber = _episode.DvdEpisodeNumber;
       this.DvdSeason = _episode.DvdSeason;
       this.EpisodeName = _episode.EpisodeName;
       this.EpisodeNumber = _episode.EpisodeNumber;
       this.FirstAired = _episode.FirstAired;
       this.GuestStars = _episode.GuestStars;
       this.ImdbId = _episode.ImdbId;
       this.Language = _episode.Language;
       this.Overview = _episode.Overview;
       this.ProductionCode = _episode.ProductionCode;
       this.Rating = _episode.Rating;
       this.SeasonId = _episode.SeasonId;
       this.SeasonNumber = _episode.SeasonNumber;
       this.Writer = _episode.Writer;
 }
예제 #18
0
        /// <summary>
        /// Extract a list of episodes from the given data when the data has the following format:
        /// <![CDATA[
        ///  <?xml version="1.0" encoding="UTF-8" ?>
        ///  <Episode>
        ///      <id>332179</id>
        ///      <DVD_chapter></DVD_chapter>
        ///      <DVD_discid></DVD_discid>
        ///      <DVD_episodenumber></DVD_episodenumber>
        ///      <DVD_season></DVD_season>
        ///      <Director>|Joseph McGinty Nichol|</Director>
        ///      <EpisodeName>Chuck Versus the World</EpisodeName>
        ///      <EpisodeNumber>1</EpisodeNumber>
        ///      <FirstAired>2007-09-24</FirstAired>
        ///      <GuestStars>|Julia Ling|Vik Sahay|Mieko Hillman|</GuestStars>
        ///      <IMDB_ID></IMDB_ID>
        ///      <Language>English</Language>
        ///      <Overview>Chuck Bartowski is an average computer geek...</Overview>
        ///      <ProductionCode></ProductionCode>
        ///      <Rating>9.0</Rating>
        ///      <SeasonNumber>1</SeasonNumber>
        ///      <Writer>|Josh Schwartz|Chris Fedak|</Writer>
        ///      <absolute_number></absolute_number>
        ///      <airsafter_season></airsafter_season>
        ///      <airsbefore_episode></airsbefore_episode>
        ///      <airsbefore_season></airsbefore_season>
        ///      <filename>episodes/80348-332179.jpg</filename>
        ///      <lastupdated>1201292806</lastupdated>
        ///      <seasonid>27985</seasonid>
        ///      <seriesid>80348</seriesid>
        ///  </Episode>
        ///  ]]>
        /// </summary>
        /// <param name="_data"></param>
        /// <returns></returns>
        internal List<TvdbEpisode> ExtractEpisodes(String _data)
        {
            //Stopwatch watch = new Stopwatch();
              //watch.Start();
              XDocument xml = XDocument.Parse(_data);
              var allEpisodes = from episode in xml.Descendants("Episode")
                        select new
                        {
                          Id = episode.Element("id").Value,
                          Combined_episodenumber = episode.Elements("Combined_episodenumber").Count() == 1
                                                 ? episode.Element("Combined_episodenumber").Value : "0",
                          Combined_season = episode.Elements("Combined_season").Count() == 1
                                          ? episode.Element("Combined_season").Value : "0",
                          DVD_chapter = episode.Element("DVD_chapter").Value,
                          DVD_discid = episode.Element("DVD_discid").Value,
                          DVD_episodenumber = episode.Element("DVD_episodenumber").Value,
                          DVD_season = episode.Elements("DVD_season").Count() == 1
                                       ? episode.Element("DVD_season").Value : episode.Element("DVD_Season").Value,
                          Director = episode.Element("Director").Value,
                          EpisodeName = episode.Element("EpisodeName").Value,
                          EpisodeNumber = episode.Element("EpisodeNumber").Value,
                          FirstAired = episode.Element("FirstAired").Value,
                          GuestStars = episode.Element("GuestStars").Value,
                          IMDB_ID = episode.Element("IMDB_ID").Value,
                          Language = episode.Elements("Language").Count() == 1
                                     ? episode.Element("Language").Value : "en",
                          Overview = episode.Element("Overview").Value,
                          ProductionCode = episode.Element("ProductionCode").Value,
                          Rating = episode.Element("Rating").Value,
                          SeasonNumber = episode.Element("SeasonNumber").Value,
                          Writer = episode.Element("Writer").Value,
                          absolute_number = episode.Element("absolute_number").Value,
                          filename = episode.Element("filename").Value,
                          lastupdated = episode.Element("lastupdated").Value,
                          seasonid = episode.Element("seasonid").Value,
                          seriesid = episode.Element("seriesid").Value,
                          airsafter_season = episode.Elements("airsafter_season").Count() == 1
                                           ? episode.Element("airsafter_season").Value : "-99",
                          airsbefore_episode = episode.Elements("airsbefore_episode").Count() == 1
                                             ? episode.Element("airsbefore_episode").Value : "-99",
                          airsbefore_season = episode.Elements("airsbefore_season").Count() == 1
                                            ? episode.Element("airsbefore_season").Value : "-99"
                        };
              //Log.Debug("Parsed xml file in  " + watch.ElapsedMilliseconds + " milliseconds");
              List<TvdbEpisode> retList = new List<TvdbEpisode>();
              foreach (var e in allEpisodes)
              {
            TvdbEpisode ep = new TvdbEpisode();
            ep.Id = Util.Int32Parse(e.Id);
            ep.CombinedEpisodeNumber = Util.DoubleParse(e.Combined_episodenumber);
            ep.CombinedSeason = Util.DoubleParse(e.Combined_season);
            ep.DvdChapter = Util.Int32Parse(e.DVD_chapter);
            ep.DvdDiscId = Util.Int32Parse(e.DVD_discid);
            ep.DvdEpisodeNumber = Util.DoubleParse(e.DVD_episodenumber);
            ep.DvdSeason = Util.Int32Parse(e.DVD_season);
            ep.Directors = Util.SplitTvdbString(e.Director);
            ep.EpisodeName = e.EpisodeName;
            ep.EpisodeNumber = Util.Int32Parse(e.EpisodeNumber);
            ep.AirsAfterSeason = Util.Int32Parse(e.airsafter_season);
            ep.AirsBeforeEpisode = Util.Int32Parse(e.airsbefore_episode);
            ep.AirsBeforeSeason = Util.Int32Parse(e.airsbefore_season);
            try
            {
              ep.FirstAired = e.FirstAired.Equals("") ? new DateTime(1, 1, 1) : DateTime.Parse(e.FirstAired);
            }
            catch (Exception)
            {
              ep.FirstAired = new DateTime();
            }
            ep.GuestStars = Util.SplitTvdbString(e.GuestStars);
            ep.ImdbId = e.IMDB_ID;
            ep.Language = Util.ParseLanguage(e.Language);
            ep.Overview = e.Overview;
            ep.ProductionCode = e.ProductionCode;
            ep.Rating = Util.DoubleParse(e.Rating);
            ep.SeasonNumber = Util.Int32Parse(e.SeasonNumber);
            ep.Writer = Util.SplitTvdbString(e.Writer);
            ep.AbsoluteNumber = Util.Int32Parse(e.absolute_number);
            ep.BannerPath = e.filename;
            ep.Banner = new TvdbEpisodeBanner(ep.Id, ep.BannerPath);
            ep.LastUpdated = Util.UnixToDotNet(e.lastupdated);
            ep.SeasonId = Util.Int32Parse(e.seasonid);
            ep.SeriesId = Util.Int32Parse(e.seriesid);

            if (ep.Id != -99) retList.Add(ep);
              }

              //watch.Stop();
              //Log.Debug("Extracted " + retList.Count + " Episodes in " + watch.ElapsedMilliseconds + " milliseconds");
              return retList;
        }
예제 #19
0
        private ItemState CheckEpisodeChanged(TvdbEpisode _before, TvdbEpisode _after, TvdbEpisode _current)
        {
            if (_current != null)
              {
            if (_after != null)
            {//episode has been updated (_before != null) or added (_before == null)
              if (EpsiodeChanged(_after, _current))
              {
            if (_before == null)
            {
              return ItemState.AddedAndInconsistent;
            }
            else
            {
              return ItemState.UpdatedAndInconsistent;
            }
              }
              else
              {
            if (_before == null)
            {//the item has been added correctly
              return ItemState.Added;
            }
            else
            {//the item has been updated correctly (after == current)
              if (EpsiodeChanged(_before, _after))
              {
                return ItemState.UpdatedAndValueChanged;
              }
              else
              {
                return ItemState.Updated;
              }
            }
              }
            }

            //episode is available but hasn't been added to our cache yet
            if (_before == null && _after == null) return ItemState.AvailableButNotDownloaded;

            //we have no update for this item
            if (_after == null)
            {
              if (EpsiodeChanged(_before, _current))
              {
            return ItemState.UnchangedAndInconsistent;
              }
              else
              {
            return ItemState.Unchanged;
              }
            }
              }

              if (_current == null)
              {//current version hasn't been loaded, we can't compare if the update was done correctly
            if (_before != null && _after != null)
            {//episode has been updated
              return ItemState.Updated;
            }
            else if (_before == null && _after != null)
            {//episode has been added
              return ItemState.Added;
            }
            else
            {
              return ItemState.Unchanged;
            }
              }

              return ItemState.Unchanged;
        }