public static Azure_CrossRef_AniDB_Other Get_CrossRefAniDBOther(int animeID, CrossRefType xrefType) { if (!ServerSettings.WebCache_TvDB_Get) { return(null); } string username = ServerSettings.AniDB_Username; if (ServerSettings.WebCache_Anonymous) { username = Constants.AnonWebCacheUsername; } string uri = string.Format(@"http://{0}/api/CrossRef_AniDB_Other/{1}?p={2}&p2={3}", azureHostBaseAddress, animeID, username, (int)xrefType); string msg = string.Format("Getting AniDB/Other Cross Ref From Cache: {0}", animeID); DateTime start = DateTime.Now; ShokoService.LogToSystem(Constants.DBLogType.APIAzureHTTP, msg); string json = GetDataJson(uri); TimeSpan ts = DateTime.Now - start; msg = string.Format("Got AniDB/MAL Cross Ref From Cache: {0} - {1}", animeID, ts.TotalMilliseconds); ShokoService.LogToSystem(Constants.DBLogType.APIAzureHTTP, msg); Azure_CrossRef_AniDB_Other xref = JSONHelper.Deserialize <Azure_CrossRef_AniDB_Other>(json); return(xref); }
public static Azure_CrossRef_AniDB_Other Get_CrossRefAniDBOther(int animeID, CrossRefType xrefType) { try { if (!ServerSettings.Instance.WebCache.TvDB_Get) { return(null); } string username = Constants.AnonWebCacheUsername; string uri = $@"http://{azureHostBaseAddress}/api/CrossRef_AniDB_Other/{animeID}?p={username}&p2={ (int) xrefType }"; string msg = $"Getting AniDB/Other Cross Ref From Cache: {animeID}"; DateTime start = DateTime.Now; ShokoService.LogToSystem(Constants.DBLogType.APIAzureHTTP, msg); string json = GetDataJson(uri); TimeSpan ts = DateTime.Now - start; msg = $"Got AniDB/MAL Cross Ref From Cache: {animeID} - {ts.TotalMilliseconds}"; ShokoService.LogToSystem(Constants.DBLogType.APIAzureHTTP, msg); Azure_CrossRef_AniDB_Other xref = JSONHelper.Deserialize <Azure_CrossRef_AniDB_Other>(json); return(xref); } catch { return(null); } }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_MovieDBSearchAnime: {0}", AnimeID); try { using (var session = DatabaseFactory.SessionFactory.OpenSession()) { ISessionWrapper sessionWrapper = session.Wrap(); // first check if the user wants to use the web cache if (ServerSettings.Instance.WebCache.Enabled && ServerSettings.Instance.WebCache.TvDB_Get) { try { Azure_CrossRef_AniDB_Other crossRef = AzureWebAPI.Get_CrossRefAniDBOther(AnimeID, CrossRefType.MovieDB); if (crossRef != null) { int movieID = int.Parse(crossRef.CrossRefID); MovieDB_Movie movie = RepoFactory.MovieDb_Movie.GetByOnlineID(sessionWrapper, movieID); if (movie == null) { // update the info from online MovieDBHelper.UpdateMovieInfo(session, movieID, true); movie = RepoFactory.MovieDb_Movie.GetByOnlineID(movieID); } if (movie != null) { // since we are using the web cache result, let's save it MovieDBHelper.LinkAniDBMovieDB(AnimeID, movieID, true); return; } } } catch (Exception) { } } // Use TvDB setting if (!ServerSettings.Instance.TvDB.AutoLink) { return; } string searchCriteria = string.Empty; SVR_AniDB_Anime anime = RepoFactory.AniDB_Anime.GetByAnimeID(sessionWrapper, AnimeID); if (anime == null) { return; } searchCriteria = anime.MainTitle; // if not wanting to use web cache, or no match found on the web cache go to TvDB directly List <MovieDB_Movie_Result> results = MovieDBHelper.Search(searchCriteria); logger.Trace("Found {0} moviedb results for {1} on TheTvDB", results.Count, searchCriteria); if (ProcessSearchResults(session, results, searchCriteria)) { return; } if (results.Count == 0) { foreach (AniDB_Anime_Title title in anime.GetTitles()) { if (title.TitleType.ToUpper() != Shoko.Models.Constants.AnimeTitleType.Official.ToUpper()) { continue; } if (searchCriteria.ToUpper() == title.Title.ToUpper()) { continue; } results = MovieDBHelper.Search(title.Title); logger.Trace("Found {0} moviedb results for search on {1}", results.Count, title.Title); if (ProcessSearchResults(session, results, title.Title)) { return; } } } } } catch (Exception ex) { logger.Error("Error processing CommandRequest_TvDBSearchAnime: {0} - {1}", AnimeID, ex); } }