/* * public static bool ConfirmTvDBOnline() * { * TvDB_Series tvser = GetSeriesInfoOnline(73255); * if (tvser == null) * return false; * else * return true; * } */ public static TvDB_Series GetSeriesInfoOnline(int seriesID) { try { //Init(); string url = string.Format(Constants.TvDBURLs.urlSeriesBaseXML, URLMirror, Constants.TvDBURLs.apiKey, seriesID, ServerSettings.TvDB_Language); logger.Trace("GetSeriesInfo: {0}", url); // Search for a series string xmlSeries = Utils.DownloadWebPage(url); logger.Trace("GetSeriesInfo RESULT: {0}", xmlSeries); if (xmlSeries.Trim().Length == 0) { return(null); } XmlDocument docSeries = new XmlDocument(); docSeries.LoadXml(xmlSeries); TvDB_Series tvSeries = null; if (docSeries != null) { TvDB_SeriesRepository repSeries = new TvDB_SeriesRepository(); tvSeries = repSeries.GetByTvDBID(seriesID); if (tvSeries == null) { tvSeries = new TvDB_Series(); } tvSeries.PopulateFromSeriesInfo(docSeries); repSeries.Save(tvSeries); } return(tvSeries); } catch (Exception ex) { logger.ErrorException("Error in TVDBHelper.GetSeriesInfoOnline: " + ex.ToString(), ex); } return(null); }
public TvDB_Series GetTvDBSeries(ISession session) { TvDB_SeriesRepository repTvSeries = new TvDB_SeriesRepository(); return(repTvSeries.GetByTvDBID(session, TvDBID)); }
public static string LinkAniDBTvDB(int animeID, enEpisodeType aniEpType, int aniEpNumber, int tvDBID, int tvSeasonNumber, int tvEpNumber, bool excludeFromWebCache) { using (var session = JMMService.SessionFactory.OpenSession()) { CrossRef_AniDB_TvDBV2Repository repCrossRef = new CrossRef_AniDB_TvDBV2Repository(); List <CrossRef_AniDB_TvDBV2> xrefTemps = repCrossRef.GetByAnimeIDEpTypeEpNumber(session, animeID, (int)aniEpType, aniEpNumber); if (xrefTemps != null && xrefTemps.Count > 0) { foreach (CrossRef_AniDB_TvDBV2 xrefTemp in xrefTemps) { // delete the existing one if we are updating TvDBHelper.RemoveLinkAniDBTvDB(xrefTemp.AnimeID, (enEpisodeType)xrefTemp.AniDBStartEpisodeType, xrefTemp.AniDBStartEpisodeNumber, xrefTemp.TvDBID, xrefTemp.TvDBSeasonNumber, xrefTemp.TvDBStartEpisodeNumber); } } // check if we have this information locally // if not download it now TvDB_SeriesRepository repSeries = new TvDB_SeriesRepository(); TvDB_Series tvSeries = repSeries.GetByTvDBID(tvDBID); if (tvSeries == null) { // we download the series info here just so that we have the basic info in the // database before the queued task runs later tvSeries = GetSeriesInfoOnline(tvDBID); } // download and update series info, episode info and episode images // will also download fanart, posters and wide banners CommandRequest_TvDBUpdateSeriesAndEpisodes cmdSeriesEps = new CommandRequest_TvDBUpdateSeriesAndEpisodes(tvDBID, false); //Optimize for batch updates, if there are a lot of LinkAniDBTvDB commands queued //this will cause only one updateSeriesAndEpisodes command to be created CommandRequestRepository repCR = new CommandRequestRepository(); if (repCR.GetByCommandID(cmdSeriesEps.CommandID) == null) { cmdSeriesEps.Save(); } CrossRef_AniDB_TvDBV2 xref = repCrossRef.GetByTvDBID(session, tvDBID, tvSeasonNumber, tvEpNumber, animeID, (int)aniEpType, aniEpNumber); if (xref == null) { xref = new CrossRef_AniDB_TvDBV2(); } xref.AnimeID = animeID; xref.AniDBStartEpisodeType = (int)aniEpType; xref.AniDBStartEpisodeNumber = aniEpNumber; xref.TvDBID = tvDBID; xref.TvDBSeasonNumber = tvSeasonNumber; xref.TvDBStartEpisodeNumber = tvEpNumber; if (tvSeries != null) { xref.TvDBTitle = tvSeries.SeriesName; } if (excludeFromWebCache) { xref.CrossRefSource = (int)CrossRefSource.WebCache; } else { xref.CrossRefSource = (int)CrossRefSource.User; } repCrossRef.Save(xref); AniDB_Anime.UpdateStatsByAnimeID(animeID); logger.Trace("Changed tvdb association: {0}", animeID); if (!excludeFromWebCache) { CommandRequest_WebCacheSendXRefAniDBTvDB req = new CommandRequest_WebCacheSendXRefAniDBTvDB(xref.CrossRef_AniDB_TvDBV2ID); req.Save(); } if (ServerSettings.Trakt_IsEnabled && !string.IsNullOrEmpty(ServerSettings.Trakt_AuthToken)) { CrossRef_AniDB_TraktV2Repository repTraktXrefs = new CrossRef_AniDB_TraktV2Repository(); if (repTraktXrefs.GetByAnimeID(animeID).Count == 0) { // check for Trakt associations CommandRequest_TraktSearchAnime cmd2 = new CommandRequest_TraktSearchAnime(animeID, false); cmd2.Save(session); } } } return(""); }
/// <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); } } }
public static string LinkAniDBTvDB(int animeID, enEpisodeType aniEpType, int aniEpNumber, int tvDBID, int tvSeasonNumber, int tvEpNumber, bool excludeFromWebCache) { using (var session = JMMService.SessionFactory.OpenSession()) { CrossRef_AniDB_TvDBV2Repository repCrossRef = new CrossRef_AniDB_TvDBV2Repository(); List <CrossRef_AniDB_TvDBV2> xrefTemps = repCrossRef.GetByAnimeIDEpTypeEpNumber(session, animeID, (int)aniEpType, aniEpNumber); if (xrefTemps != null && xrefTemps.Count > 0) { foreach (CrossRef_AniDB_TvDBV2 xrefTemp in xrefTemps) { // delete the existing one if we are updating TvDBHelper.RemoveLinkAniDBTvDB(xrefTemp.AnimeID, (enEpisodeType)xrefTemp.AniDBStartEpisodeType, xrefTemp.AniDBStartEpisodeNumber, xrefTemp.TvDBID, xrefTemp.TvDBSeasonNumber, xrefTemp.TvDBStartEpisodeNumber); } } // check if we have this information locally // if not download it now TvDB_SeriesRepository repSeries = new TvDB_SeriesRepository(); TvDB_Series tvSeries = repSeries.GetByTvDBID(tvDBID); if (tvSeries == null) { // we download the series info here just so that we have the basic info in the // database before the queued task runs later tvSeries = GetSeriesInfoOnline(tvDBID); } // download and update series info, episode info and episode images // will also download fanart, posters and wide banners CommandRequest_TvDBUpdateSeriesAndEpisodes cmdSeriesEps = new CommandRequest_TvDBUpdateSeriesAndEpisodes(tvDBID, false); cmdSeriesEps.Save(); CrossRef_AniDB_TvDBV2 xref = repCrossRef.GetByTvDBID(session, tvDBID, tvSeasonNumber, tvEpNumber, animeID, (int)aniEpType, aniEpNumber); if (xref == null) { xref = new CrossRef_AniDB_TvDBV2(); } xref.AnimeID = animeID; xref.AniDBStartEpisodeType = (int)aniEpType; xref.AniDBStartEpisodeNumber = aniEpNumber; xref.TvDBID = tvDBID; xref.TvDBSeasonNumber = tvSeasonNumber; xref.TvDBStartEpisodeNumber = tvEpNumber; if (tvSeries != null) { xref.TvDBTitle = tvSeries.SeriesName; } if (excludeFromWebCache) { xref.CrossRefSource = (int)CrossRefSource.WebCache; } else { xref.CrossRefSource = (int)CrossRefSource.User; } repCrossRef.Save(xref); StatsCache.Instance.UpdateUsingAnime(animeID); logger.Trace("Changed tvdb association: {0}", animeID); if (!excludeFromWebCache) { CommandRequest_WebCacheSendXRefAniDBTvDB req = new CommandRequest_WebCacheSendXRefAniDBTvDB(xref.CrossRef_AniDB_TvDBV2ID); req.Save(); } } return(""); }