public string AssociateMultipleFiles(List<int> videoLocalIDs, int animeSeriesID, int startingEpisodeNumber, bool singleEpisode) { try { CrossRef_File_EpisodeRepository repXRefs = new CrossRef_File_EpisodeRepository(); AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); VideoLocalRepository repVids = new VideoLocalRepository(); AniDB_EpisodeRepository repAniEps = new AniDB_EpisodeRepository(); AnimeEpisodeRepository repEps = new AnimeEpisodeRepository(); AnimeSeries ser = repSeries.GetByID(animeSeriesID); if (ser == null) return "Could not find anime series record"; int epNumber = startingEpisodeNumber; int count = 1; foreach (int videoLocalID in videoLocalIDs) { VideoLocal vid = repVids.GetByID(videoLocalID); if (vid == null) return "Could not find video local record"; List<AniDB_Episode> anieps = repAniEps.GetByAnimeIDAndEpisodeNumber(ser.AniDB_ID, epNumber); if (anieps.Count == 0) return "Could not find the AniDB episode record"; AniDB_Episode aniep = anieps[0]; List<AnimeEpisode> eps = repEps.GetByAniEpisodeIDAndSeriesID(aniep.EpisodeID, ser.AnimeSeriesID); if (eps.Count == 0) return "Could not find episode record"; AnimeEpisode ep = eps[0]; CrossRef_File_Episode xref = new CrossRef_File_Episode(); xref.PopulateManually(vid, ep); // TODO do this properly if (singleEpisode) { xref.EpisodeOrder = count; if (videoLocalIDs.Count > 5) xref.Percentage = 100; else xref.Percentage = GetEpisodePercentages(videoLocalIDs.Count)[count - 1]; } repXRefs.Save(xref); vid.RenameIfRequired(); vid.MoveFileIfRequired(); CommandRequest_WebCacheSendXRefFileEpisode cr = new CommandRequest_WebCacheSendXRefFileEpisode(xref.CrossRef_File_EpisodeID); cr.Save(); count++; if (!singleEpisode) epNumber++; } ser.QueueUpdateStats(); // update epidsode added stats ser.EpisodeAddedDate = DateTime.Now; repSeries.Save(ser); AnimeGroupRepository repGroups = new AnimeGroupRepository(); foreach (AnimeGroup grp in ser.AllGroupsAbove) { grp.EpisodeAddedDate = DateTime.Now; repGroups.Save(grp); } } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); } return ""; }
public string AssociateSingleFileWithMultipleEpisodes(int videoLocalID, int animeSeriesID, int startEpNum, int endEpNum) { try { VideoLocalRepository repVids = new VideoLocalRepository(); VideoLocal vid = repVids.GetByID(videoLocalID); if (vid == null) return "Could not find video record"; AnimeEpisodeRepository repEps = new AnimeEpisodeRepository(); AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); AniDB_EpisodeRepository repAniEps = new AniDB_EpisodeRepository(); CrossRef_File_EpisodeRepository repXRefs = new CrossRef_File_EpisodeRepository(); AnimeSeries ser = repSeries.GetByID(animeSeriesID); if (ser == null) return "Could not find anime series record"; for (int i = startEpNum; i <= endEpNum; i++) { List<AniDB_Episode> anieps = repAniEps.GetByAnimeIDAndEpisodeNumber(ser.AniDB_ID, i); if (anieps.Count == 0) return "Could not find the AniDB episode record"; AniDB_Episode aniep = anieps[0]; List<AnimeEpisode> eps = repEps.GetByAniEpisodeIDAndSeriesID(aniep.EpisodeID, ser.AnimeSeriesID); if (eps.Count == 0) return "Could not find episode record"; AnimeEpisode ep = eps[0]; CrossRef_File_Episode xref = new CrossRef_File_Episode(); xref.PopulateManually(vid, ep); repXRefs.Save(xref); CommandRequest_WebCacheSendXRefFileEpisode cr = new CommandRequest_WebCacheSendXRefFileEpisode(xref.CrossRef_File_EpisodeID); cr.Save(); } vid.RenameIfRequired(); vid.MoveFileIfRequired(); ser.QueueUpdateStats(); // update epidsode added stats ser.EpisodeAddedDate = DateTime.Now; repSeries.Save(ser); AnimeGroupRepository repGroups = new AnimeGroupRepository(); foreach (AnimeGroup grp in ser.AllGroupsAbove) { grp.EpisodeAddedDate = DateTime.Now; repGroups.Save(grp); } return ""; } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); } return ""; }
public GroupStatusCollection GetReleaseGroupStatusUDP(int animeID) { if (!Login()) return null; enHelperActivityType ev = enHelperActivityType.NoSuchCreator; AniDBCommand_GetGroupStatus getCmd = null; lock (lockAniDBConnections) { Pause(); getCmd = new AniDBCommand_GetGroupStatus(); getCmd.Init(animeID); SetWaitingOnResponse(true); ev = getCmd.Process(ref soUdp, ref remoteIpEndPoint, curSessionID, new UnicodeEncoding(true, false)); SetWaitingOnResponse(false); } if (ev == enHelperActivityType.GotGroupStatus && getCmd.GrpStatusCollection != null) { // delete existing records AniDB_GroupStatusRepository repGrpStat = new AniDB_GroupStatusRepository(); AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AniDB_EpisodeRepository repAniEp = new AniDB_EpisodeRepository(); AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); repGrpStat.DeleteForAnime(animeID); // save the records foreach (Raw_AniDB_GroupStatus raw in getCmd.GrpStatusCollection.Groups) { AniDB_GroupStatus grpstat = new AniDB_GroupStatus(raw); repGrpStat.Save(grpstat); } // updated cached stats // we don't do it in the save method as it would be too many unecessary updates logger.Trace("Updating group stats by anime from GetReleaseGroupStatusUDP: {0}", animeID); StatsCache.Instance.UpdateUsingAnime(animeID); if (getCmd.GrpStatusCollection.LatestEpisodeNumber > 0) { // update the anime with a record of the latest subbed episode AniDB_Anime anime = repAnime.GetByAnimeID(animeID); if (anime != null) { anime.LatestEpisodeNumber = getCmd.GrpStatusCollection.LatestEpisodeNumber; repAnime.Save(anime); // check if we have this episode in the database // if not get it now by updating the anime record List<AniDB_Episode> eps = repAniEp.GetByAnimeIDAndEpisodeNumber(animeID, getCmd.GrpStatusCollection.LatestEpisodeNumber); if (eps.Count == 0) { CommandRequest_GetAnimeHTTP cr_anime = new CommandRequest_GetAnimeHTTP(animeID, true, false); cr_anime.Save(); } // update the missing episode stats on groups and children AnimeSeries series = repSeries.GetByAnimeID(animeID); if (series != null) { series.QueueUpdateStats(); //series.TopLevelAnimeGroup.UpdateStatsFromTopLevel(true, true, true); } } } } return getCmd.GrpStatusCollection; }