private static void PopulateVideoEpisodeFromAnimeEpisode(Video v, AnimeEpisode ep, int userid) { AniDB_Episode aep = ep.AniDB_Episode; if (aep != null) { v.EpNumber = aep.EpisodeNumber; v.Index = aep.EpisodeNumber.ToString(); v.Title = aep.EnglishName; v.OriginalTitle = aep.RomajiName; v.Rating = (float.Parse(aep.Rating, CultureInfo.InvariantCulture)).ToString(CultureInfo.InvariantCulture); if (aep.AirDateAsDate.HasValue) { v.Year = aep.AirDateAsDate.Value.Year.ToString(); v.OriginallyAvailableAt = aep.AirDateAsDate.Value.ToPlexDate(); } AnimeEpisode_User epuser = ep.GetUserRecord(userid); if (epuser != null) { v.ViewCount = epuser.WatchedCount.ToString(); if (epuser.WatchedDate.HasValue) { v.LastViewedAt = epuser.WatchedDate.Value.ToUnixTime(); } } MetroContract_Anime_Episode contract = new MetroContract_Anime_Episode(); JMMServiceImplementationMetro.SetTvDBInfo(aep.AnimeID, aep, ref contract); v.Thumb = contract.GenPoster(); v.Summary = contract.EpisodeOverview; } }
public static void Init() { JMMUser.Populate(a => a.JMMUserID); CloudAccount.Populate(a => a.CloudID); ImportFolder.Populate(a => a.ImportFolderID); AniDB_Anime.Populate(a => a.AniDB_AnimeID); AniDB_Episode.Populate(a => a.AniDB_EpisodeID); AniDB_File.Populate(a => a.AniDB_FileID); AniDB_Anime_Title.Populate(a => a.AniDB_Anime_TitleID); AniDB_Anime_Tag.Populate(a => a.AniDB_Anime_TagID); AniDB_Tag.Populate(a => a.AniDB_TagID); CustomTag.Populate(a => a.CustomTagID); CrossRef_CustomTag.Populate(a => a.CrossRef_CustomTagID); CrossRef_File_Episode.Populate(a => a.CrossRef_File_EpisodeID); VideoLocalPlace.Populate(a => a.VideoLocal_Place_ID); VideoLocal.Populate(a => a.VideoLocalID); VideoLocalUser.Populate(a => a.VideoLocal_UserID); GroupFilter.Populate(a => a.GroupFilterID); AnimeEpisode.Populate(a => a.AnimeEpisodeID); AnimeEpisode_User.Populate(a => a.AnimeEpisode_UserID); AnimeSeries.Populate(a => a.AnimeSeriesID); AnimeSeries_User.Populate(a => a.AnimeSeries_UserID); AnimeGroup.Populate(a => a.AnimeGroupID); AnimeGroup_User.Populate(a => a.AnimeGroup_UserID); GroupFilter.PostProcess(); CleanUpMemory(); }
public static UserInfo GetUserInfoData(string dashType = "", string vidPlayer = "") { try { if (string.IsNullOrEmpty(ServerSettings.AniDB_Username)) { return(null); } UserInfo uinfo = new UserInfo(); uinfo.DateTimeUpdated = DateTime.Now; uinfo.DateTimeUpdatedUTC = 0; // Optional JMM Desktop data uinfo.DashboardType = null; uinfo.VideoPlayer = vidPlayer; System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly(); try { if (a != null) { uinfo.JMMServerVersion = Utils.GetApplicationVersion(a); } } catch { } uinfo.UsernameHash = Utils.GetMd5Hash(ServerSettings.AniDB_Username); uinfo.DatabaseType = ServerSettings.DatabaseType; uinfo.WindowsVersion = Utils.GetOSInfo(); uinfo.TraktEnabled = ServerSettings.Trakt_IsEnabled ? 1 : 0; uinfo.MALEnabled = string.IsNullOrEmpty(ServerSettings.MAL_Username) ? 0 : 1; uinfo.CountryLocation = ""; // this field is not actually used uinfo.LastEpisodeWatchedAsDate = DateTime.Now.AddDays(-5); uinfo.LocalUserCount = (int)RepoFactory.JMMUser.GetTotalRecordCount(); uinfo.FileCount = RepoFactory.VideoLocal.GetTotalRecordCount(); AnimeEpisode_User rec = RepoFactory.AnimeEpisode_User.GetLastWatchedEpisode(); uinfo.LastEpisodeWatched = 0; if (rec != null) { uinfo.LastEpisodeWatched = Utils.GetAniDBDateAsSeconds(rec.WatchedDate); } return(uinfo); } catch (Exception ex) { logger.Error(ex, ex.ToString()); return(null); } }
public void Save(AnimeEpisode_User obj) { lock (obj) { if (obj.AnimeEpisode_UserID == 0) { using (var session = JMMService.SessionFactory.OpenSession()) { using (var transaction = session.BeginTransaction()) { session.SaveOrUpdate(obj); transaction.Commit(); } } } using (var session = JMMService.SessionFactory.OpenSession()) { UpdateContract(session, obj); // populate the database using (var transaction = session.BeginTransaction()) { session.SaveOrUpdate(obj); transaction.Commit(); } } Cache.Update(obj); } }
public static void Init() { JMMUser.Populate(); CloudAccount.Populate(); ImportFolder.Populate(); AniDB_Anime.Populate(); AniDB_Episode.Populate(); AniDB_File.Populate(); AniDB_Anime_Title.Populate(); AniDB_Anime_Tag.Populate(); AniDB_Tag.Populate(); CustomTag.Populate(); CrossRef_CustomTag.Populate(); CrossRef_File_Episode.Populate(); VideoLocalPlace.Populate(); VideoLocal.Populate(); VideoLocalUser.Populate(); GroupFilter.Populate(); AnimeEpisode.Populate(); AnimeEpisode_User.Populate(); AnimeSeries.Populate(); AnimeSeries_User.Populate(); AnimeGroup.Populate(); AnimeGroup_User.Populate(); // Update Contracts if necessary try { JMMUser.RegenerateDb(); CloudAccount.RegenerateDb(); ImportFolder.RegenerateDb(); AniDB_Anime.RegenerateDb(); AniDB_Episode.RegenerateDb(); AniDB_File.RegenerateDb(); AniDB_Anime_Title.RegenerateDb(); AniDB_Anime_Tag.RegenerateDb(); AniDB_Tag.RegenerateDb(); CustomTag.RegenerateDb(); CrossRef_CustomTag.RegenerateDb(); CrossRef_File_Episode.RegenerateDb(); VideoLocalPlace.RegenerateDb(); VideoLocal.RegenerateDb(); VideoLocalUser.RegenerateDb(); AnimeEpisode.RegenerateDb(); AnimeEpisode_User.RegenerateDb(); AnimeSeries.RegenerateDb(); AnimeSeries_User.RegenerateDb(); AnimeGroup.RegenerateDb(); AnimeGroup_User.RegenerateDb(); GroupFilter.RegenerateDb(); GroupFilter.PostProcess(); } catch (Exception e) { LogManager.GetCurrentClassLogger().Error(e, "There was an error starting the Database Factory"); } CleanUpMemory(); }
public AnimeEpisode_User GetByUserIDAndEpisodeID(ISession session, int userid, int epid) { AnimeEpisode_User obj = session .CreateCriteria(typeof(AnimeEpisode_User)) .Add(Restrictions.Eq("JMMUserID", userid)) .Add(Restrictions.Eq("AnimeEpisodeID", epid)) .UniqueResult <AnimeEpisode_User>(); return(obj); }
public void Save(AnimeEpisode_User obj) { using (var session = JMMService.SessionFactory.OpenSession()) { // populate the database using (var transaction = session.BeginTransaction()) { session.SaveOrUpdate(obj); transaction.Commit(); } } }
public static void CleanUpMemory() { AniDB_Anime.GetAll().ForEach(a => a.CollectContractMemory()); VideoLocal.GetAll().ForEach(a => a.CollectContractMemory()); AnimeEpisode.GetAll().ForEach(a => a.CollectContractMemory()); AnimeEpisode_User.GetAll().ForEach(a => a.CollectContractMemory()); AnimeSeries.GetAll().ForEach(a => a.CollectContractMemory()); AnimeSeries_User.GetAll().ForEach(a => a.CollectContractMemory()); AnimeGroup.GetAll().ForEach(a => a.CollectContractMemory()); AnimeGroup_User.GetAll().ForEach(a => a.CollectContractMemory()); GC.Collect(); }
public static void Init() { JMMUser.Populate(); CloudAccount.Populate(); ImportFolder.Populate(); AniDB_Anime.Populate(); AniDB_Episode.Populate(); AniDB_File.Populate(); AniDB_Anime_Title.Populate(); AniDB_Anime_Tag.Populate(); AniDB_Tag.Populate(); CustomTag.Populate(); CrossRef_CustomTag.Populate(); CrossRef_File_Episode.Populate(); VideoLocalPlace.Populate(); VideoLocal.Populate(); VideoLocalUser.Populate(); GroupFilter.Populate(); AnimeEpisode.Populate(); AnimeEpisode_User.Populate(); AnimeSeries.Populate(); AnimeSeries_User.Populate(); AnimeGroup.Populate(); AnimeGroup_User.Populate(); // Update Contracts if necessary JMMUser.RegenerateDb(); CloudAccount.RegenerateDb(); ImportFolder.RegenerateDb(); AniDB_Anime.RegenerateDb(); AniDB_Episode.RegenerateDb(); AniDB_File.RegenerateDb(); AniDB_Anime_Title.RegenerateDb(); AniDB_Anime_Tag.RegenerateDb(); AniDB_Tag.RegenerateDb(); CustomTag.RegenerateDb(); CrossRef_CustomTag.RegenerateDb(); CrossRef_File_Episode.RegenerateDb(); VideoLocalPlace.RegenerateDb(); VideoLocal.RegenerateDb(); VideoLocalUser.RegenerateDb(); AnimeEpisode.RegenerateDb(); AnimeEpisode_User.RegenerateDb(); AnimeSeries.RegenerateDb(); AnimeSeries_User.RegenerateDb(); AnimeGroup.RegenerateDb(); AnimeGroup_User.RegenerateDb(); GroupFilter.RegenerateDb(); GroupFilter.PostProcess(); CleanUpMemory(); }
public static void CleanUpMemory() { AniDB_Anime.GetAll().ForEach(a => a.CollectContractMemory()); VideoLocal.GetAll().ForEach(a => a.CollectContractMemory()); AnimeEpisode_User.GetAll().ForEach(a => a.CollectContractMemory()); AnimeSeries.GetAll().ForEach(a => a.CollectContractMemory()); AnimeSeries_User.GetAll().ForEach(a => a.CollectContractMemory()); AnimeGroup.GetAll().ForEach(a => a.CollectContractMemory()); AnimeGroup_User.GetAll().ForEach(a => a.CollectContractMemory()); GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce; GC.Collect(); }
public static CL_AnimeEpisode_User ToClient(this AnimeEpisode_User e) { return(new CL_AnimeEpisode_User { AnimeEpisode_UserID = e.AnimeEpisode_UserID, JMMUserID = e.JMMUserID, AnimeEpisodeID = e.AnimeEpisodeID, AnimeSeriesID = e.AnimeSeriesID, WatchedDate = e.WatchedDate, PlayedCount = e.PlayedCount, WatchedCount = e.WatchedCount, StoppedCount = e.StoppedCount }); }
public void Delete(int id) { using (var session = JMMService.SessionFactory.OpenSession()) { // populate the database using (var transaction = session.BeginTransaction()) { AnimeEpisode_User cr = GetByID(id); if (cr != null) { session.Delete(cr); transaction.Commit(); } } } }
public void UpdateContract(ISession session, AnimeEpisode_User aeu) { AnimeEpisodeRepository aerepo = new AnimeEpisodeRepository(); Contract_AnimeEpisode caep = aeu.Contract ?? new Contract_AnimeEpisode(); AnimeEpisode ep = aerepo.GetByID(aeu.AnimeEpisodeID); if (ep == null) { return; } AniDB_Episode aniEp = ep.AniDB_Episode; caep.AniDB_EpisodeID = ep.AniDB_EpisodeID; caep.AnimeEpisodeID = ep.AnimeEpisodeID; caep.AnimeSeriesID = ep.AnimeSeriesID; caep.DateTimeUpdated = ep.DateTimeUpdated; caep.IsWatched = aeu.WatchedCount > 0 ? 1 : 0; caep.PlayedCount = aeu.PlayedCount; caep.StoppedCount = aeu.StoppedCount; caep.WatchedCount = aeu.WatchedCount; caep.WatchedDate = aeu.WatchedDate; if (aniEp != null) { caep.AniDB_AirDate = aniEp.AirDateAsDate; caep.AniDB_EnglishName = aniEp.EnglishName; caep.AniDB_LengthSeconds = aniEp.LengthSeconds; caep.AniDB_Rating = aniEp.Rating; caep.AniDB_RomajiName = aniEp.RomajiName; caep.AniDB_Votes = aniEp.Votes; caep.EpisodeNumber = aniEp.EpisodeNumber; caep.EpisodeNameRomaji = aniEp.RomajiName; caep.EpisodeNameEnglish = aniEp.EnglishName; caep.EpisodeType = aniEp.EpisodeType; } //TODO if this is needed, calculating it in here will not affect performance caep.ReleaseGroups = new List <Contract_AniDBReleaseGroup>(); aeu.Contract = caep; }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_AddFileToMyList: {0}", Hash); try { VideoLocalRepository repVids = new VideoLocalRepository(); AnimeEpisodeRepository repEpisodes = new AnimeEpisodeRepository(); vid = repVids.GetByHash(this.Hash); if (vid != null) { // when adding a file via the API, newWatchedStatus will return with current watched status on AniDB // if the file is already on the user's list bool isManualLink = false; List <CrossRef_File_Episode> xrefs = vid.EpisodeCrossRefs; if (xrefs.Count > 0) { isManualLink = xrefs[0].CrossRefSource != (int)CrossRefSource.AniDB; } // mark the video file as watched DateTime?watchedDate = null; bool newWatchedStatus = false; if (isManualLink) { newWatchedStatus = JMMService.AnidbProcessor.AddFileToMyList(xrefs[0].AnimeID, xrefs[0].Episode.EpisodeNumber, ref watchedDate); } else { newWatchedStatus = JMMService.AnidbProcessor.AddFileToMyList(vid, ref watchedDate); } // do for all AniDB users JMMUserRepository repUsers = new JMMUserRepository(); List <JMMUser> aniDBUsers = repUsers.GetAniDBUsers(); List <AnimeEpisode> animeEpisodes = vid.GetAnimeEpisodes(); if (aniDBUsers.Count > 0) { JMMUser juser = aniDBUsers[0]; vid.ToggleWatchedStatus(newWatchedStatus, false, watchedDate, false, false, juser.JMMUserID, false, true); logger.Info("Adding file to list: {0} - {1}", vid.ToString(), watchedDate); // if the the episode is watched we may want to set the file to watched as well if (ServerSettings.Import_UseExistingFileWatchedStatus && !newWatchedStatus) { if (animeEpisodes.Count > 0) { AnimeEpisode ep = animeEpisodes[0]; AnimeEpisode_User epUser = null; foreach (JMMUser tempuser in aniDBUsers) { // only find the first user who watched this if (epUser == null) { epUser = ep.GetUserRecord(tempuser.JMMUserID); } } if (epUser != null) { logger.Info("Setting file as watched, because episode was already watched: {0} - user: {1}", vid.ToString(), juser.Username); vid.ToggleWatchedStatus(true, true, epUser.WatchedDate, false, false, epUser.JMMUserID, false, true); } } } } AnimeSeries ser = animeEpisodes[0].GetAnimeSeries(); // all the eps should belong to the same anime ser.UpdateStats(true, true, true); StatsCache.Instance.UpdateUsingSeries(ser.AnimeSeriesID); } } catch (Exception ex) { logger.Error("Error processing CommandRequest_AddFileToMyList: {0} - {1}", Hash, ex.ToString()); return; } }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_MALDownloadStatusFromMAL"); try { if (string.IsNullOrEmpty(ServerSettings.MAL_Username) || string.IsNullOrEmpty(ServerSettings.MAL_Password)) { return; } // find the latest eps to update AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); myanimelist mal = MALHelper.GetMALAnimeList(); if (mal == null) { return; } if (mal.anime == null) { return; } CrossRef_AniDB_MALRepository repCrossRef = new CrossRef_AniDB_MALRepository(); AniDB_EpisodeRepository repAniEps = new AniDB_EpisodeRepository(); AnimeEpisodeRepository repEp = new AnimeEpisodeRepository(); // find the anidb user JMMUserRepository repUsers = new JMMUserRepository(); List <JMMUser> aniDBUsers = repUsers.GetAniDBUsers(); if (aniDBUsers.Count == 0) { return; } JMMUser user = aniDBUsers[0]; foreach (myanimelistAnime malAnime in mal.anime) { // look up the anime CrossRef_AniDB_MAL xref = repCrossRef.GetByMALID(malAnime.series_animedb_id); if (xref == null) { continue; } if (malAnime.series_animedb_id == 8107 || malAnime.series_animedb_id == 10737) { Console.Write(""); } // check if this anime has any other links List <CrossRef_AniDB_MAL> allXrefs = repCrossRef.GetByAnimeID(xref.AnimeID); if (allXrefs.Count == 0) { continue; } // find the range of watched episodes that this applies to int startEpNumber = xref.StartEpisodeNumber; int endEpNumber = GetUpperEpisodeLimit(allXrefs, xref); List <AniDB_Episode> aniEps = repAniEps.GetByAnimeID(xref.AnimeID); foreach (AniDB_Episode aniep in aniEps) { if (aniep.EpisodeType != xref.StartEpisodeType) { continue; } AnimeEpisode ep = repEp.GetByAniDBEpisodeID(aniep.EpisodeID); if (ep == null) { continue; } int adjustedWatchedEps = malAnime.my_watched_episodes + xref.StartEpisodeNumber - 1; int epNum = aniep.EpisodeNumber; if (epNum < startEpNumber || epNum > endEpNumber) { continue; } AnimeEpisode_User usrRec = ep.GetUserRecord(user.JMMUserID); if (epNum <= adjustedWatchedEps) { // update if the user doesn't have a record (means not watched) // or it is currently un-watched bool update = false; if (usrRec == null) { update = true; } else { if (!usrRec.WatchedDate.HasValue) { update = true; } } if (update) { ep.ToggleWatchedStatus(true, true, DateTime.Now, user.JMMUserID, false); } } else { bool update = false; if (usrRec != null) { if (usrRec.WatchedDate.HasValue) { update = true; } } if (update) { ep.ToggleWatchedStatus(false, true, DateTime.Now, user.JMMUserID, false); } } } } } catch (Exception ex) { logger.Error("Error processing CommandRequest_MALDownloadStatusFromMAL: {0}", ex.ToString()); return; } }
/*public static void UpdateWatchedStatus(int animeID, enEpisodeType epType, int lastWatchedEpNumber) * { * try * { * if (string.IsNullOrEmpty(ServerSettings.MAL_Username) || string.IsNullOrEmpty(ServerSettings.MAL_Password)) * return; * * AniDB_EpisodeRepository repAniEps = new AniDB_EpisodeRepository(); * List<AniDB_Episode> aniEps = repAniEps.GetByAnimeIDAndEpisodeTypeNumber(animeID, epType, lastWatchedEpNumber); * if (aniEps.Count == 0) return; * * AnimeEpisodeRepository repEp = new AnimeEpisodeRepository(); * AnimeEpisode ep = repEp.GetByAniDBEpisodeID(aniEps[0].EpisodeID); * if (ep == null) return; * * MALHelper.UpdateMAL(ep); * } * catch (Exception ex) * { * logger.Error( ex,ex.ToString()); * } * }*/ public static void UpdateMALSeries(AnimeSeries ser) { try { if (string.IsNullOrEmpty(ServerSettings.MAL_Username) || string.IsNullOrEmpty(ServerSettings.MAL_Password)) { return; } // Populate MAL animelist hashtable if isNeverDecreaseWatched set Hashtable animeListHashtable = new Hashtable(); myanimelist malAnimeList = GetMALAnimeList(); if (ServerSettings.MAL_NeverDecreaseWatchedNums) //if set, check watched number before update: take some time, as user anime list must be loaded { if (malAnimeList != null && malAnimeList.anime != null) { for (int i = 0; i < malAnimeList.anime.Length; i++) { animeListHashtable.Add(malAnimeList.anime[i].series_animedb_id, malAnimeList.anime[i]); } } } // look for MAL Links List <CrossRef_AniDB_MAL> crossRefs = ser.GetAnime().GetCrossRefMAL(); if (crossRefs == null || crossRefs.Count == 0) { logger.Warn("Could not find MAL link for : {0} ({1})", ser.GetAnime().GetFormattedTitle(), ser.GetAnime().AnimeID); return; } List <AnimeEpisode> eps = ser.GetAnimeEpisodes(); // find the anidb user List <JMMUser> aniDBUsers = RepoFactory.JMMUser.GetAniDBUsers(); if (aniDBUsers.Count == 0) { return; } JMMUser user = aniDBUsers[0]; int score = 0; if (ser.GetAnime().UserVote != null) { score = (int)(ser.GetAnime().UserVote.VoteValue / 100); } // e.g. // AniDB - Code Geass R2 // MAL Equivalent = AniDB Normal Eps 1 - 25 / Code Geass: Hangyaku no Lelouch R2 / hxxp://myanimelist.net/anime/2904/Code_Geass:_Hangyaku_no_Lelouch_R2 // MAL Equivalent = AniDB Special Eps 1 - 9 / Code Geass: Hangyaku no Lelouch R2 Picture Drama / hxxp://myanimelist.net/anime/5163/Code_Geass:_Hangyaku_no_Lelouch_R2_Picture_Drama // MAL Equivalent = AniDB Special Eps 9 - 18 / Code Geass: Hangyaku no Lelouch R2: Flash Specials / hxxp://myanimelist.net/anime/9591/Code_Geass:_Hangyaku_no_Lelouch_R2:_Flash_Specials // MAL Equivalent = AniDB Special Eps 20 / Code Geass: Hangyaku no Lelouch - Kiseki no Birthday Picture Drama / hxxp://myanimelist.net/anime/8728/Code_Geass:_Hangyaku_no_Lelouch_-_Kiseki_no_Birthday_Picture_Drama foreach (CrossRef_AniDB_MAL xref in crossRefs) { // look for the right MAL id int malID = -1; int epNumber = -1; int totalEpCount = -1; List <string> fanSubGroups = new List <string>(); // for each cross ref (which is a series on MAL) we need to update the data // so find all the episodes which apply to this cross ref int lastWatchedEpNumber = 0; int downloadedEps = 0; foreach (AnimeEpisode ep in eps) { int epNum = ep.AniDB_Episode.EpisodeNumber; if (xref.StartEpisodeType == (int)ep.EpisodeTypeEnum && epNum >= xref.StartEpisodeNumber && epNum <= GetUpperEpisodeLimit(crossRefs, xref)) { malID = xref.MALID; epNumber = epNum - xref.StartEpisodeNumber + 1; // find the total episode count if (totalEpCount < 0) { if (ep.EpisodeTypeEnum == AniDBAPI.enEpisodeType.Episode) { totalEpCount = ser.GetAnime().EpisodeCountNormal; } if (ep.EpisodeTypeEnum == AniDBAPI.enEpisodeType.Special) { totalEpCount = ser.GetAnime().EpisodeCountSpecial; } totalEpCount = totalEpCount - xref.StartEpisodeNumber + 1; } // any episodes here belong to the MAL series // find the latest watched episod enumber AnimeEpisode_User usrRecord = ep.GetUserRecord(user.JMMUserID); if (usrRecord != null && usrRecord.WatchedDate.HasValue && epNum > lastWatchedEpNumber) { lastWatchedEpNumber = epNum; } List <Contract_VideoDetailed> contracts = ep.GetVideoDetailedContracts(user.JMMUserID); // find the latest episode number in the collection if (contracts.Count > 0) { downloadedEps++; } foreach (Contract_VideoDetailed contract in contracts) { if (!string.IsNullOrEmpty(contract.AniDB_Anime_GroupNameShort) && !fanSubGroups.Contains(contract.AniDB_Anime_GroupNameShort)) { fanSubGroups.Add(contract.AniDB_Anime_GroupNameShort); } } } } string fanSubs = ""; foreach (string fgrp in fanSubGroups) { if (!string.IsNullOrEmpty(fanSubs)) { fanSubs += ","; } fanSubs += fgrp; } // determine status int status = 1; //watching if (animeListHashtable.ContainsKey(malID)) { myanimelistAnime animeInList = (myanimelistAnime)animeListHashtable[malID]; status = animeInList.my_status; } // over-ride is user has watched an episode // don't override on hold (3) or dropped (4) but do override plan to watch (6) if (status == 6 && lastWatchedEpNumber > 0) { status = 1; //watching } if (lastWatchedEpNumber == totalEpCount) { status = 2; //completed } if (lastWatchedEpNumber > totalEpCount) { logger.Error("updateMAL, episode number > matching anime episode total : {0} ({1}) / {2}", ser.GetAnime().GetFormattedTitle(), ser.GetAnime().AnimeID, epNumber); continue; } if (malID <= 0 || totalEpCount <= 0) { logger.Warn("Could not find MAL link for : {0} ({1})", ser.GetAnime().GetFormattedTitle(), ser.GetAnime().AnimeID); continue; } string confirmationMessage = ""; if (animeListHashtable.ContainsKey(malID)) { ModifyAnime(malID, lastWatchedEpNumber, status, score, downloadedEps, fanSubs); confirmationMessage = string.Format("MAL successfully updated (MAL MODIFY), mal id: {0}, ep: {1}, score: {2}", malID, lastWatchedEpNumber, score); } else { AddAnime(malID, lastWatchedEpNumber, status, score, downloadedEps, fanSubs); confirmationMessage = string.Format("MAL successfully updated (MAL ADD), mal id: {0}, ep: {1}, score: {2}", malID, lastWatchedEpNumber, score); } logger.Trace(confirmationMessage); } } catch (Exception ex) { logger.Error(ex, ex.ToString()); } }
private static void PopulateVideoEpisodeFromAnimeEpisode(Video v, AnimeEpisode ep, int userid) { AniDB_Episode aep = ep.AniDB_Episode; if (aep != null) { v.JMMEpisodeId = ep.AnimeEpisodeID; v.EpNumber = aep.EpisodeNumber; v.Index = aep.EpisodeNumber.ToString(); v.Title = aep.EnglishName; v.OriginalTitle = aep.RomajiName; v.Rating = (Convert.ToDouble(aep.Rating)).ToString(CultureInfo.InvariantCulture); v.Votes = aep.Votes; if (aep.AirDateAsDate.HasValue) { v.Year = aep.AirDateAsDate.Value.Year.ToString(); v.OriginallyAvailableAt = aep.AirDateAsDate.Value.Year.ToString("0000") + "-" + aep.AirDateAsDate.Value.Month.ToString("00") + "-" + aep.AirDateAsDate.Value.Day.ToString("00"); } AnimeEpisode_User epuser = ep.GetUserRecord(userid); if (epuser != null) { v.ViewCount = epuser.WatchedCount.ToString(); } MetroContract_Anime_Episode contract = new MetroContract_Anime_Episode(); JMMServiceImplementationMetro.SetTvDBInfo(aep.AnimeID, aep, ref contract); if (contract.ImageID != 0) { v.Thumb = ServerUrl(int.Parse(ServerSettings.JMMServerPort), MainWindow.PathAddressREST + "/GetImage/" + contract.ImageType + "/" + contract.ImageID); } else { v.Thumb = ServerUrl(int.Parse(ServerSettings.JMMServerPort), MainWindow.PathAddressKodi + "/GetSupportImage/plex_404.png"); } v.Summary = contract.EpisodeOverview; //community support //CrossRef_AniDB_TraktV2Repository repCrossRef = new CrossRef_AniDB_TraktV2Repository(); //List<CrossRef_AniDB_TraktV2> Trakt = repCrossRef.GetByAnimeID(aep.AnimeID); //if (Trakt != null) //{ // if (Trakt.Count > 0) // { // v.Trakt = Trakt[0].TraktID; // } //} //CrossRef_AniDB_TvDBV2Repository repCrossRefV2 = new CrossRef_AniDB_TvDBV2Repository(); //List<CrossRef_AniDB_TvDBV2> TvDB = repCrossRefV2.GetByAnimeID(aep.AnimeID); //if (TvDB != null) //{ // if (TvDB.Count > 0) // { // v.TvDB = TvDB[0].TvDBID.ToString(); // } //} //community support END } }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_AddFileToMyList: {0}", Hash); try { vid = RepoFactory.VideoLocal.GetByHash(this.Hash); List <AnimeEpisode> animeEpisodes = new List <AnimeEpisode>(); if (vid != null) { animeEpisodes = vid.GetAnimeEpisodes(); } if (vid != null) { // when adding a file via the API, newWatchedStatus will return with current watched status on AniDB // if the file is already on the user's list bool isManualLink = false; List <CrossRef_File_Episode> xrefs = vid.EpisodeCrossRefs; if (xrefs.Count > 0) { isManualLink = xrefs[0].CrossRefSource != (int)CrossRefSource.AniDB; } // mark the video file as watched DateTime?watchedDate = null; bool newWatchedStatus = false; if (isManualLink) { newWatchedStatus = JMMService.AnidbProcessor.AddFileToMyList(xrefs[0].AnimeID, xrefs[0].Episode.EpisodeNumber, ref watchedDate); } else { newWatchedStatus = JMMService.AnidbProcessor.AddFileToMyList(vid, ref watchedDate); } // do for all AniDB users List <JMMUser> aniDBUsers = RepoFactory.JMMUser.GetAniDBUsers(); if (aniDBUsers.Count > 0) { JMMUser juser = aniDBUsers[0]; vid.ToggleWatchedStatus(newWatchedStatus, false, watchedDate, false, false, juser.JMMUserID, false, true); logger.Info("Adding file to list: {0} - {1}", vid.ToString(), watchedDate); // if the the episode is watched we may want to set the file to watched as well if (ServerSettings.Import_UseExistingFileWatchedStatus && !newWatchedStatus) { if (animeEpisodes.Count > 0) { AnimeEpisode ep = animeEpisodes[0]; AnimeEpisode_User epUser = null; foreach (JMMUser tempuser in aniDBUsers) { // only find the first user who watched this if (epUser == null) { epUser = ep.GetUserRecord(tempuser.JMMUserID); } } if (epUser != null) { logger.Info( "Setting file as watched, because episode was already watched: {0} - user: {1}", vid.ToString(), juser.Username); vid.ToggleWatchedStatus(true, true, epUser.WatchedDate, false, false, epUser.JMMUserID, false, true); } } } } AnimeSeries ser = animeEpisodes[0].GetAnimeSeries(); // all the eps should belong to the same anime ser.QueueUpdateStats(); //StatsCache.Instance.UpdateUsingSeries(ser.AnimeSeriesID); // lets also try adding to the users trakt collecion if (ser != null && ServerSettings.Trakt_IsEnabled && !string.IsNullOrEmpty(ServerSettings.Trakt_AuthToken)) { foreach (AnimeEpisode aep in animeEpisodes) { CommandRequest_TraktCollectionEpisode cmdSyncTrakt = new CommandRequest_TraktCollectionEpisode ( aep.AnimeEpisodeID, TraktSyncAction.Add); cmdSyncTrakt.Save(); } } // sync the series on MAL if (ser != null && !string.IsNullOrEmpty(ServerSettings.MAL_Username) && !string.IsNullOrEmpty(ServerSettings.MAL_Password)) { CommandRequest_MALUpdatedWatchedStatus cmdMAL = new CommandRequest_MALUpdatedWatchedStatus(ser.AniDB_ID); cmdMAL.Save(); } } } catch (Exception ex) { logger.Error("Error processing CommandRequest_AddFileToMyList: {0} - {1}", Hash, ex.ToString()); return; } }