void btnSearch_Click(object sender, RoutedEventArgs e) { HasWebCacheRec = false; if (!VM_ShokoServer.Instance.ServerOnline) { return; } Cursor = Cursors.Wait; try { var webCacheRec = VM_ShokoServer.Instance.ShokoServices.GetTraktCrossRefWebCache(AnimeID, false); if (webCacheRec != null && webCacheRec.Count > 0) { CrossRef_AniDB_TraktResult.ReplaceRange(webCacheRec.Cast <VM_CrossRef_AniDB_TraktV2>()); if (CrossRef_AniDB_TraktResult.Count > 0) { HasWebCacheRec = true; } } // now search Trakt TraktSeriesSearchResults.ReplaceRange(VM_ShokoServer.Instance.ShokoServices.SearchTrakt(txtSearch.Text.Replace("`", "'").Trim())); } catch (Exception ex) { Utils.ShowErrorMessage(ex); } finally { Cursor = Cursors.Arrow; } }
void btnSearch_Click(object sender, RoutedEventArgs e) { TraktSeriesSearchResults.Clear(); CrossRef_AniDB_TraktResult.Clear(); HasWebCacheRec = false; if (!JMMServerVM.Instance.ServerOnline) { return; } this.Cursor = Cursors.Wait; try { // first find what the community recommends List <JMMServerBinary.Contract_Azure_CrossRef_AniDB_Trakt> xrefs = JMMServerVM.Instance.clientBinaryHTTP.GetTraktCrossRefWebCache(AnimeID, false); if (xrefs != null && xrefs.Count > 0) { foreach (JMMServerBinary.Contract_Azure_CrossRef_AniDB_Trakt xref in xrefs) { CrossRef_AniDB_TraktVMV2 xrefAzure = new CrossRef_AniDB_TraktVMV2(xref); CrossRef_AniDB_TraktResult.Add(xrefAzure); } HasWebCacheRec = true; } // now search Trakt List <JMMServerBinary.Contract_TraktTVShowResponse> traktResults = JMMServerVM.Instance.clientBinaryHTTP.SearchTrakt(txtSearch.Text.Trim()); foreach (JMMServerBinary.Contract_TraktTVShowResponse traktResult in traktResults) { TraktSeriesSearchResults.Add(new TraktTVShowResponseVM(traktResult)); } } catch (Exception ex) { Utils.ShowErrorMessage(ex); } finally { this.Cursor = Cursors.Arrow; } }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_TraktSearchAnime: {0}", AnimeID); try { using (var session = JMMService.SessionFactory.OpenSession()) { // first check if the user wants to use the web cache if (ServerSettings.WebCache_TvDB_Get) { try { CrossRef_AniDB_TraktResult crossRef = XMLService.Get_CrossRef_AniDB_Trakt(AnimeID); if (crossRef != null) { TraktTVShow showInfo = TraktTVHelper.GetShowInfo(crossRef.TraktID); if (showInfo != null) { logger.Trace("Found trakt match on web cache for {0} - id = {1}", AnimeID, showInfo.title); TraktTVHelper.LinkAniDBTrakt(AnimeID, crossRef.TraktID, crossRef.TraktSeasonNumber, true); return; } } } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); } } // lets try to see locally if we have a tvDB link for this anime // Trakt allows the use of TvDB ID's or their own Trakt ID's CrossRef_AniDB_TvDBV2Repository repCrossRefTvDB = new CrossRef_AniDB_TvDBV2Repository(); List <CrossRef_AniDB_TvDBV2> xrefTvDBs = repCrossRefTvDB.GetByAnimeID(session, AnimeID); if (xrefTvDBs != null && xrefTvDBs.Count == 1) //TODO this is temporary code, until trakt also allows multiple links { TraktTVShow showInfo = TraktTVHelper.GetShowInfo(xrefTvDBs[0].TvDBID); if (showInfo != null) { // make sure the season specified by TvDB also exists on Trakt Trakt_ShowRepository repShow = new Trakt_ShowRepository(); Trakt_Show traktShow = repShow.GetByTraktID(session, showInfo.TraktID); if (traktShow != null) { Trakt_SeasonRepository repSeasons = new Trakt_SeasonRepository(); Trakt_Season traktSeason = repSeasons.GetByShowIDAndSeason(session, traktShow.Trakt_ShowID, xrefTvDBs[0].TvDBSeasonNumber); if (traktSeason != null) { logger.Trace("Found trakt match using TvDBID locally {0} - id = {1}", AnimeID, showInfo.title); TraktTVHelper.LinkAniDBTrakt(AnimeID, showInfo.TraktID, traktSeason.Season, true); return; } } } } // if not lets try the tvdb web cache based on the same reasoning if (ServerSettings.WebCache_TvDB_Get) { List <JMMServer.Providers.Azure.CrossRef_AniDB_TvDB> cacheResults = JMMServer.Providers.Azure.AzureWebAPI.Get_CrossRefAniDBTvDB(AnimeID); if (cacheResults != null && cacheResults.Count > 0) { TraktTVShow showInfo = TraktTVHelper.GetShowInfo(cacheResults[0].TvDBID); if (showInfo != null) { // make sure the season specified by TvDB also exists on Trakt Trakt_ShowRepository repShow = new Trakt_ShowRepository(); Trakt_Show traktShow = repShow.GetByTraktID(session, showInfo.TraktID); if (traktShow != null) { Trakt_SeasonRepository repSeasons = new Trakt_SeasonRepository(); Trakt_Season traktSeason = repSeasons.GetByShowIDAndSeason(session, traktShow.Trakt_ShowID, cacheResults[0].TvDBSeasonNumber); if (traktSeason != null) { logger.Trace("Found trakt match on web cache by using TvDBID {0} - id = {1}", AnimeID, showInfo.title); TraktTVHelper.LinkAniDBTrakt(AnimeID, showInfo.TraktID, traktSeason.Season, true); return; } } } } } // finally lets try searching Trakt directly string searchCriteria = ""; AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AniDB_Anime anime = repAnime.GetByAnimeID(session, 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 <TraktTVShow> results = TraktTVHelper.SearchShow(searchCriteria); logger.Trace("Found {0} trakt results for {1} ", results.Count, searchCriteria); if (ProcessSearchResults(session, results, searchCriteria)) { return; } if (results.Count == 0) { foreach (AniDB_Anime_Title title in anime.GetTitles(session)) { if (title.TitleType.ToUpper() != Constants.AnimeTitleType.Official.ToUpper()) { continue; } if (searchCriteria.ToUpper() == title.Title.ToUpper()) { continue; } results = TraktTVHelper.SearchShow(searchCriteria); logger.Trace("Found {0} trakt 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.ToString()); return; } }
protected void Page_Load(object sender, EventArgs e) { Response.ContentType = "text/xml"; try { string aid = Utils.GetParam("AnimeID"); int animeid = 0; int.TryParse(aid, out animeid); if (animeid <= 0) { Response.Write(Constants.ERROR_XML); return; } string uname = Utils.GetParam("uname"); if (uname.Trim().Length == 0) { Response.Write(Constants.ERROR_XML); return; } CrossRef_AniDB_TraktRepository repCrossRef = new CrossRef_AniDB_TraktRepository(); CrossRef_AniDB_Trakt xref = null; // check for admin approved List <CrossRef_AniDB_Trakt> recs = repCrossRef.GetByAnimeIDApproved(animeid); if (recs.Count > 0) { xref = recs[0]; // should only be one } // check for user specific if (xref == null) { recs = repCrossRef.GetByAnimeIDUser(animeid, uname); if (recs.Count > 0) { xref = recs[0]; // should only be one } } // check for other users (anonymous) if (xref == null) { // check for other users (anonymous) recs = repCrossRef.GetByAnimeID(animeid); if (recs.Count == 0) { Response.Write(Constants.ERROR_XML); return; } // find the most popular result List <CrossRefTraktStat> results = new List <CrossRefTraktStat>(); foreach (CrossRef_AniDB_Trakt xrefloc in recs) { bool found = false; foreach (CrossRefTraktStat stat in results) { if (stat.TraktID.Equals(xrefloc.TraktID, StringComparison.InvariantCultureIgnoreCase) && stat.TraktSeason == xrefloc.TraktSeasonNumber) { found = true; stat.ResultCount++; } } if (!found) { CrossRefTraktStat stat = new CrossRefTraktStat(); stat.ResultCount = 1; stat.TraktID = xrefloc.TraktID; stat.TraktSeason = xrefloc.TraktSeasonNumber; stat.CrossRef = xrefloc; results.Add(stat); } } CrossRefTraktStat mostPopular = null; foreach (CrossRefTraktStat stat in results) { if (mostPopular == null) { mostPopular = stat; } else { if (stat.ResultCount > mostPopular.ResultCount) { mostPopular = stat; } } } xref = mostPopular.CrossRef; } CrossRef_AniDB_TraktResult result = new CrossRef_AniDB_TraktResult(xref); string ret = Utils.ConvertToXML(result, typeof(CrossRef_AniDB_TraktResult)); Response.Write(ret); } catch (Exception ex) { Response.Write(ex.ToString()); return; } }