public bool Init(AnimeEpisode aniepisode) { try { if (string.IsNullOrEmpty(ServerSettings.Trakt_Username) || string.IsNullOrEmpty(ServerSettings.Trakt_Password)) return false; username = ServerSettings.Trakt_Username; password = Utils.CalculateSHA1(ServerSettings.Trakt_Password, Encoding.Default); imdb_id = ""; AnimeSeries ser = aniepisode.GetAnimeSeries(); if (ser == null) return false; CrossRef_AniDB_TraktRepository repCrossRef = new CrossRef_AniDB_TraktRepository(); CrossRef_AniDB_Trakt xref = repCrossRef.GetByAnimeID(ser.AniDB_ID); if (xref == null) return false; Trakt_ShowRepository repShows = new Trakt_ShowRepository(); Trakt_Show show = repShows.GetByTraktID(xref.TraktID); if (show == null) return false; if (!show.TvDB_ID.HasValue) return false; tvdb_id = show.TvDB_ID.Value.ToString(); title = show.Title; year = show.Year; int retEpNum = 0, retSeason = 0; GetTraktEpisodeNumber(aniepisode, show, xref.TraktSeasonNumber, ref retEpNum, ref retSeason); if (retEpNum < 0) return false; episode = retEpNum.ToString(); season = retSeason.ToString(); AniDB_Episode aniep = aniepisode.AniDB_Episode; if (aniep != null) { TimeSpan t = TimeSpan.FromSeconds(aniep.LengthSeconds + 14); int toMinutes = int.Parse(Math.Round(t.TotalMinutes).ToString()); duration = toMinutes.ToString(); } else duration = "25"; progress = "100"; plugin_version = "0.4"; media_center_version = "1.2.0.1"; media_center_date = "Dec 17 2010"; } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); return false; } return true; }
public override void ProcessCommand() { try { CrossRef_AniDB_TraktRepository repCrossRef = new CrossRef_AniDB_TraktRepository(); CrossRef_AniDB_Trakt xref = repCrossRef.GetByID(CrossRef_AniDB_TraktID); if (xref == null) return; Trakt_ShowRepository repShow = new Trakt_ShowRepository(); Trakt_Show tvShow = repShow.GetByTraktID(xref.TraktID); if (tvShow == null) return; string showName = ""; if (tvShow != null) showName = tvShow.Title; XMLService.Send_CrossRef_AniDB_Trakt(xref, showName); } catch (Exception ex) { logger.ErrorException("Error processing CommandRequest_WebCacheSendXRefAniDBTrakt: {0}" + ex.ToString(), ex); return; } }
public static void MigrateTraktLinks_V1_to_V2() { try { AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); Trakt_EpisodeRepository repEps = new Trakt_EpisodeRepository(); Trakt_ShowRepository repShows = new Trakt_ShowRepository(); CrossRef_AniDB_TraktRepository repCrossRefTrakt = new CrossRef_AniDB_TraktRepository(); CrossRef_AniDB_TraktV2Repository repCrossRefTraktNew = new CrossRef_AniDB_TraktV2Repository(); using (var session = JMMService.SessionFactory.OpenSession()) { List<CrossRef_AniDB_Trakt> xrefsTrakt = repCrossRefTrakt.GetAll(); foreach (CrossRef_AniDB_Trakt xrefTrakt in xrefsTrakt) { CrossRef_AniDB_TraktV2 xrefNew = new CrossRef_AniDB_TraktV2(); xrefNew.AnimeID = xrefTrakt.AnimeID; xrefNew.CrossRefSource = xrefTrakt.CrossRefSource; xrefNew.TraktID = xrefTrakt.TraktID; xrefNew.TraktSeasonNumber = xrefTrakt.TraktSeasonNumber; Trakt_Show show = xrefTrakt.GetByTraktShow(session); if (show != null) xrefNew.TraktTitle = show.Title; // determine start ep type if (xrefTrakt.TraktSeasonNumber == 0) xrefNew.AniDBStartEpisodeType = (int)AniDBAPI.enEpisodeType.Special; else xrefNew.AniDBStartEpisodeType = (int)AniDBAPI.enEpisodeType.Episode; xrefNew.AniDBStartEpisodeNumber = 1; xrefNew.TraktStartEpisodeNumber = 1; repCrossRefTraktNew.Save(xrefNew); } // create cross ref's for specials foreach (CrossRef_AniDB_Trakt xrefTrakt in xrefsTrakt) { AniDB_Anime anime = repAnime.GetByAnimeID(xrefTrakt.AnimeID); if (anime == null) continue; Trakt_Show show = xrefTrakt.GetByTraktShow(session); if (show == null) continue; // this anime has specials if (anime.EpisodeCountSpecial <= 0) continue; // this Trakt series has a season 0 (specials) List<int> seasons = repEps.GetSeasonNumbersForSeries(show.Trakt_ShowID); if (!seasons.Contains(0)) continue; //make sure we are not doubling up CrossRef_AniDB_TraktV2 temp = repCrossRefTraktNew.GetByTraktID(xrefTrakt.TraktID, 0, 1, xrefTrakt.AnimeID, (int)AniDBAPI.enEpisodeType.Special, 1); if (temp != null) continue; CrossRef_AniDB_TraktV2 xrefNew = new CrossRef_AniDB_TraktV2(); xrefNew.AnimeID = xrefTrakt.AnimeID; xrefNew.CrossRefSource = xrefTrakt.CrossRefSource; xrefNew.TraktID = xrefTrakt.TraktID; xrefNew.TraktSeasonNumber = 0; xrefNew.TraktStartEpisodeNumber = 1; xrefNew.AniDBStartEpisodeType = (int)AniDBAPI.enEpisodeType.Special; xrefNew.AniDBStartEpisodeNumber = 1; xrefNew.TraktTitle = show.Title; repCrossRefTraktNew.Save(xrefNew); } } } catch (Exception ex) { logger.ErrorException("Could not MigrateTraktLinks_V1_to_V2: " + ex.ToString(), ex); } }
public static void FixDuplicateTraktLinks() { AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); // delete all Trakt link duplicates CrossRef_AniDB_TraktRepository repCrossRefTrakt = new CrossRef_AniDB_TraktRepository(); List<CrossRef_AniDB_Trakt> xrefsTraktProcessed = new List<CrossRef_AniDB_Trakt>(); List<CrossRef_AniDB_Trakt> xrefsTraktToBeDeleted = new List<CrossRef_AniDB_Trakt>(); List<CrossRef_AniDB_Trakt> xrefsTrakt = repCrossRefTrakt.GetAll(); foreach (CrossRef_AniDB_Trakt xrefTrakt in xrefsTrakt) { bool deleteXref = false; foreach (CrossRef_AniDB_Trakt xref in xrefsTraktProcessed) { if (xref.TraktID == xrefTrakt.TraktID && xref.TraktSeasonNumber == xrefTrakt.TraktSeasonNumber) { xrefsTraktToBeDeleted.Add(xrefTrakt); deleteXref = true; } } if (!deleteXref) xrefsTraktProcessed.Add(xrefTrakt); } foreach (CrossRef_AniDB_Trakt xref in xrefsTraktToBeDeleted) { string msg = ""; AniDB_Anime anime = repAnime.GetByAnimeID(xref.AnimeID); if (anime != null) msg = anime.MainTitle; logger.Warn("Deleting Trakt Link because of a duplicate: {0} ({1}) - {2}/{3}", xref.AnimeID, msg, xref.TraktID, xref.TraktSeasonNumber); repCrossRefTrakt.Delete(xref.CrossRef_AniDB_TraktID); } }
public Contract_Trakt_Activity GetTraktFriendInfo(int maxResults, bool animeOnly, bool getShouts, bool getScrobbles) { CrossRef_AniDB_TraktRepository repXrefTrakt = new CrossRef_AniDB_TraktRepository(); CrossRef_AniDB_TvDBV2Repository repXrefTvDB = new CrossRef_AniDB_TvDBV2Repository(); AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); Trakt_FriendRepository repFriends = new Trakt_FriendRepository(); Trakt_EpisodeRepository repEpisodes = new Trakt_EpisodeRepository(); Trakt_ShowRepository repShows = new Trakt_ShowRepository(); Contract_Trakt_Activity contract = new Contract_Trakt_Activity(); contract.HasTraktAccount = true; if (string.IsNullOrEmpty(ServerSettings.Trakt_Username) || string.IsNullOrEmpty(ServerSettings.Trakt_Password)) contract.HasTraktAccount = false; contract.TraktFriends = new List<Contract_Trakt_Friend>(); contract.TraktFriendRequests = new List<Contract_Trakt_FriendFrequest>(); contract.TraktFriendActivity = new List<Contract_Trakt_FriendActivity>(); try { int i = 1; foreach (TraktTV_Activity act in StatsCache.Instance.TraktFriendActivityInfo) { if (i >= maxResults) break; if (act.ActivityAction == (int)TraktActivityAction.Scrobble && !getScrobbles) continue; if (act.ActivityAction == (int)TraktActivityAction.Shout && !getShouts) continue; Contract_Trakt_FriendActivity contractAct = new Contract_Trakt_FriendActivity(); if (act.show == null) continue; // find the anime and series based on the trakt id int? animeID = null; CrossRef_AniDB_Trakt xref = null; if (act.episode != null) xref = repXrefTrakt.GetByTraktID(act.show.TraktID, int.Parse(act.episode.season)); if (xref != null) animeID = xref.AnimeID; else { // try a rough match // since we won't always do an exact match by season List<CrossRef_AniDB_Trakt> traktXrefs = repXrefTrakt.GetByTraktID(act.show.TraktID); if (traktXrefs.Count > 0) animeID = traktXrefs[0].AnimeID; else { // try the tvdb id instead //TODO /* CrossRef_AniDB_TvDBV2 xrefTvDB = null; if (act.episode != null) xrefTvDB = repXrefTvDB.GetByTvDBID(int.Parse(act.show.tvdb_id), int.Parse(act.episode.season)); if (xrefTvDB != null) animeID = xrefTvDB.AnimeID;*/ } } // skip this activity if we can't find the anime and the user only wants to see anime related stuff if (!animeID.HasValue && animeOnly) { //TODO // however let's try and look it up on the web cache to see if it is an anime // this just might be an anime that user doesn't have in their local database continue; } // activity details contractAct.ActivityAction = act.ActivityAction; contractAct.ActivityType = act.ActivityType; contractAct.ActivityDate = Utils.GetAniDBDateAsDate(act.timestamp); if (act.elapsed != null) { contractAct.Elapsed = act.elapsed.full; contractAct.ElapsedShort = act.elapsed.shortElapsed; } Trakt_Friend traktFriend = repFriends.GetByUsername(act.user.username); if (traktFriend == null) return null; // user details contractAct.User = new Contract_Trakt_User(); contractAct.User.Trakt_FriendID = traktFriend.Trakt_FriendID; contractAct.User.Username = act.user.username; contractAct.User.Full_name = act.user.full_name; contractAct.User.Gender = act.user.gender; contractAct.User.Age = act.user.age; contractAct.User.Location = act.user.location; contractAct.User.About = act.user.about; contractAct.User.Joined = act.user.joined; contractAct.User.Avatar = act.user.avatar; contractAct.User.Url = act.user.url; contractAct.User.JoinedDate = Utils.GetAniDBDateAsDate(act.user.joined); // episode details if (act.ActivityAction == (int)TraktActivityAction.Scrobble && act.episode != null) // scrobble episode { contractAct.Episode = new Contract_Trakt_WatchedEpisode(); contractAct.Episode.AnimeSeriesID = null; contractAct.Episode.Episode_Number = act.episode.number; contractAct.Episode.Episode_Overview = act.episode.overview; contractAct.Episode.Episode_Season = act.episode.season; contractAct.Episode.Episode_Title = act.episode.title; contractAct.Episode.Episode_Url = act.episode.url; contractAct.Episode.Trakt_EpisodeID = -1; if (act.episode.images != null) contractAct.Episode.Episode_Screenshot = act.episode.images.screen; if (act.show != null) { contractAct.Episode.TraktShow = act.show.ToContract(); Trakt_Show show = repShows.GetByTraktID(act.show.TraktID); if (show != null) { Trakt_Episode episode = repEpisodes.GetByShowIDSeasonAndEpisode(show.Trakt_ShowID, int.Parse(act.episode.season), int.Parse(act.episode.number)); if (episode != null) contractAct.Episode.Trakt_EpisodeID = episode.Trakt_EpisodeID; } if (animeID.HasValue) { AnimeSeries ser = repSeries.GetByAnimeID(animeID.Value); if (ser != null) contractAct.Episode.AnimeSeriesID = ser.AnimeSeriesID; AniDB_Anime anime = repAnime.GetByAnimeID(animeID.Value); if (anime != null) contractAct.Episode.Anime = anime.ToContract(true, null); } } } // shout details if (act.ActivityAction == (int)TraktActivityAction.Shout && act.shout != null) // shout { contractAct.Shout = new Contract_Trakt_Shout(); contractAct.Shout.ShoutType = act.ActivityType; // episode or show contractAct.Shout.Text = act.shout.text; contractAct.Shout.Spoiler = act.shout.spoiler; contractAct.Shout.AnimeSeriesID = null; if (act.ActivityType == 1 && act.episode != null) // episode { contractAct.Shout.Episode_Number = act.episode.number; contractAct.Shout.Episode_Overview = act.episode.overview; contractAct.Shout.Episode_Season = act.episode.season; contractAct.Shout.Episode_Title = act.episode.title; contractAct.Shout.Episode_Url = act.episode.url; if (act.episode.images != null) contractAct.Shout.Episode_Screenshot = act.episode.images.screen; } if (act.show != null) // episode or show { if (act.episode == null) contractAct.Shout.Episode_Screenshot = act.show.images.fanart; contractAct.Shout.TraktShow = act.show.ToContract(); if (animeID.HasValue) { AnimeSeries ser = repSeries.GetByAnimeID(animeID.Value); if (ser != null) contractAct.Shout.AnimeSeriesID = ser.AnimeSeriesID; AniDB_Anime anime = repAnime.GetByAnimeID(animeID.Value); if (anime != null) contractAct.Shout.Anime = anime.ToContract(true, null); } } } contract.TraktFriendActivity.Add(contractAct); i++; } foreach (TraktTVFriendRequest req in StatsCache.Instance.TraktFriendRequests) { Contract_Trakt_FriendFrequest contractReq = req.ToContract(); contract.TraktFriendRequests.Add(contractReq); } } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); } return contract; }
public string LinkAniDBTrakt(int animeID, string traktID, int seasonNumber) { try { CrossRef_AniDB_TraktRepository repXrefTrakt = new CrossRef_AniDB_TraktRepository(); CrossRef_AniDB_Trakt xref = repXrefTrakt.GetByTraktID(traktID, seasonNumber); if (xref != null) return string.Format("You have already linked Anime ID {0} to this Trakt show/season", xref.AnimeID); TraktTVHelper.LinkAniDBTrakt(animeID, traktID, seasonNumber, false); return ""; } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); return ex.Message; } }
public Contract_CrossRef_AniDB_Trakt GetTraktCrossRef(int animeID) { try { CrossRef_AniDB_TraktRepository repCrossRef = new CrossRef_AniDB_TraktRepository(); CrossRef_AniDB_Trakt xref = repCrossRef.GetByAnimeID(animeID); if (xref == null) return null; return xref.ToContract(); } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); return null; } }
public Contract_Trakt_Friend ToContract() { CrossRef_AniDB_TraktRepository repXrefTrakt = new CrossRef_AniDB_TraktRepository(); CrossRef_AniDB_TvDBRepository repXrefTvDB = new CrossRef_AniDB_TvDBRepository(); AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); Trakt_FriendRepository repFriends = new Trakt_FriendRepository(); Trakt_EpisodeRepository repEpisodes = new Trakt_EpisodeRepository(); Trakt_Friend traktFriend = repFriends.GetByUsername(username); if (traktFriend == null) return null; Contract_Trakt_Friend contract = new Contract_Trakt_Friend(); contract.Trakt_FriendID = traktFriend.Trakt_FriendID; contract.Username = username; contract.Full_name = full_name; contract.Gender = gender; contract.Age = age; contract.Location = location; contract.About = about; contract.Joined = joined; contract.Avatar = avatar; contract.Url = url; contract.JoinedDate = Utils.GetAniDBDateAsDate(joined); contract.WatchedEpisodes = new List<Contract_Trakt_WatchedEpisode>(); // we only care about the watched episodes foreach (TraktTVWatched wtch in watched) { if (wtch.episode != null) { Contract_Trakt_WatchedEpisode watchedEp = new Contract_Trakt_WatchedEpisode(); watchedEp.Watched = wtch.watched; watchedEp.WatchedDate = Utils.GetAniDBDateAsDate(wtch.watched); if (!contract.LastEpisodeWatched.HasValue) contract.LastEpisodeWatched = watchedEp.WatchedDate; if (watchedEp.WatchedDate.HasValue && watchedEp.WatchedDate > contract.LastEpisodeWatched) contract.LastEpisodeWatched = watchedEp.WatchedDate; watchedEp.AnimeSeriesID = null; watchedEp.Episode_Number = wtch.episode.number; watchedEp.Episode_Overview = wtch.episode.overview; watchedEp.Episode_Season = wtch.episode.season; watchedEp.Episode_Title = wtch.episode.title; watchedEp.Episode_Url = wtch.episode.url; if (wtch.episode.images != null) watchedEp.Episode_Screenshot = wtch.episode.images.screen; if (wtch.show != null) { watchedEp.TraktShow = wtch.show.ToContract(); // find the anime and series based on the trakt id int? animeID = null; CrossRef_AniDB_Trakt xref = repXrefTrakt.GetByTraktID(wtch.show.TraktID, int.Parse(wtch.episode.season)); if (xref != null) animeID = xref.AnimeID; else { // try the tvdb id instead //TODO /* CrossRef_AniDB_TvDB xrefTvDB = repXrefTvDB.GetByTvDBID(int.Parse(wtch.show.tvdb_id), int.Parse(wtch.episode.season)); if (xrefTvDB != null) animeID = xrefTvDB.AnimeID;*/ } if (animeID.HasValue) { AnimeSeries ser = repSeries.GetByAnimeID(animeID.Value); if (ser != null) watchedEp.AnimeSeriesID = ser.AnimeSeriesID; AniDB_Anime anime = repAnime.GetByAnimeID(animeID.Value); if (anime != null) watchedEp.Anime = anime.ToContract(true, null); } } contract.WatchedEpisodes.Add(watchedEp); break; // only show the latest show } } List<SortPropOrFieldAndDirection> sortCriteria = new List<SortPropOrFieldAndDirection>(); sortCriteria.Add(new SortPropOrFieldAndDirection("WatchedDate", true, SortType.eDateTime)); contract.WatchedEpisodes = Sorting.MultiSort<Contract_Trakt_WatchedEpisode>(contract.WatchedEpisodes, sortCriteria); return contract; }
public static void UpdateAllInfo() { CrossRef_AniDB_TraktRepository repCrossRef = new CrossRef_AniDB_TraktRepository(); List<CrossRef_AniDB_Trakt> allCrossRefs = repCrossRef.GetAll(); foreach (CrossRef_AniDB_Trakt xref in allCrossRefs) { CommandRequest_TraktUpdateInfoAndImages cmd = new CommandRequest_TraktUpdateInfoAndImages(xref.TraktID); cmd.Save(); } }
public CrossRef_AniDB_Trakt GetCrossRefTrakt(ISession session) { CrossRef_AniDB_TraktRepository repCrossRef = new CrossRef_AniDB_TraktRepository(); return repCrossRef.GetByAnimeID(session, this.AnimeID); }
public static void ScanForMatches() { AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); List<AnimeSeries> allSeries = repSeries.GetAll(); CrossRef_AniDB_TraktRepository repCrossRef = new CrossRef_AniDB_TraktRepository(); List<CrossRef_AniDB_Trakt> allCrossRefs = repCrossRef.GetAll(); List<int> alreadyLinked = new List<int>(); foreach (CrossRef_AniDB_Trakt xref in allCrossRefs) { alreadyLinked.Add(xref.AnimeID); } foreach (AnimeSeries ser in allSeries) { if (alreadyLinked.Contains(ser.AniDB_ID)) continue; AniDB_Anime anime = ser.GetAnime(); if (anime != null) logger.Trace("Found anime without Trakt association: " + anime.MainTitle); if (anime.IsTraktLinkDisabled) continue; CommandRequest_TraktSearchAnime cmd = new CommandRequest_TraktSearchAnime(ser.AniDB_ID, false); cmd.Save(); } }
public static bool PostShoutShow(int animeID, string shoutText, bool isSpoiler, ref string returnMessage) { returnMessage = ""; try { if (string.IsNullOrEmpty(ServerSettings.Trakt_Username) || string.IsNullOrEmpty(ServerSettings.Trakt_Password)) { returnMessage = "Trakt credentials have not been entered"; return false; } if (string.IsNullOrEmpty(shoutText)) { returnMessage = "Please enter text for your shout"; return false; } CrossRef_AniDB_TraktRepository repXrefTrakt = new CrossRef_AniDB_TraktRepository(); Trakt_ShowRepository repTraktShow = new Trakt_ShowRepository(); CrossRef_AniDB_Trakt traktXRef = repXrefTrakt.GetByAnimeID(animeID); if (traktXRef == null) { returnMessage = string.Format("Could not find trakt show for Anime ID: {0}", animeID); return false; } Trakt_Show show = repTraktShow.GetByTraktID(traktXRef.TraktID); if (show == null || !show.TvDB_ID.HasValue) { returnMessage = string.Format("Could not find trakt show for Anime ID: {0}", animeID); return false; } TraktTVPost_ShoutShow cmd = new TraktTVPost_ShoutShow(); cmd.Init(shoutText, isSpoiler, show.TvDB_ID.Value); string url = string.Format(Constants.TraktTvURLs.URLPostShoutShow, Constants.TraktTvURLs.APIKey); logger.Trace("PostShoutShow: {0}", url); string json = JSONHelper.Serialize<TraktTVPost_ShoutShow>(cmd); string jsonResponse = SendData(url, json); TraktTVGenericResponse genResponse = JSONHelper.Deserialize<TraktTVGenericResponse>(jsonResponse); if (genResponse.IsSuccess) { returnMessage = genResponse.message; return true; } else { returnMessage = genResponse.error; return false; } } catch (Exception ex) { logger.ErrorException("Error in TraktTVHelper.PostShoutShow: " + ex.ToString(), ex); returnMessage = ex.Message; return false; } }
// Removes all Trakt information from a series, bringing it back to a blank state. public static void RemoveLinkAniDBTrakt(AnimeSeries ser) { CrossRef_AniDB_TraktRepository repCrossRef = new CrossRef_AniDB_TraktRepository(); CrossRef_AniDB_Trakt xref = repCrossRef.GetByAnimeID(ser.AniDB_ID); if (xref == null) return; repCrossRef.Delete(xref.CrossRef_AniDB_TraktID); CommandRequest_WebCacheDeleteXRefAniDBTrakt req = new CommandRequest_WebCacheDeleteXRefAniDBTrakt(ser.AniDB_ID); req.Save(); }
public static void LinkAniDBTrakt(ISession session, int animeID, string traktID, int seasonNumber, bool fromWebCache) { CrossRef_AniDB_TraktRepository repCrossRef = new CrossRef_AniDB_TraktRepository(); CrossRef_AniDB_Trakt xrefTemp = repCrossRef.GetByTraktID(traktID, seasonNumber); if (xrefTemp != null) { string msg = string.Format("Not using Trakt link as one already exists {0} ({1}) - {2}", traktID, seasonNumber, animeID); logger.Warn(msg); return; } // check if we have this information locally // if not download it now Trakt_ShowRepository repShow = new Trakt_ShowRepository(); Trakt_Show traktShow = repShow.GetByTraktID(traktID); if (traktShow == null) { // we download the series info here TraktTVShow tvshow = GetShowInfo(traktID); if (tvshow == null) return; } // download fanart, posters DownloadAllImages(traktID); CrossRef_AniDB_Trakt xref = repCrossRef.GetByAnimeID(animeID); if (xref == null) xref = new CrossRef_AniDB_Trakt(); xref.AnimeID = animeID; if (fromWebCache) xref.CrossRefSource = (int)CrossRefSource.WebCache; else xref.CrossRefSource = (int)CrossRefSource.User; xref.TraktID = traktID; xref.TraktSeasonNumber = seasonNumber; repCrossRef.Save(xref); StatsCache.Instance.UpdateUsingAnime(session, animeID); logger.Trace("Changed trakt association: {0}", animeID); CommandRequest_WebCacheSendXRefAniDBTrakt req = new CommandRequest_WebCacheSendXRefAniDBTrakt(xref.CrossRef_AniDB_TraktID); req.Save(); }
public static List<TraktTV_ShoutGet> GetShowShouts(ISession session, int animeID) { List<TraktTV_ShoutGet> shouts = null; try { if (string.IsNullOrEmpty(ServerSettings.Trakt_Username) || string.IsNullOrEmpty(ServerSettings.Trakt_Password)) return null; CrossRef_AniDB_TraktRepository repXrefTrakt = new CrossRef_AniDB_TraktRepository(); CrossRef_AniDB_Trakt traktXRef = repXrefTrakt.GetByAnimeID(session, animeID); if (traktXRef == null) return null; string url = string.Format(Constants.TraktTvURLs.URLGetShowShouts, Constants.TraktTvURLs.APIKey, traktXRef.TraktID); logger.Trace("GetShowShouts: {0}", url); // Search for a series string json = Utils.DownloadWebPage(url); if (json.Trim().Length == 0) return new List<TraktTV_ShoutGet>(); shouts = JSONHelper.Deserialize<List<TraktTV_ShoutGet>>(json); Trakt_FriendRepository repFriends = new Trakt_FriendRepository(); foreach (TraktTV_ShoutGet shout in shouts) { Trakt_Friend traktFriend = repFriends.GetByUsername(session, shout.user.username); if (traktFriend == null) { traktFriend = new Trakt_Friend(); traktFriend.LastAvatarUpdate = DateTime.Now; } traktFriend.Populate(shout.user); repFriends.Save(traktFriend); if (!string.IsNullOrEmpty(traktFriend.FullImagePath)) { bool fileExists = File.Exists(traktFriend.FullImagePath); TimeSpan ts = DateTime.Now - traktFriend.LastAvatarUpdate; if (!fileExists || ts.TotalHours > 8) { traktFriend.LastAvatarUpdate = DateTime.Now; CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(traktFriend.Trakt_FriendID, JMMImageType.Trakt_Friend, true); cmd.Save(session); } } } } catch (Exception ex) { logger.ErrorException("Error in TraktTVHelper.GetShowShouts: " + ex.ToString(), ex); } return shouts; }