Example #1
0
		/// <summary>
		/// Updates the followung
		/// 1. Series Info
		/// 2. Episode Info
		/// 3. Episode Images
		/// 4. Fanart, Poster and Wide Banner Images
		/// </summary>
		/// <param name="seriesID"></param>
		/// <param name="forceRefresh"></param>
		public void UpdateAllInfoAndImages(int seriesID, bool forceRefresh, bool downloadImages)
		{
			TvDB_EpisodeRepository repEpisodes = new TvDB_EpisodeRepository();
			TvDB_SeriesRepository repSeries = new TvDB_SeriesRepository();

			string fileName = string.Format("{0}.xml", ServerSettings.TvDB_Language);

			Dictionary<string, XmlDocument> docSeries = GetFullSeriesInfo(seriesID);
			if (docSeries.ContainsKey(fileName))
			{
				try
				{
					// update the series info
					XmlDocument xmlDoc = docSeries[fileName];
					if (xmlDoc != null)
					{
						TvDB_Series tvSeries = repSeries.GetByTvDBID(seriesID);
						if (tvSeries == null)
							tvSeries = new TvDB_Series();

						tvSeries.PopulateFromSeriesInfo(xmlDoc);
						repSeries.Save(tvSeries);
					}

					if (downloadImages)
					{
						// get all fanart, posters and wide banners
						if (docSeries.ContainsKey("banners.xml"))
						{
							XmlDocument xmlDocBanners = docSeries["banners.xml"];
							if (xmlDocBanners != null)
								DownloadAutomaticImages(xmlDocBanners, seriesID, forceRefresh);
						}
					}

					// update all the episodes and download episode images
					XmlNodeList episodeItems = xmlDoc["Data"].GetElementsByTagName("Episode");
					logger.Trace("Found {0} Episode nodes", episodeItems.Count.ToString());

					List<int> existingEpIds = new List<int>();
					foreach (XmlNode node in episodeItems)
					{
						try
						{
							

							// the episode id
							int id = int.Parse(node["id"].InnerText.Trim());
							existingEpIds.Add(id);

							TvDB_Episode ep = repEpisodes.GetByTvDBID(id);
							if (ep == null)
								ep = new TvDB_Episode();
							ep.Populate(node);
							repEpisodes.Save(ep);

							//BaseConfig.MyAnimeLog.Write("Refreshing episode info for: {0}", ep.ToString());

							if (downloadImages)
							{
								// download the image for this episode
								if (!string.IsNullOrEmpty(ep.Filename))
								{
									bool fileExists = File.Exists(ep.FullImagePath);
									if (!fileExists || (fileExists && forceRefresh))
									{
										CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(ep.TvDB_EpisodeID, JMMImageType.TvDB_Episode, forceRefresh);
										cmd.Save();
									}
								}
							}
						}
						catch (Exception ex)
						{
							logger.ErrorException("Error in TVDBHelper.GetEpisodes: " + ex.ToString(), ex);
						}
					}

					// get all the existing tvdb episodes, to see if any have been deleted
					List<TvDB_Episode> allEps = repEpisodes.GetBySeriesID(seriesID);
					foreach (TvDB_Episode oldEp in allEps)
					{
						if (!existingEpIds.Contains(oldEp.Id))
							repEpisodes.Delete(oldEp.TvDB_EpisodeID);
					}


				}
				catch (Exception ex)
				{
					logger.ErrorException("Error in TVDBHelper.GetEpisodes: " + ex.ToString(), ex);
				}
			}
		}
Example #2
0
        private void PopulateTvDBEpisodes()
        {
            try
            {
                TvDB_EpisodeRepository repTvEps = new TvDB_EpisodeRepository();
                tvDBEpisodes = repTvEps.GetBySeriesID(TvDBID);

                if (tvDBEpisodes.Count > 0)
                {
                    List<SortPropOrFieldAndDirection> sortCriteria = new List<SortPropOrFieldAndDirection>();
                    sortCriteria.Add(new SortPropOrFieldAndDirection("SeasonNumber", false, SortType.eInteger));
                    sortCriteria.Add(new SortPropOrFieldAndDirection("EpisodeNumber", false, SortType.eInteger));
                    tvDBEpisodes = Sorting.MultiSort<TvDB_Episode>(tvDBEpisodes, sortCriteria);
                }
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
        }
Example #3
0
        public List<Contract_TvDB_Episode> GetAllTvDBEpisodes(int? tvDBID)
        {
            List<Contract_TvDB_Episode> allImages = new List<Contract_TvDB_Episode>();
            try
            {
                TvDB_EpisodeRepository repImages = new TvDB_EpisodeRepository();
                List<TvDB_Episode> allEpisodes = null;
                if (tvDBID.HasValue)
                    allEpisodes = repImages.GetBySeriesID(tvDBID.Value);
                else
                    allEpisodes = repImages.GetAll();

                foreach (TvDB_Episode img in allEpisodes)
                    allImages.Add(img.ToContract());

                return allImages;

            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return allImages;
            }
        }
Example #4
0
        public List<TvDB_Episode> GetTvDBEpisodes(ISession session)
        {
            List<TvDB_Episode> tvDBEpisodes = new List<TvDB_Episode>();

            List<CrossRef_AniDB_TvDBV2> xrefs = GetCrossRefTvDBV2(session);
            if (xrefs.Count == 0) return tvDBEpisodes;

            TvDB_EpisodeRepository repEps = new TvDB_EpisodeRepository();
            foreach (CrossRef_AniDB_TvDBV2 xref in xrefs)
            {
                tvDBEpisodes.AddRange(repEps.GetBySeriesID(session, xref.TvDBID));
            }

            List<SortPropOrFieldAndDirection> sortCriteria = new List<SortPropOrFieldAndDirection>();
            sortCriteria.Add(new SortPropOrFieldAndDirection("SeasonNumber", false, SortType.eInteger));
            sortCriteria.Add(new SortPropOrFieldAndDirection("EpisodeNumber", false, SortType.eInteger));
            tvDBEpisodes = Sorting.MultiSort<TvDB_Episode>(tvDBEpisodes, sortCriteria);

            return tvDBEpisodes;
        }