Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Saves the series to cache
        /// </summary>
        /// <param name="_series">The series to save</param>
        public void SaveToCache(TvdbSeries _series)
        {
            String root = m_rootFolder + Path.DirectorySeparatorChar + _series.Id;

            if (!Directory.Exists(root))
            {
                Directory.CreateDirectory(root);
            }
            try
            {//delete old cached content
                String[] files = Directory.GetFiles(root, "*.xml");
                foreach (String f in files)
                {
                    File.Delete(f);
                }
            }
            catch (Exception ex)
            {
                Log.Warn("Couldn't delete old cache files", ex);
            }

            foreach (TvdbLanguage l in _series.GetAvailableLanguages())
            {//write all languages to file
                String fName = root + Path.DirectorySeparatorChar + l.Abbriviation +
                               (_series.EpisodesLoaded ? "_full" : "") + ".xml";
                _series.SetLanguage(l);
                m_xmlWriter.WriteSeriesContent(_series, fName);
            }

            if (_series.BannersLoaded)
            {//write the banners file
                m_xmlWriter.WriteSeriesBannerContent(_series.Banners, root + Path.DirectorySeparatorChar + "banners.xml");
            }

            if (_series.TvdbActorsLoaded)
            {//write the actors file
                m_xmlWriter.WriteActorFile(_series.TvdbActors, root + Path.DirectorySeparatorChar + "actors.xml");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the series with the given id either from cache (if it has already been loaded) or from
        /// the selected tvdb mirror.
        ///
        /// To check if this series has already been cached, use the Method IsCached(TvdbSeries _series)
        /// </summary>
        /// <param name="_seriesId">id of series</param>
        /// <param name="_language">language that should be retrieved</param>
        /// <param name="_full">if true, the full series record will be loaded (series + all episodes), otherwise only the base record will be loaded which contains only series information</param>
        /// <param name="_loadBanners">if true also loads the paths to the banners</param>
        /// <returns>Instance of TvdbSeries containing all gained information</returns>
        public TvdbSeries GetSeries(int _seriesId, TvdbLanguage _language, bool _loadEpisodes,
                                    bool _loadActors, bool _loadBanners)
        {
            Stopwatch watch = new Stopwatch();

            watch.Start();

            TvdbSeries series = GetSeriesFromCache(_seriesId);

            if (series == null)
            {//load complete series from tvdb
                series = m_downloader.DownloadSeries(_seriesId, _language, _loadEpisodes, _loadActors, _loadBanners);
                if (series == null)
                {
                    return(null);
                }
                watch.Stop();
                Log.Debug("Loaded series in " + watch.ElapsedMilliseconds + " milliseconds");
                series.IsFavorite = m_userInfo == null ? false : CheckIfSeriesFavorite(_seriesId, m_userInfo.UserFavorites);
                AddSeriesToCache(series);
                return(series);
            }
            else
            {     //some (if not all) information has already been loaded from tvdb at some point -> fill the missing details and return the series
                if (!_language.Abbriviation.Equals(series.Language.Abbriviation))
                { //user wants a different language than the one that has been loaded
                    if (series.GetAvailableLanguages().Contains(_language))
                    {
                        series.SetLanguage(_language);
                    }
                    else
                    {
                        TvdbSeriesFields newFields = m_downloader.DownloadSeriesFields(_seriesId, _language);
                        if (_loadEpisodes)
                        {
                            List <TvdbEpisode> epList = m_downloader.DownloadEpisodes(_seriesId, _language);
                            if (epList != null)
                            {
                                newFields.Episodes = epList;
                            }
                        }
                        if (newFields != null)
                        {
                            series.AddLanguage(newFields);
                            series.SetLanguage(_language);
                        }
                        else
                        {
                            Log.Warn("Couldn't load new language " + _language.Abbriviation + " for series " + _seriesId);
                            return(null);
                        }
                    }
                }

                if (_loadActors && !series.TvdbActorsLoaded)
                {//user wants actors loaded
                    series.TvdbActors = m_downloader.DownloadActors(_seriesId);
                }

                if (_loadEpisodes && !series.EpisodesLoaded)
                {//user wants the full version but only the basic has been loaded (without episodes
                    series.Episodes = m_downloader.DownloadEpisodes(_seriesId, _language);
                }

                if (_loadBanners && !series.BannersLoaded)
                {//user wants banners loaded but current series hasn't -> Do it baby
                    series.Banners = m_downloader.DownloadBanners(_seriesId);
                }

                watch.Stop();
                Log.Debug("Loaded series in " + watch.ElapsedMilliseconds + " milliseconds");

                return(series);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Saves the series to cache
        /// </summary>
        /// <param name="_series">The series to save</param>
        public void SaveToCache(TvdbSeries _series)
        {
            if (!Directory.Exists(m_rootFolder))
            {
                Directory.CreateDirectory(m_rootFolder);
            }
            String root = m_rootFolder + "\\" + _series.Id;

            m_xmlWriter.WriteSeriesContent(_series, root + "\\all.xml");
            TvdbLanguage defaultLang = _series.Language;

            foreach (TvdbLanguage l in _series.GetAvailableLanguages())
            {
                if (l != defaultLang)
                {
                    _series.SetLanguage(l);
                    m_xmlWriter.WriteSeriesContent(_series, root + "\\" + l.Abbriviation + ".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 != null && 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);
                    }
                }
            }
        }