Beispiel #1
0
 /// <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;
       }
 }
Beispiel #2
0
        /// <summary>
        /// Extract all the series fields that are available on thetvdb
        /// <![CDATA[
        /// <?xml version="1.0" encoding="UTF-8" ?>
        /// <Data>
        ///    <Series>
        ///       <id>73739</id>
        ///       <Actors>|Malcolm David Kelley|Jorge Garcia|Maggie Grace|...|</Actors>
        ///       <Airs_DayOfWeek>Thursday</Airs_DayOfWeek>
        ///       <Airs_Time>9:00 PM</Airs_Time>
        ///       <ContentRating>TV-14</ContentRating>
        ///       <FirstAired>2004-09-22</FirstAired>
        ///       <Genre>|Action and Adventure|Drama|Science-Fiction|</Genre>
        ///       <IMDB_ID>tt0411008</IMDB_ID>
        ///       <Language>en</Language>
        ///       <Network>ABC</Network>
        ///       <Overview>After Oceanic Air flight 815...</Overview>
        ///       <Rating>8.9</Rating>
        ///       <Runtime>60</Runtime>
        ///       <SeriesID>24313</SeriesID>
        ///       <SeriesName>Lost</SeriesName>
        ///       <Status>Continuing</Status>
        ///       <banner>graphical/24313-g2.jpg</banner>
        ///       <fanart>fanart/original/73739-1.jpg</fanart>
        ///       <lastupdated>1205694666</lastupdated>
        ///       <zap2it_id>SH672362</zap2it_id>
        ///    </Series>
        ///  
        /// </Data>
        /// ]]>
        /// </summary>
        /// <param name="_data"></param>
        /// <returns></returns>
        internal List<TvdbSeriesFields> ExtractSeriesFields(String _data)
        {
            Stopwatch watch = new Stopwatch();
              watch.Start();
              XDocument xml = XDocument.Parse(_data);

              var allSeries = from series in xml.Descendants("Series")
                      select new
                      {
                        Id = series.Element("id").Value,
                        Actors = series.Element("Actors").Value,
                        Airs_DayOfWeek = series.Element("Airs_DayOfWeek").Value,
                        Airs_Time = series.Element("Airs_Time").Value,
                        ContentRating = series.Element("ContentRating").Value,
                        FirstAired = series.Element("FirstAired").Value,
                        Genre = series.Element("Genre").Value,
                        IMDB_ID = series.Element("IMDB_ID").Value,
                        Language = series.Element("Language").Value,
                        Network = series.Element("Network").Value,
                        Overview = series.Element("Overview").Value,
                        Rating = series.Element("Rating").Value,
                        Runtime = series.Element("Runtime").Value,
                        SeriesID = series.Element("SeriesID").Value,
                        SeriesName = series.Element("SeriesName").Value,
                        Status = series.Element("Status").Value,
                        banner = series.Element("banner").Value,
                        fanart = series.Element("fanart").Value,
                        lastupdated = series.Element("lastupdated").Value,
                        zap2it_id = series.Element("zap2it_id").Value
                      };

              List<TvdbSeriesFields> retList = new List<TvdbSeriesFields>();
              foreach (var s in allSeries)
              {
            TvdbSeries series = new TvdbSeries();
            series.Id = Util.Int32Parse(s.Id);
            series.Actors = Util.SplitTvdbString(s.Actors);
            series.AirsDayOfWeek = Util.GetDayOfWeek(s.Airs_DayOfWeek);
            series.AirsTime = s.Airs_Time.Equals("") ? new DateTime(1, 1, 1) : DateTime.Parse(s.Airs_Time.Replace(".", ":"));
            series.ContentRating = s.ContentRating;
            series.FirstAired = s.FirstAired.Equals("") ? new DateTime() : DateTime.Parse(s.FirstAired);
            series.Genre = Util.SplitTvdbString(s.Genre);
            series.ImdbId = s.IMDB_ID;
            series.Language = Util.ParseLanguage(s.Language);
            series.Network = s.Network;
            series.Overview = s.Overview;
            series.Rating = Util.DoubleParse(s.Rating);
            series.Runtime = Util.DoubleParse(s.Runtime);
            series.TvDotComId = Util.Int32Parse(s.SeriesID);
            series.SeriesName = s.SeriesName;
            series.Status = s.Status;
            series.BannerPath = s.banner;
            series.FanartPath = s.fanart;
            series.LastUpdated = Util.UnixToDotNet(s.lastupdated);
            series.Zap2itId = s.zap2it_id;
            if (series.Id != -99) retList.Add(series);
              }

              watch.Stop();
              Log.Debug("Extracted " + retList.Count + " series in " + watch.ElapsedMilliseconds + " milliseconds");
              return retList;
        }
Beispiel #3
0
        private void FillFullSeriesDetails(TvdbSeries _series)
        {
            List<TvdbSeasonBanner> seasonBannerList = _series.SeasonBanners;
              tvEpisodes.Nodes.Clear();
              foreach (TvdbEpisode e in _series.Episodes)
              {
            bool found = false;
            foreach (TreeNode seasonNode in tvEpisodes.Nodes)
            {
              if (((SeasonTag)seasonNode.Tag).SeasonId == e.SeasonId)
              {
            TreeNode node = new TreeNode(e.EpisodeNumber + " - " + e.EpisodeName);
            node.Tag = e;
            seasonNode.Nodes.Add(node);
            found = true;
            break;
              }
            }
            if (!found)
            {
              TreeNode node = new TreeNode("Season " + e.SeasonNumber);

              List<TvdbSeasonBanner> tagList = new List<TvdbSeasonBanner>();
              foreach (TvdbSeasonBanner b in seasonBannerList)
              {
            if (b.Season == e.SeasonNumber) tagList.Add(b);
              }
              SeasonTag tag = new SeasonTag(e.SeasonNumber, e.SeasonId, tagList);
              node.Tag = tag;
              tvEpisodes.Nodes.Add(node);

              TreeNode epNode = new TreeNode(e.EpisodeNumber + " - " + e.EpisodeName);
              epNode.Tag = e;
              node.Nodes.Add(epNode);
            }
              }
        }
Beispiel #4
0
        /// <summary>
        /// Add this episode to the proper cached series
        /// </summary>
        /// <param name="_episode">Episode to add to cache</param>
        private void AddEpisodeToCache(TvdbEpisode _episode)
        {
            bool seriesFound = false;
              foreach (TvdbSeries s in m_loadedData.SeriesList)
              {
            if (s.Id == _episode.SeriesId)
            {//series for ep found
              seriesFound = true;
              Util.AddEpisodeToSeries(_episode, s);
              break;
            }

              }

              //todo: maybe skip this since downloading an episode is no biggie
              if (!seriesFound)
              {//the series doesn't exist yet -> add episode to dummy series
            TvdbSeries newSeries = new TvdbSeries();
            newSeries.LastUpdated = new DateTime(1, 1, 1);
            newSeries.Episodes.Add(_episode);
            m_loadedData.SeriesList.Add(newSeries);
              }
        }
Beispiel #5
0
        /// <summary>
        /// Forces a complete update of the series. All information that has already been loaded (including loaded images!) will be deleted and reloaded from tvdb -> if you only want to update the series, use the "MakeUpdate" method
        /// </summary>
        /// <param name="_series">Series to update</param>
        /// <param name="_loadEpisodes">Should episodes be loaded as well</param>
        /// <param name="_loadActors">Should actors be loaded as well</param>
        /// <param name="_loadBanners">Should banners be loaded as well</param>
        /// <returns></returns>
        public TvdbSeries ForceUpdate(TvdbSeries _series, bool _loadEpisodes,
            bool _loadActors, bool _loadBanners)
        {
            for (int i = 0; i < m_loadedData.SeriesList.Count; i++)
              {
            if (((TvdbSeries)m_loadedData.SeriesList[i]).Id == _series.Id)
            {
              m_loadedData.SeriesList.Remove((TvdbSeries)m_loadedData.SeriesList[i]);
            }
              }

              _series = m_downloader.DownloadSeries(_series.Id, _series.Language, _loadEpisodes,
                                      _loadActors, _loadBanners);

              m_loadedData.SeriesList.Add(_series);

              return _series;
        }
Beispiel #6
0
 /// <summary>
 /// Adds the series to the users list of favorites and returns the new list of
 /// favorites
 /// </summary>
 /// <param name="_series">series to add to the favorites</param>
 /// <returns>new list with all favorites</returns>
 public List<int> AddSeriesToFavorites(TvdbSeries _series)
 {
     if (_series == null) return null;
       return AddSeriesToFavorites(_series.Id);
 }
Beispiel #7
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="s"></param>
        /// <param name="ue"></param>
        private void UpdateEpisode(TvdbSeries s, TvdbEpisode ue)
        {
            List<TvdbEpisode> allEpList = new List<TvdbEpisode>();
              allEpList.AddRange(s.Episodes);
              foreach (TvdbLanguage l in s.GetAvailableLanguages())
              {
            if (s.SeriesTranslations[l].Episodes != null && s.SeriesTranslations[l].Language != s.Language)
            {
              allEpList.AddRange(s.SeriesTranslations[l].Episodes);
            }
              }

              //check all episodes if the updated episode is in it
              foreach (TvdbEpisode e in allEpList)
              {
            if (e.Id == ue.Id)
            {
              if (e.LastUpdated < ue.LastUpdated)
              {
            //download episode which has been updated
            TvdbEpisode newEpisode = m_downloader.DownloadEpisode(e.Id, e.Language);

            //update information of episode with new episodes informations
            if (newEpisode != null)
            {
              newEpisode.LastUpdated = ue.LastUpdated;

              e.UpdateEpisodeInfo(newEpisode);
              Log.Info("Updated Episode " + e.Id + " for series " + e.SeriesId);
            }
              }
              return;
            }
              }

              //episode hasn't been found
              foreach (TvdbLanguage l in s.GetAvailableLanguages())
              {
            //hasn't been found -> add it
            TvdbEpisode ep = m_downloader.DownloadEpisode(ue.Id, l);
            AddEpisodeToCache(ep);
            Log.Info("Added Episode " + ep.Id + " for series " + ep.SeriesId);
              }
        }
Beispiel #8
0
 /// <summary>
 /// Write the series content to file
 /// </summary>
 /// <param name="_series"></param>
 /// <param name="_path"></param>
 /// <returns></returns>
 internal bool WriteSeriesContent(TvdbSeries _series, String _path)
 {
     String fileContent = CreateSeriesContent(_series);
       try
       {
     FileInfo info = new FileInfo(_path);
     if (!info.Directory.Exists) info.Directory.Create();
     File.WriteAllText(info.FullName , fileContent);
     return true;
       }
       catch (Exception)
       {
     return false;
       }
 }
Beispiel #9
0
        internal TvdbSeries DownloadSeriesZipped(int _seriesId, TvdbLanguage _language)
        {
            //download the xml data from this request
            byte[] data;
            try
            {
                data = m_webClient.DownloadData(TvdbLinks.CreateSeriesLinkZipped(m_apiKey, _seriesId, _language));
            }
            catch (WebException ex)
            {
                Log.Warn("Request not successfull", ex);
                if (ex.Message.Equals("The remote server returned an error: (404) Not Found."))
                {
                    throw new TvdbInvalidApiKeyException("Couldn't connect to Thetvdb.com to retrieve " + _seriesId +
                                                         ", it seems like you have an invalid api key (" + m_apiKey + ")");
                }
                else
                {
                    throw new TvdbNotAvailableException("Couldn't connect to Thetvdb.com to retrieve " + _seriesId +
                                                        ", check your internet connection and the status of http://thetvdb.com");
                }
            }

            ZipInputStream zip = new ZipInputStream(new MemoryStream(data));

            ZipEntry entry         = zip.GetNextEntry();
            String   seriesString  = null;
            String   actorsString  = null;
            String   bannersString = null;

            while (entry != null)
            {
                Log.Debug("Extracting " + entry.Name);
                byte[] buffer = new byte[zip.Length];
                int    count  = zip.Read(buffer, 0, (int)zip.Length);
                if (entry.Name.Equals(_language.Abbriviation + ".xml"))
                {
                    seriesString = Encoding.UTF8.GetString(buffer);
                }
                else if (entry.Name.Equals("banners.xml"))
                {
                    bannersString = Encoding.UTF8.GetString(buffer);
                }
                else if (entry.Name.Equals("actors.xml"))
                {
                    actorsString = Encoding.UTF8.GetString(buffer);
                }
                entry = zip.GetNextEntry();
            }
            zip.Close();

            //extract all series the xml file contains
            List <TvdbSeries> seriesList = m_xmlHandler.ExtractSeries(seriesString);

            //if a request is made on a series id, one and only one result
            //should be returned, otherwise there obviously was an error
            if (seriesList != null && seriesList.Count == 1)
            {
                TvdbSeries series = seriesList[0];
                series.EpisodesLoaded = true;
                series.Episodes       = new List <TvdbEpisode>();
                //add episode info to series
                List <TvdbEpisode> epList = m_xmlHandler.ExtractEpisodes(seriesString);
                foreach (TvdbEpisode e in epList)
                {
                    Util.AddEpisodeToSeries(e, series);
                }

                //also load actors
                List <TvdbActor> actors = m_xmlHandler.ExtractActors(actorsString);
                if (actors != null)
                {
                    series.TvdbActorsLoaded = true;
                    series.TvdbActors       = actors;
                }

                //also load banner paths
                List <TvdbBanner> banners = m_xmlHandler.ExtractBanners(bannersString);
                if (banners != null)
                {
                    series.BannersLoaded = true;
                    series.Banners       = banners;
                }

                return(series);
            }
            else
            {
                Log.Warn("More than one series returned when trying to retrieve series " + _seriesId);
                return(null);
            }
        }
Beispiel #10
0
/// <summary>
        /// Download series from tvdb
/// </summary>
/// <param name="_seriesId">id of series</param>
/// <param name="_language">language of series</param>
/// <param name="_loadEpisodes">load episodes</param>
/// <param name="_loadActors">load actors</param>
/// <param name="_loadBanners">load banners</param>
/// <returns></returns>
        internal TvdbSeries DownloadSeries(int _seriesId, TvdbLanguage _language, bool _loadEpisodes, bool _loadActors, bool _loadBanners)
        {
            //download the xml data from this request
            String data;

            try
            {
                data = m_webClient.DownloadString(TvdbLinks.CreateSeriesLink(m_apiKey, _seriesId, _language, _loadEpisodes, false));
            }
            catch (WebException ex)
            {
                Log.Warn("Request not successfull", ex);
                if (ex.Message.Equals("The remote server returned an error: (404) Not Found."))
                {
                    throw new TvdbInvalidApiKeyException("Couldn't connect to Thetvdb.com to retrieve " + _seriesId +
                                                         ", it seems like you have an invalid api key (" + m_apiKey + ")");
                }
                else
                {
                    throw new TvdbNotAvailableException("Couldn't connect to Thetvdb.com to retrieve " + _seriesId +
                                                        ", check your internet connection and the status of http://thetvdb.com");
                }
            }
            //extract all series the xml file contains
            List <TvdbSeries> seriesList = m_xmlHandler.ExtractSeries(data);

            //if a request is made on a series id, one and only one result
            //should be returned, otherwise there obviously was an error
            if (seriesList != null && seriesList.Count == 1)
            {
                TvdbSeries series = seriesList[0];
                if (_loadEpisodes)
                {
                    //add episode info to series
                    List <TvdbEpisode> epList = m_xmlHandler.ExtractEpisodes(data);
                    foreach (TvdbEpisode e in epList)
                    {
                        Util.AddEpisodeToSeries(e, series);
                    }
                }

                //also load actors
                if (_loadActors)
                {
                    List <TvdbActor> list = DownloadActors(_seriesId);
                    if (list != null)
                    {
                        series.TvdbActors = list;
                    }
                }

                //also load banner paths
                if (_loadBanners)
                {
                    List <TvdbBanner> banners = DownloadBanners(_seriesId);
                    if (banners != null)
                    {
                        series.Banners = banners;
                    }
                }
                return(series);
            }
            else
            {
                Log.Warn("More than one series returned when trying to retrieve series " + _seriesId);
                return(null);
            }
        }
Beispiel #11
0
        /// <summary>
        /// Uptdate the info of the current series with the updated one
        /// </summary>
        /// <param name="_series"></param>
        public void UpdateSeriesInfo(TvdbSeries _series)
        {
            this.Actors = _series.Actors;
              this.AirsDayOfWeek = _series.AirsDayOfWeek;
              this.AirsTime = _series.AirsTime;
              this.BannerPath = _series.BannerPath;
              this.Banners = _series.Banners;
              this.ContentRating = _series.ContentRating;
              this.FanartPath = _series.FanartPath;
              this.FirstAired = _series.FirstAired;
              this.Genre = _series.Genre;
              this.Id = _series.Id;
              this.ImdbId = _series.ImdbId;
              this.Language = _series.Language;
              this.LastUpdated = _series.LastUpdated;
              this.Network = _series.Network;
              this.Overview = _series.Overview;
              this.Rating = _series.Rating;
              this.Runtime = _series.Runtime;
              this.SeriesName = _series.SeriesName;
              this.Status = _series.Status;
              this.TvDotComId = _series.TvDotComId;
              this.Zap2itId = _series.Zap2itId;

              if (_series.EpisodesLoaded)
              {//check if the old series has any images loaded already -> if yes, save them
            if (this.EpisodesLoaded)
            {
              foreach (TvdbEpisode oe in this.Episodes)
              {
            foreach (TvdbEpisode ne in _series.Episodes)
            {
              if (oe.SeasonNumber == ne.SeasonNumber &&
                  oe.EpisodeNumber == ne.EpisodeNumber)
              {
                if (oe.Banner != null && oe.Banner.IsLoaded)
                {
                  ne.Banner = oe.Banner;
                }
              }
            }
              }
            }

            this.Episodes = _series.Episodes;
              }

              if (_series.TvdbActorsLoaded)
              {//check if the old series has any images loaded already -> if yes, save them
            if (this.TvdbActorsLoaded)
            {
              foreach (TvdbActor oa in this.TvdbActors)
              {
            foreach (TvdbActor na in _series.TvdbActors)
            {
              if (oa.Id == na.Id)
              {
                if (oa.ActorImage != null && oa.ActorImage.IsLoaded)
                {
                  na.ActorImage = oa.ActorImage;
                }
              }
            }
              }
            }
            this.TvdbActors = _series.TvdbActors;
              }

              if (_series.BannersLoaded)
              {
            //check if the old series has any images loaded already -> if yes, save them
            if (this.BannersLoaded)
            {
              foreach (TvdbBanner ob in this.Banners)
              {
            foreach (TvdbBanner nb in _series.Banners)
            {
              if (ob.Id == nb.Id)
              {
                if (ob.Banner != null && ob.IsLoaded)
                {
                  nb.Banner = ob.Banner;
                }

                if (ob.GetType() == typeof(TvdbFanartBanner))
                {
                  TvdbFanartBanner newFaBanner = (TvdbFanartBanner)nb;
                  TvdbFanartBanner oldFaBanner = (TvdbFanartBanner)ob;

                  if (oldFaBanner.BannerThumb != null && oldFaBanner.IsThumbLoaded)
                  {
                    newFaBanner.BannerThumb = oldFaBanner.BannerThumb;
                  }

                  if (oldFaBanner.BannerThumb != null && oldFaBanner.IsVignetteLoaded)
                  {
                    newFaBanner.VignetteImage = oldFaBanner.VignetteImage;
                  }
                }
              }
            }
              }
            }
            this.Banners = _series.Banners;
              }
        }
 /// <summary>
 /// Saves the series to cache
 /// </summary>
 /// <param name="_series"></param>
 public void SaveToCache(TvdbSeries _series)
 {
     if (_series != null)
       {
     m_filestream = new FileStream(m_rootFolder + "\\series_" + _series.Id + ".ser", FileMode.Create);
     m_formatter.Serialize(m_filestream, _series);
     m_filestream.Close();
       }
 }
Beispiel #13
0
        /// <summary>
        /// Load the give series from cache
        /// </summary>
        /// <param name="_seriesId">Id of the series to load</param>
        /// <returns>Series that has been loaded</returns>
        public TvdbSeries LoadSeriesFromCache(int _seriesId)
        {
            String seriesRoot = m_rootFolder + "\\" + _seriesId;
              //todo: handle languages
              TvdbSeries series = new TvdbSeries();

              #region load series in all available languages
              String[] seriesLanguages = Directory.GetFiles(seriesRoot, "*.xml");
              TvdbLanguage defaultLanguage = null; ;

              foreach (String l in seriesLanguages)
              {
            if (!l.EndsWith("actors.xml") && !l.EndsWith("banners.xml"))
            {
              String content = File.ReadAllText(l);
              List<TvdbSeriesFields> seriesList = m_xmlReader.ExtractSeriesFields(content);
              if (seriesList != null && seriesList.Count == 1)
              {
            TvdbSeriesFields s = seriesList[0];
            if (l.EndsWith("all.xml")) defaultLanguage = s.Language;

            //Load episodes
            List<TvdbEpisode> epList = m_xmlReader.ExtractEpisodes(content);
            if (epList != null && epList.Count > 0)
            {
              s.EpisodesLoaded = true;
              s.Episodes = epList;
            }
            series.AddLanguage(s);
              }
            }
              }

              if (defaultLanguage != null)
              {//change language of the series to the default language
            series.SetLanguage(defaultLanguage);
              }
              else
              {//no series info could be loaded
            return null;
              }

              Regex rex = new Regex("S(\\d+)E(\\d+)");
              if (Directory.Exists(seriesRoot + "\\EpisodeImages"))
              {
            String[] episodeFiles = Directory.GetFiles(seriesRoot + "\\EpisodeImages", "*.jpg");
            foreach (String epImageFile in episodeFiles)
            {
              try
              {
            Match match = rex.Match(epImageFile);
            int season = Int32.Parse(match.Groups[1].Value);
            int episode = Int32.Parse(match.Groups[2].Value);
            foreach (TvdbEpisode e in series.Episodes)
            {
              if (e.SeasonNumber == season && e.EpisodeNumber == episode)
              {
                e.Banner.LoadBanner(Image.FromFile(epImageFile));
                break;
              }
            }
              }
              catch (Exception)
              {
            Log.Warn("Couldn't load episode image file " + epImageFile);
              }
            }
              }

              #endregion

              #region Banner loading
              String bannerFile = seriesRoot + "\\banners.xml";
              //load cached banners
              if (File.Exists(bannerFile))
              {//banners have been already loaded
            List<TvdbBanner> bannerList = m_xmlReader.ExtractBanners(File.ReadAllText(bannerFile));

            String[] banners = Directory.GetFiles(seriesRoot, "banner*.jpg");
            foreach (String b in banners)
            {
              try
              {
            int bannerId = Int32.Parse(b.Remove(b.IndexOf(".")).Remove(0, b.LastIndexOf("_") + 1));
            foreach (TvdbBanner banner in bannerList)
            {
              if (banner.Id == bannerId)
              {
                if (b.Contains("thumb") && banner.GetType() == typeof(TvdbFanartBanner))
                {
                  ((TvdbFanartBanner)banner).LoadThumb(Image.FromFile(b));
                }
                else if (b.Contains("vignette") && banner.GetType() == typeof(TvdbFanartBanner))
                {
                  ((TvdbFanartBanner)banner).LoadVignette(Image.FromFile(b));
                }
                else
                {
                  banner.LoadBanner(Image.FromFile(b));
                }
              }
            }

              }
              catch (Exception)
              {
            Log.Warn("Couldn't load image file " + b);
              }
            }
            series.Banners = bannerList;
              }
              #endregion

              #region actor loading
              //load actor info
              String actorFile = seriesRoot + "\\actors.xml";
              if (File.Exists(actorFile))
              {
            List<TvdbActor> actorList = m_xmlReader.ExtractActors(File.ReadAllText(actorFile));

            String[] banners = Directory.GetFiles(seriesRoot, "actor_*.jpg");
            foreach (String b in banners)
            {
              try
              {
            int actorId = Int32.Parse(b.Remove(b.IndexOf(".")).Remove(0, b.LastIndexOf("_") + 1));
            foreach (TvdbActor actor in actorList)
            {
              if (actor.Id == actorId)
              {
                actor.ActorImage.LoadBanner(Image.FromFile(b));
              }
            }

              }
              catch (Exception)
              {
            Log.Warn("Couldn't load image file " + b);
              }
            }
            series.TvdbActors = actorList;
              }
              #endregion

              return series;
        }
Beispiel #14
0
        private void UpdateSeries(TvdbSeries _series)
        {
            m_currentSeries = _series;
              FillSeriesDetails(_series);

              cmdForceUpdate.Enabled = true;
              if (_series.BannersLoaded)
              {
            cmdLoadBanners.Enabled = false;
            pnlFanartEnabled.Visible = false;

            if (_series.PosterBanners.Count > 0)
            {
              posterControlSeries.PosterImages = _series.PosterBanners;
            }
            else
            {
              posterControlSeries.ClearPoster();
            }
              }
              else
              {
            cmdLoadBanners.Enabled = true;
            pnlFanartEnabled.Visible = true;
              }

              if (_series.EpisodesLoaded)
              {
            cmdLoadFullSeriesInfo.Enabled = false;
            pnlEpisodeEnabled.Visible = false;
            FillFullSeriesDetails(_series);
              }
              else
              {
            cmdLoadFullSeriesInfo.Enabled = true;
            pnlEpisodeEnabled.Visible = true;
              }

              if (_series.TvdbActorsLoaded && _series.Actors.Count > 0)
              {
            cmdLoadActorInfo.Enabled = false;
            pnlActorsEnabled.Visible = false;
            lbAllActors.Items.Clear();
            bcActors.ClearControl();
            if (_series.TvdbActors.Count > 0)
            {
              List<TvdbBanner> bannerList = new List<TvdbBanner>();
              foreach (TvdbActor a in _series.TvdbActors)
              {
            lbAllActors.Items.Add(a.Name);
            bannerList.Add(a.ActorImage);
              }

              bcActors.BannerImages = bannerList;
              SetActorInfo(_series.TvdbActors[0]);
            }
              }
              else
              {
            bcActors.ClearControl();

            cmdLoadActorInfo.Enabled = true;
            pnlActorsEnabled.Visible = true;
              }
        }
Beispiel #15
0
        private void FillSeriesDetails(TvdbSeries series)
        {
            if (m_tvdbHandler.UserInfo != null)
              {
            cmdAddRemoveFavorites.Enabled = true;
            cmdAddRemoveFavorites.Text = series.IsFavorite ? "Remove from favorites" : "Add to favorites";
            cmdSendSeriesRating.Enabled = true;
            raterSeriesYourRating.Enabled = true;
              }
              else
              {
            cmdAddRemoveFavorites.Enabled = false;
            cmdSendSeriesRating.Enabled = false;
            raterSeriesYourRating.Enabled = false;
              }

              List<TvdbBanner> bannerlist = new List<TvdbBanner>();
              foreach (TvdbBanner b in series.Banners)
              {
            if (b.GetType() == typeof(TvdbSeriesBanner))
            {
              //if (b.Language.Id == m_defaultLang.Id)
              {
            bannerlist.Add(b);
              }
            }
              }

              if (bannerlist.Count > 0)
              {
            bcSeriesBanner.BannerImages = bannerlist;
              }
              else
              {
            bcSeriesBanner.ClearControl();
              }

              txtSeriesId.Text = series.Id.ToString();
              txtSeriesName.Text = series.SeriesName;
              txtStatus.Text = series.Status;
              txtGenre.Text = series.GenreString;
              txtFirstAired.Text = series.FirstAired != null ? series.FirstAired.ToShortDateString() : "";
              txtAirsWeekday.Text = series.AirsDayOfWeek != null ? series.AirsDayOfWeek.ToString() : "";
              txtAirstime.Text = series.AirsTime.ToShortTimeString();
              txtNetwork.Text = series.Network;
              txtRuntime.Text = series.Runtime != -99 ? series.Runtime.ToString() : "";
              txtRating.Text = series.Rating != -99 ? series.Rating.ToString() : "";
              txtActors.Text = series.ActorsString;
              txtOverview.Text = series.Overview;
              txtTvComId.Text = series.TvDotComId != -99 ? series.TvDotComId.ToString() : ""; //series.
              txtImdbId.Text = series.ImdbId;
              txtZap2itId.Text = series.Zap2itId;
              raterSeriesSiteRating.CurrentRating = series.Rating != -99 ? (int)(series.Rating / 10) : 0;
        }
        /// <summary>
        /// Saves the series to cache
        /// </summary>
        /// <param name="_series"></param>
        public void SaveToCache(TvdbSeries _series)
        {
            if (_series != null)
              {
            if (!Directory.Exists(m_rootFolder)) Directory.CreateDirectory(m_rootFolder);
            m_filestream = new FileStream(m_rootFolder + "\\series_" + _series.Id + ".ser", FileMode.Create);
            m_formatter.Serialize(m_filestream, _series);
            m_filestream.Close();

            SeriesConfiguration cfg = new SeriesConfiguration(_series.Id, _series.EpisodesLoaded,
                                                  _series.BannersLoaded, _series.TvdbActorsLoaded);
            m_filestream = new FileStream(m_rootFolder + "\\series_" + _series.Id + ".cfg", FileMode.Create);
            m_formatter.Serialize(m_filestream, cfg);
            m_filestream.Close();
              }
        }
Beispiel #17
0
        /// <summary>
        /// Create the series content
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        internal String CreateSeriesContent(TvdbSeries m)
        {
            XElement xml = new XElement("Data");

              xml.Add(new XElement("Series",
                  new XElement("id", m.Id),
                  new XElement("Actors", m.ActorsString),
                  new XElement("Airs_DayOfWeek", m.AirsDayOfWeek),
                  new XElement("Airs_Time", m.AirsTime),
                  new XElement("ContentRating", m.ContentRating),
                  new XElement("FirstAired", m.FirstAired),
                  new XElement("Genre", m.GenreString),
                  new XElement("IMDB_ID", m.ImdbId),
                  new XElement("Language", m.Language),
                  new XElement("Network", m.Network),
                  new XElement("Overview", m.Overview),
                  new XElement("Rating", m.Rating),
                  new XElement("Runtime", m.Runtime),
                  new XElement("SeriesID", m.TvDotComId),
                  new XElement("SeriesName", m.SeriesName),
                  new XElement("Status", m.Status),
                  new XElement("banner", m.BannerPath != null ? m.BannerPath : ""),
                  new XElement("fanart", m.FanartPath != null ? m.FanartPath : ""),
                  new XElement("lastupdated", Util.DotNetToUnix(m.LastUpdated)),
                  new XElement("zap2it_id", m.Zap2itId))
             );

              if (m.Episodes != null && m.EpisodesLoaded)
              {
            foreach (TvdbEpisode e in m.Episodes)
            {
              xml.Add(new XElement("Episode",
                  new XElement("id", e.Id),
                  new XElement("Combined_episodenumber", e.CombinedEpisodeNumber),
                  new XElement("Combined_season", e.CombinedSeason),
                  new XElement("DVD_chapter", e.DvdChapter != -99 ? e.DvdChapter.ToString() : ""),
                  new XElement("DVD_discid", e.DvdDiscId != -99 ? e.DvdDiscId.ToString() : ""),
                  new XElement("DVD_episodenumber", e.DvdEpisodeNumber != -99 ? e.DvdEpisodeNumber.ToString() : ""),
                  new XElement("DVD_season", e.DvdSeason != -99 ? e.DvdSeason.ToString() : ""),
                  new XElement("Director", e.DirectorsString),
                  new XElement("EpisodeName", e.EpisodeName),
                  new XElement("EpisodeNumber", e.EpisodeNumber),
                  new XElement("FirstAired", e.FirstAired),
                  new XElement("GuestStars", e.GuestStarsString),
                  new XElement("IMDB_ID", e.ImdbId),
                  new XElement("Language", e.Language.Name),
                  new XElement("Overview", e.Overview),
                  new XElement("ProductionCode", e.ProductionCode),
                  new XElement("Rating", e.Rating.ToString()),
                  new XElement("SeasonNumber", e.SeasonNumber),
                  new XElement("Writer", e.WriterString),
                  new XElement("absolute_number", e.AbsoluteNumber),
                  new XElement("airsafter_season", e.AirsAfterSeason != -99 ? e.AirsAfterSeason.ToString() : ""),
                  new XElement("airsbefore_episode", e.AirsBeforeEpisode != -99 ? e.AirsBeforeEpisode.ToString() : ""),
                  new XElement("airsbefore_season", e.AirsBeforeSeason != -99 ? e.AirsBeforeSeason.ToString() : ""),
                  new XElement("filename", e.Banner.BannerPath),
                  new XElement("lastupdated", Util.DotNetToUnix(e.LastUpdated)),
                  new XElement("seasonid", e.SeasonId),
                  new XElement("seriesid", e.SeriesId))
                 );

            }
              }
              return xml.ToString();
        }
Beispiel #18
0
        /// <summary>
        /// Uptdate the info of the current series with the updated one
        /// </summary>
        /// <param name="_series"></param>
        public void UpdateSeriesInfo(TvdbSeries _series)
        {
            this.Actors        = _series.Actors;
            this.AirsDayOfWeek = _series.AirsDayOfWeek;
            this.AirsTime      = _series.AirsTime;
            this.BannerPath    = _series.BannerPath;
            this.Banners       = _series.Banners;
            this.ContentRating = _series.ContentRating;
            this.FanartPath    = _series.FanartPath;
            this.FirstAired    = _series.FirstAired;
            this.Genre         = _series.Genre;
            this.Id            = _series.Id;
            this.ImdbId        = _series.ImdbId;
            this.Language      = _series.Language;
            this.LastUpdated   = _series.LastUpdated;
            this.Network       = _series.Network;
            this.Overview      = _series.Overview;
            this.Rating        = _series.Rating;
            this.Runtime       = _series.Runtime;
            this.SeriesName    = _series.SeriesName;
            this.Status        = _series.Status;
            this.TvDotComId    = _series.TvDotComId;
            this.Zap2itId      = _series.Zap2itId;

            if (_series.EpisodesLoaded)
            {//check if the old series has any images loaded already -> if yes, save them
                if (this.EpisodesLoaded)
                {
                    foreach (TvdbEpisode oe in this.Episodes)
                    {
                        foreach (TvdbEpisode ne in _series.Episodes)
                        {
                            if (oe.SeasonNumber == ne.SeasonNumber &&
                                oe.EpisodeNumber == ne.EpisodeNumber)
                            {
                                if (oe.Banner != null && oe.Banner.IsLoaded)
                                {
                                    ne.Banner = oe.Banner;
                                }
                            }
                        }
                    }
                }

                this.Episodes = _series.Episodes;
            }

            if (_series.TvdbActorsLoaded)
            {//check if the old series has any images loaded already -> if yes, save them
                if (this.TvdbActorsLoaded)
                {
                    foreach (TvdbActor oa in this.TvdbActors)
                    {
                        foreach (TvdbActor na in _series.TvdbActors)
                        {
                            if (oa.Id == na.Id)
                            {
                                if (oa.ActorImage != null && oa.ActorImage.IsLoaded)
                                {
                                    na.ActorImage = oa.ActorImage;
                                }
                            }
                        }
                    }
                }
                this.TvdbActors = _series.TvdbActors;
            }

            if (_series.BannersLoaded)
            {
                //check if the old series has any images loaded already -> if yes, save them
                if (this.BannersLoaded)
                {
                    foreach (TvdbBanner ob in this.Banners)
                    {
                        foreach (TvdbBanner nb in _series.Banners)
                        {
                            if (ob.Id == nb.Id)
                            {
                                if (ob.Banner != null && ob.IsLoaded)
                                {
                                    nb.Banner = ob.Banner;
                                }

                                if (ob.GetType() == typeof(TvdbFanartBanner))
                                {
                                    TvdbFanartBanner newFaBanner = (TvdbFanartBanner)nb;
                                    TvdbFanartBanner oldFaBanner = (TvdbFanartBanner)ob;

                                    if (oldFaBanner.BannerThumb != null && oldFaBanner.IsThumbLoaded)
                                    {
                                        newFaBanner.BannerThumb = oldFaBanner.BannerThumb;
                                    }

                                    if (oldFaBanner.BannerThumb != null && oldFaBanner.IsVignetteLoaded)
                                    {
                                        newFaBanner.VignetteImage = oldFaBanner.VignetteImage;
                                    }
                                }
                            }
                        }
                    }
                }
                this.Banners = _series.Banners;
            }
        }
Beispiel #19
0
        /// <summary>
        /// Update the series with the banner
        /// </summary>
        /// <param name="_series"></param>
        /// <param name="_banner"></param>
        private void UpdateBanner(TvdbSeries _series, TvdbBanner _banner)
        {
            if (!_series.BannersLoaded)
              {//banners for this series havn't been loaded -> don't update banners
            return;
              }
              bool found = false;
              foreach (TvdbBanner b in _series.Banners)
              {
            if (_banner.GetType() == b.GetType() && _banner.BannerPath.Equals(b.BannerPath))
            {
              if (b.LastUpdated < _banner.LastUpdated)
              {
            b.LastUpdated = _banner.LastUpdated;
            if (_banner.GetType() == typeof(TvdbFanartBanner))
            {
              TvdbFanartBanner fanart = (TvdbFanartBanner)b;

              fanart.Resolution = ((TvdbFanartBanner)_banner).Resolution;
              if (fanart.IsThumbLoaded)
              {
                fanart.LoadThumb(null);
              }

              if (fanart.IsVignetteLoaded)
              {
                fanart.LoadVignette(null);
              }
            }
            if (b.IsLoaded)
            {
              b.LoadBanner(null);
            }

            Log.Info("Replacing banner " + _banner.Id);
              }
              else
              {
            Log.Debug("Not replacing banner " + _banner.Id + " because it's not newer than current image");
              }
              found = true;
            }
              }
              if (!found)
              {//banner not found -> add it to bannerlist
            Log.Info("Adding banner " + _banner.Id);
            _series.Banners.Add(_banner);
              }
        }
Beispiel #20
0
        /// <summary>
        /// Uptdate the info of the current series with the updated one
        /// </summary>
        /// <param name="_series"></param>
        public void UpdateSeriesInfo(TvdbSeries _series)
        {
            this.Actors = _series.Actors;
              this.AirsDayOfWeek = _series.AirsDayOfWeek;
              this.AirsTime = _series.AirsTime;
              this.BannerPath = _series.BannerPath;
              this.Banners = _series.Banners;
              this.ContentRating = _series.ContentRating;
              this.FanartPath = _series.FanartPath;
              this.FirstAired = _series.FirstAired;
              this.Genre = _series.Genre;
              this.Id = _series.Id;
              this.ImdbId = _series.ImdbId;
              this.Language = _series.Language;
              this.LastUpdated = _series.LastUpdated;
              this.Network = _series.Network;
              this.Overview = _series.Overview;
              this.Rating = _series.Rating;
              this.Runtime = _series.Runtime;
              this.SeriesName = _series.SeriesName;
              this.Status = _series.Status;
              this.TvDotComId = _series.TvDotComId;
              this.Zap2itId = _series.Zap2itId;

              if (_series.EpisodesLoaded)
              {
            this.Episodes = _series.Episodes;
              }
        }
Beispiel #21
0
 /// <summary>
 /// Download the new series and update the information
 /// </summary>
 /// <param name="_series">Series to update</param>
 /// <param name="_lastUpdated">When was the last update made</param>
 private void UpdateSeries(TvdbSeries _series, DateTime _lastUpdated)
 {
     //get series info
       TvdbSeries newSeries = GetSeries(_series.Id, _series.Language, false, false, false);
       newSeries.LastUpdated = _lastUpdated;
       if (newSeries != null)
       {
     _series.UpdateSeriesInfo(newSeries);
     Log.Info("Updated Series " + _series.Id);
       }
 }
Beispiel #22
0
        /// <summary>
        /// Saves the series to cache
        /// </summary>
        /// <param name="_series"></param>
        public void SaveToCache(TvdbSeries _series)
        {
            String root = m_rootFolder + "\\" + _series.Id;
              m_xmlWriter.WriteSeriesContent(_series, root + "\\all.xml");
              if (_series.BannersLoaded)
              {
            m_xmlWriter.WriteSeriesBannerContent(_series.Banners, root + "\\banners.xml");
              }

              if (_series.TvdbActorsLoaded)
              {
            m_xmlWriter.WriteActorFile(_series.TvdbActors, root + "\\actors.xml");
              }

              //Save all loaded banners to file
              foreach (TvdbBanner b in _series.Banners)
              {
            FileInfo file = new FileInfo(root + "\\banner_" + b.Id + ".jpg");
            if (b.IsLoaded && !file.Exists)
            {//banner is cached
              if (!file.Directory.Exists) file.Directory.Create();
              b.Banner.Save(file.FullName);
            }
            if (b.GetType() == typeof(TvdbFanartBanner))
            {//banner is fanart -> has vignette and thumb
              file = new FileInfo(root + "\\bannerthumb_" + b.Id + ".jpg");
              if (((TvdbFanartBanner)b).IsThumbLoaded && !file.Exists)
              {
            if (!file.Directory.Exists) file.Directory.Create();
            ((TvdbFanartBanner)b).BannerThumb.Save(file.FullName);
              }

              file = new FileInfo(root + "\\bannervignette_" + b.Id + ".jpg");
              if (((TvdbFanartBanner)b).IsVignetteLoaded && !file.Exists)
              {
            if (!file.Directory.Exists) file.Directory.Create();
            ((TvdbFanartBanner)b).VignetteImage.Save(file.FullName);
              }

            }
              }

              if (_series.EpisodesLoaded)
              {
            foreach (TvdbEpisode e in _series.Episodes)
            {
              FileInfo file = new FileInfo(root + "\\EpisodeImages\\S" + e.SeasonNumber + "E" + e.EpisodeNumber + ".jpg");
              if (e.Banner.IsLoaded && !file.Exists)
              {
            if (!file.Directory.Exists) file.Directory.Create();
            e.Banner.Banner.Save(file.FullName);
              }
            }
              }

              if (_series.TvdbActorsLoaded)
              {
            foreach (TvdbActor a in _series.TvdbActors)
            {
              FileInfo file = new FileInfo(root + "\\actor_" + a.ActorImage.Id + ".jpg");
              if (a.ActorImage.IsLoaded && !file.Exists)
              {
            if (!file.Directory.Exists) file.Directory.Create();
            a.ActorImage.Banner.Save(file.FullName);
              }
            }
              }
        }
Beispiel #23
0
 /// <summary>
 /// Forces a complete update of the series. All information that has already been loaded (including loaded images!) will be deleted and reloaded from tvdb -> if you only want to update the series, use the "MakeUpdate" method
 /// </summary>
 /// <param name="_series">Series to reload</param>
 public TvdbSeries ForceUpdate(TvdbSeries _series)
 {
     return ForceUpdate(_series, _series.EpisodesLoaded, _series.TvdbActorsLoaded, _series.BannersLoaded);
 }
Beispiel #24
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="_epList"></param>
        private void AddEpisodeToCache(TvdbEpisode e)
        {
            bool seriesFound = false;
              foreach (TvdbSeries s in m_loadedData.SeriesList)
              {
            if (s.Id == e.SeriesId)
            {//series for ep found
              seriesFound = true;
              Util.AddEpisodeToSeries(e, s);
              break;
            }

              }
              if (!seriesFound)
              {//the series doesn't exist yet -> add episode to dummy series
            TvdbSeries newSeries = new TvdbSeries();
            newSeries.LastUpdated = new DateTime(1, 1, 1);
            newSeries.Episodes.Add(e);
            m_loadedData.SeriesList.Add(newSeries);
              }
        }
Beispiel #25
0
 /// <summary>
 /// Removes the series from the users list of favorites and returns the new list of
 /// favorites
 /// </summary>
 /// <param name="_series">series to remove from the favorites</param>
 /// <returns>new list with all favorites</returns>
 public List<int> RemoveSeriesFromFavorites(TvdbSeries _series)
 {
     return RemoveSeriesFromFavorites(_series.Id);
 }
Beispiel #26
0
        /// <summary>
        /// Extract a list of series in the format:
        /// <![CDATA[
        /// <?xml version="1.0" encoding="UTF-8" ?>
        /// <Data>
        ///    <Series>
        ///       <id>73739</id>
        ///       <Actors>|Malcolm David Kelley|Jorge Garcia|Maggie Grace|...|</Actors>
        ///       <Airs_DayOfWeek>Thursday</Airs_DayOfWeek>
        ///       <Airs_Time>9:00 PM</Airs_Time>
        ///       <ContentRating>TV-14</ContentRating>
        ///       <FirstAired>2004-09-22</FirstAired>
        ///       <Genre>|Action and Adventure|Drama|Science-Fiction|</Genre>
        ///       <IMDB_ID>tt0411008</IMDB_ID>
        ///       <Language>en</Language>
        ///       <Network>ABC</Network>
        ///       <Overview>After Oceanic Air flight 815...</Overview>
        ///       <Rating>8.9</Rating>
        ///       <Runtime>60</Runtime>
        ///       <SeriesID>24313</SeriesID>
        ///       <SeriesName>Lost</SeriesName>
        ///       <Status>Continuing</Status>
        ///       <banner>graphical/24313-g2.jpg</banner>
        ///       <fanart>fanart/original/73739-1.jpg</fanart>
        ///       <lastupdated>1205694666</lastupdated>
        ///       <zap2it_id>SH672362</zap2it_id>
        ///    </Series>
        /// </Data>
        /// ]]>
        /// </summary>
        /// <param name="_data"></param>
        /// <returns></returns>
        internal List<TvdbSeries> ExtractSeries(String _data)
        {
            List<TvdbSeriesFields> tvdbInfo = ExtractSeriesFields(_data);
              List<TvdbSeries> retList = new List<TvdbSeries>();
              foreach (TvdbSeriesFields s in tvdbInfo)
              {
            TvdbSeries series = new TvdbSeries(s);

            if (!series.BannerPath.Equals(""))
            {
              series.Banners.Add(new TvdbSeriesBanner(series.Id, series.BannerPath, series.Language, TvdbSeriesBanner.Type.graphical));
            }

            if (!series.FanartPath.Equals(""))
            {
              series.Banners.Add(new TvdbFanartBanner(series.Id, series.FanartPath, series.Language));
            }
            retList.Add(series);
              }
              return retList;
        }
Beispiel #27
0
 private void AddSeriesToCache(TvdbSeries _series)
 {
     bool found = false;
       for (int i = 0; i < m_loadedData.SeriesList.Count; i++)
       {
     if (((TvdbSeries)m_loadedData.SeriesList[i]).Id == _series.Id)
     {
       found = true;
       m_loadedData.SeriesList[i].UpdateSeriesInfo(_series);//so we're not losing banners, etc.
       //_series.UpdateSeriesInfo(m_loadedData.SeriesList[i]); //so we're not losing banners, etc.
       //m_loadedData.SeriesList[i] = _series;
     }
       }
       if (!found)
       {
     m_loadedData.SeriesList.Add(_series);
       }
 }
Beispiel #28
0
 private void cmdForceUpdate_Click(object sender, EventArgs e)
 {
     TvdbSeries series = null;
       try
       {
     series = m_tvdbHandler.ForceUpdate(m_currentSeries, cbLoadFull.Checked,
                                             cbLoadActors.Checked, cbLoadBanner.Checked);
       }
       catch (TvdbInvalidApiKeyException ex)
       {
     MessageBox.Show(ex.Message);
       }
       catch (TvdbNotAvailableException ex)
       {
     MessageBox.Show(ex.Message);
       }
       if (series != null)
       {
     m_currentSeries = series;
     UpdateSeries(m_currentSeries);
       }
 }