예제 #1
0
        public ActionResult LinkSingleEpisodeToFile([FromRoute] int fileID, [FromBody] File.Input.LinkEpisodesBody body)
        {
            var file = RepoFactory.VideoLocal.GetByID(fileID);

            if (file == null)
            {
                return(NotFound(FileNotFoundWithFileID));
            }

            if (RemoveXRefsForFile(file))
            {
                return(BadRequest($"Cannot remove associations created from AniDB data for file '{file.VideoLocalID}'"));
            }

            foreach (var episodeID in body.episodeIDs)
            {
                var episode = RepoFactory.AnimeEpisode.GetByID(episodeID);
                if (episode == null)
                {
                    return(BadRequest("Could not find episode entry"));
                }

                var command = new CommandRequest_LinkFileManually(fileID, episode.AnimeEpisodeID);
                command.Save();
            }

            return(Ok());
        }
예제 #2
0
        public ActionResult LinkMultipleFiles([FromBody] File.Input.LinkMultipleFilesBody body)
        {
            if (body.fileIDs.Length == 0)
            {
                return(BadRequest("`fileIDs` must contain at least one element."));
            }

            // Validate all the file ids.
            var files = new List <SVR_VideoLocal>(body.fileIDs.Length);

            for (int index = 0, fileID = body.fileIDs[0]; index < body.fileIDs.Length; fileID = body.fileIDs[++index])
            {
                var file = RepoFactory.VideoLocal.GetByID(fileID);
                if (file == null)
                {
                    return(BadRequest($"Unable to find file entry for `fileIDs[{index}]`."));
                }

                files[index] = file;
            }

            var episode = RepoFactory.AnimeEpisode.GetByID(body.episodeID);

            if (episode == null)
            {
                return(BadRequest("Unable to find episode entry"));
            }
            var anidbEpisode = episode.AniDB_Episode;

            if (anidbEpisode == null)
            {
                return(InternalError("Could not find the AniDB entry for episode"));
            }

            var fileCount = 1;

            foreach (var file in files)
            {
                var command = new CommandRequest_LinkFileManually(file.VideoLocalID, episode.AnimeEpisodeID);
                command.Percentage = (int)Math.Round((double)(fileCount / files.Count * 100));

                if (RemoveXRefsForFile(file))
                {
                    return(BadRequest($"Cannot remove associations created from AniDB data for file '{file.VideoLocalID}'"));
                }

                fileCount++;
                command.Save();
            }

            return(Ok());
        }
예제 #3
0
        // List of priorities for commands
        // Order is as such:
        //    Get Max Priority
        //    Get/Update
        //    Set Internal
        //    Recalculate Internal (stats, contracts, etc)
        //    Sync External
        //    Set External
        //
        // Pri 1
        //------
        // Reserved for commands user manually initiates from UI
        //------
        // Pri 2
        //------
        // CommandRequest_GetAnimeHTTP
        //------
        // Pri 3
        //------
        // CommandRequest_ProcessFile
        // CommandRequest_GetFile
        // CommandRequest_LinkFileManually
        //------
        // Pri 4
        //------
        // CommandRequest_GetUpdated
        // CommandRequest_GetEpsode
        //------
        // Pri 5
        //------
        // CommandRequest_GetCalendar
        // CommandRequest_GetReleaseGroup
        // CommandRequest_GetReleaseGroupStatus
        // CommandRequest_GetReviews
        // CommandRequest_LinkAniDBTvDB
        //------
        // Pri 6
        //------
        // CommandRequest_AddFileToMyList #This also updates watched state from AniDB, so it has priority
        // CommandRequest_GetMyListFileStatus
        // CommandRequest_MALDownloadStatusFromMAL
        // CommandRequest_MALSearchAnime
        // CommandRequest_MALUpdatedWatchedStatus
        // CommandRequest_MovieDBSearchAnime
        // CommandRequest_TraktSearchAnime
        // CommandRequest_TraktUpdateAllSeries
        // CommandRequest_TraktUpdateInfo
        // CommandRequest_TvDBSearchAnime
        // CommandRequest_TvDBUpdateEpisodes
        // CommandRequest_TvDBUpdateSeries
        // CommandRequest_UpdateMyListFileStatus
        // CommandRequest_VoteAnime
        //------
        // Pri 7
        //------
        // CommandRequest_PlexSyncWatched
        // CommandRequest_SyncMyList
        // CommandRequest_SyncMyVotes
        // CommandRequest_TraktShowEpisodeUnseen
        // CommandRequest_TraktSyncCollection
        // CommandRequest_TraktSyncCollectionSeries
        // CommandRequest_UpdateMylistStats
        //------
        // Pri 8
        //------
        // CommandRequest_RefreshAnime
        //------
        // Pri 9
        //------
        // CommandRequest_RefreshGroupFilter
        //------
        // Pri 10
        //------
        // CommandRequest_Azure_SendAnimeFull
        // CommandRequest_Azure_SendAnimeTitle
        // CommandRequest_Azure_SendAnimeXML
        // CommandRequest_DeleteFileFromMyList
        // CommandRequest_MALUploadStatusToMAL
        // CommandRequest_WebCacheDeleteXRefAniDBOther
        // CommandRequest_WebCacheDeleteXRefAniDBTrakt
        // CommandRequest_WebCacheDeleteXRefAniDBTvDB
        // CommandRequest_WebCacheDeleteXRefAniDBTvDBAll
        // CommandRequest_WebCacheDeleteXRefFileEpisode
        // CommandRequest_WebCacheSendAniDB_File
        // CommandRequest_WebCacheSendFileHash
        // CommandRequest_WebCacheSendXRefAniDBOther
        // CommandRequest_WebCacheSendXRefAniDBTrakt
        // CommandRequest_WebCacheSendXRefAniDBTvDB
        // CommandRequest_WebCacheSendXRefFileEpisode
        //------
        // Pri 11
        //------

        public static CommandRequest GetCommand(CommandRequest crdb)
        {
            CommandRequestType crt = (CommandRequestType)crdb.CommandType;

            switch (crt)
            {
            case CommandRequestType.AniDB_AddFileUDP:
                CommandRequest_AddFileToMyList cr_af = new CommandRequest_AddFileToMyList();
                cr_af.InitFromDB(crdb);
                return(cr_af);

            case CommandRequestType.AniDB_DeleteFileUDP:
                CommandRequest_DeleteFileFromMyList cr_AniDB_DeleteFileUDP =
                    new CommandRequest_DeleteFileFromMyList();
                cr_AniDB_DeleteFileUDP.InitFromDB(crdb);
                return(cr_AniDB_DeleteFileUDP);

            case CommandRequestType.AniDB_GetAnimeHTTP:
                CommandRequest_GetAnimeHTTP cr_geth = new CommandRequest_GetAnimeHTTP();
                cr_geth.InitFromDB(crdb);
                return(cr_geth);

            case CommandRequestType.AniDB_GetCalendar:
                CommandRequest_GetCalendar cr_GetCalendar = new CommandRequest_GetCalendar();
                cr_GetCalendar.InitFromDB(crdb);
                return(cr_GetCalendar);

            case CommandRequestType.AniDB_GetEpisodeUDP:
                CommandRequest_GetEpisode cr_CommandRequest_GetEpisode = new CommandRequest_GetEpisode();
                cr_CommandRequest_GetEpisode.InitFromDB(crdb);
                return(cr_CommandRequest_GetEpisode);

            case CommandRequestType.AniDB_GetFileUDP:
                CommandRequest_GetFile cr_AniDB_GetFileUDP = new CommandRequest_GetFile();
                cr_AniDB_GetFileUDP.InitFromDB(crdb);
                return(cr_AniDB_GetFileUDP);

            case CommandRequestType.AniDB_GetMyListFile:
                CommandRequest_GetFileMyListStatus cr_MyListStatus = new CommandRequest_GetFileMyListStatus();
                cr_MyListStatus.InitFromDB(crdb);
                return(cr_MyListStatus);

            case CommandRequestType.AniDB_GetReleaseGroup:
                CommandRequest_GetReleaseGroup cr_GetReleaseGroup = new CommandRequest_GetReleaseGroup();
                cr_GetReleaseGroup.InitFromDB(crdb);
                return(cr_GetReleaseGroup);

            case CommandRequestType.AniDB_GetReleaseGroupStatus:
                CommandRequest_GetReleaseGroupStatus cr_GetReleaseGroupStatus =
                    new CommandRequest_GetReleaseGroupStatus();
                cr_GetReleaseGroupStatus.InitFromDB(crdb);
                return(cr_GetReleaseGroupStatus);

            case CommandRequestType.AniDB_GetReviews:
                CommandRequest_GetReviews cr_GetReviews = new CommandRequest_GetReviews();
                cr_GetReviews.InitFromDB(crdb);
                return(cr_GetReviews);

            case CommandRequestType.AniDB_GetTitles:
                CommandRequest_GetAniDBTitles cr_CommandRequest_GetAniDBTitles =
                    new CommandRequest_GetAniDBTitles();
                cr_CommandRequest_GetAniDBTitles.InitFromDB(crdb);
                return(cr_CommandRequest_GetAniDBTitles);

            case CommandRequestType.AniDB_GetUpdated:
                CommandRequest_GetUpdated cr_GetUpdated = new CommandRequest_GetUpdated();
                cr_GetUpdated.InitFromDB(crdb);
                return(cr_GetUpdated);

            case CommandRequestType.AniDB_SyncMyList:
                CommandRequest_SyncMyList cr_SyncMyList = new CommandRequest_SyncMyList();
                cr_SyncMyList.InitFromDB(crdb);
                return(cr_SyncMyList);

            case CommandRequestType.AniDB_SyncVotes:
                CommandRequest_SyncMyVotes cr_SyncVotes = new CommandRequest_SyncMyVotes();
                cr_SyncVotes.InitFromDB(crdb);
                return(cr_SyncVotes);

            case CommandRequestType.AniDB_UpdateMylistStats:
                CommandRequest_UpdateMyListStats crAniDbUpdateMyListStats =
                    new CommandRequest_UpdateMyListStats();
                crAniDbUpdateMyListStats.InitFromDB(crdb);
                return(crAniDbUpdateMyListStats);

            case CommandRequestType.AniDB_UpdateWatchedUDP:
                CommandRequest_UpdateMyListFileStatus cr_umlf = new CommandRequest_UpdateMyListFileStatus();
                cr_umlf.InitFromDB(crdb);
                return(cr_umlf);

            case CommandRequestType.AniDB_VoteAnime:
                CommandRequest_VoteAnime cr_VoteAnime = new CommandRequest_VoteAnime();
                cr_VoteAnime.InitFromDB(crdb);
                return(cr_VoteAnime);

            case CommandRequestType.Azure_SendAnimeFull:
                CommandRequest_Azure_SendAnimeFull cr_CommandRequest_Azure_SendAnimeFull =
                    new CommandRequest_Azure_SendAnimeFull();
                cr_CommandRequest_Azure_SendAnimeFull.InitFromDB(crdb);
                return(cr_CommandRequest_Azure_SendAnimeFull);

            case CommandRequestType.Azure_SendAnimeTitle:
                CommandRequest_Azure_SendAnimeTitle cr_CommandRequest_Azure_SendAnimeTitle =
                    new CommandRequest_Azure_SendAnimeTitle();
                cr_CommandRequest_Azure_SendAnimeTitle.InitFromDB(crdb);
                return(cr_CommandRequest_Azure_SendAnimeTitle);

            case CommandRequestType.Azure_SendAnimeXML:
                CommandRequest_Azure_SendAnimeXML cr_CommandRequest_Azure_SendAnimeXML =
                    new CommandRequest_Azure_SendAnimeXML();
                cr_CommandRequest_Azure_SendAnimeXML.InitFromDB(crdb);
                return(cr_CommandRequest_Azure_SendAnimeXML);

            case CommandRequestType.Azure_SendUserInfo:
                CommandRequest_Azure_SendUserInfo cr_CommandRequest_Azure_SendUserInfo =
                    new CommandRequest_Azure_SendUserInfo();
                cr_CommandRequest_Azure_SendUserInfo.InitFromDB(crdb);
                return(cr_CommandRequest_Azure_SendUserInfo);

            case CommandRequestType.HashFile:
                CommandRequest_HashFile cr_HashFile = new CommandRequest_HashFile();
                cr_HashFile.InitFromDB(crdb);
                return(cr_HashFile);

            case CommandRequestType.ImageDownload:
                CommandRequest_DownloadImage cr_ImageDownload = new CommandRequest_DownloadImage();
                cr_ImageDownload.InitFromDB(crdb);
                return(cr_ImageDownload);

            case CommandRequestType.LinkAniDBTvDB:
                CommandRequest_LinkAniDBTvDB cr_linkAniDBTvDB = new CommandRequest_LinkAniDBTvDB();
                cr_linkAniDBTvDB.InitFromDB(crdb);
                return(cr_linkAniDBTvDB);

            case CommandRequestType.LinkFileManually:
                CommandRequest_LinkFileManually cr_LinkFile = new CommandRequest_LinkFileManually();
                cr_LinkFile.InitFromDB(crdb);
                return(cr_LinkFile);

            case CommandRequestType.MAL_DownloadWatchedStates:
                CommandRequest_MALDownloadStatusFromMAL cr_MAL_DownloadWatchedStates =
                    new CommandRequest_MALDownloadStatusFromMAL();
                cr_MAL_DownloadWatchedStates.InitFromDB(crdb);
                return(cr_MAL_DownloadWatchedStates);

            case CommandRequestType.MAL_SearchAnime:
                CommandRequest_MALSearchAnime cr_MAL_SearchAnime = new CommandRequest_MALSearchAnime();
                cr_MAL_SearchAnime.InitFromDB(crdb);
                return(cr_MAL_SearchAnime);

            case CommandRequestType.MAL_UpdateStatus:
                CommandRequest_MALUpdatedWatchedStatus cr_MAL_UpdateStatus =
                    new CommandRequest_MALUpdatedWatchedStatus();
                cr_MAL_UpdateStatus.InitFromDB(crdb);
                return(cr_MAL_UpdateStatus);

            case CommandRequestType.MAL_UploadWatchedStates:
                CommandRequest_MALUploadStatusToMAL cr_MAL_UploadWatchedStates =
                    new CommandRequest_MALUploadStatusToMAL();
                cr_MAL_UploadWatchedStates.InitFromDB(crdb);
                return(cr_MAL_UploadWatchedStates);

            case CommandRequestType.MovieDB_SearchAnime:
                CommandRequest_MovieDBSearchAnime cr_MovieDB_SearchAnime = new CommandRequest_MovieDBSearchAnime();
                cr_MovieDB_SearchAnime.InitFromDB(crdb);
                return(cr_MovieDB_SearchAnime);

            case CommandRequestType.Plex_Sync:
                CommandRequest_PlexSyncWatched cr_PlexSync = new CommandRequest_PlexSyncWatched();
                cr_PlexSync.InitFromDB(crdb);
                return(cr_PlexSync);

            case CommandRequestType.ProcessFile:
                CommandRequest_ProcessFile cr_pf = new CommandRequest_ProcessFile();
                cr_pf.InitFromDB(crdb);
                return(cr_pf);

            case CommandRequestType.ReadMediaInfo:
                CommandRequest_ReadMediaInfo cr_ReadMediaInfo = new CommandRequest_ReadMediaInfo();
                cr_ReadMediaInfo.InitFromDB(crdb);
                return(cr_ReadMediaInfo);

            case CommandRequestType.Refresh_AnimeStats:
                CommandRequest_RefreshAnime cr_refreshAnime = new CommandRequest_RefreshAnime();
                cr_refreshAnime.InitFromDB(crdb);
                return(cr_refreshAnime);

            case CommandRequestType.Refresh_GroupFilter:
                CommandRequest_RefreshGroupFilter cr_refreshGroupFilter = new CommandRequest_RefreshGroupFilter();
                cr_refreshGroupFilter.InitFromDB(crdb);
                return(cr_refreshGroupFilter);

            case CommandRequestType.Trakt_EpisodeCollection:
                CommandRequest_TraktCollectionEpisode cr_TraktCollectionEpisode =
                    new CommandRequest_TraktCollectionEpisode();
                cr_TraktCollectionEpisode.InitFromDB(crdb);
                return(cr_TraktCollectionEpisode);

            case CommandRequestType.Trakt_EpisodeHistory:
                CommandRequest_TraktHistoryEpisode cr_Trakt_EpisodeHistory =
                    new CommandRequest_TraktHistoryEpisode();
                cr_Trakt_EpisodeHistory.InitFromDB(crdb);
                return(cr_Trakt_EpisodeHistory);

            case CommandRequestType.Trakt_SearchAnime:
                CommandRequest_TraktSearchAnime cr_Trakt_SearchAnime = new CommandRequest_TraktSearchAnime();
                cr_Trakt_SearchAnime.InitFromDB(crdb);
                return(cr_Trakt_SearchAnime);

            case CommandRequestType.Trakt_SyncCollection:
                CommandRequest_TraktSyncCollection cr_Trakt_SyncCollection =
                    new CommandRequest_TraktSyncCollection();
                cr_Trakt_SyncCollection.InitFromDB(crdb);
                return(cr_Trakt_SyncCollection);

            case CommandRequestType.Trakt_SyncCollectionSeries:
                CommandRequest_TraktSyncCollectionSeries cr_CommandRequest_TraktSyncCollectionSeries =
                    new CommandRequest_TraktSyncCollectionSeries();
                cr_CommandRequest_TraktSyncCollectionSeries.InitFromDB(crdb);
                return(cr_CommandRequest_TraktSyncCollectionSeries);


            case CommandRequestType.Trakt_UpdateAllSeries:
                CommandRequest_TraktUpdateAllSeries cr_Trakt_UpdateAllSeries =
                    new CommandRequest_TraktUpdateAllSeries();
                cr_Trakt_UpdateAllSeries.InitFromDB(crdb);
                return(cr_Trakt_UpdateAllSeries);

            case CommandRequestType.Trakt_UpdateInfo:
                CommandRequest_TraktUpdateInfo cr_Trakt_UpdateInfoImages =
                    new CommandRequest_TraktUpdateInfo();
                cr_Trakt_UpdateInfoImages.InitFromDB(crdb);
                return(cr_Trakt_UpdateInfoImages);

            case CommandRequestType.TvDB_DownloadImages:
                CommandRequest_TvDBDownloadImages cr_TvDB_DownloadImages = new CommandRequest_TvDBDownloadImages();
                cr_TvDB_DownloadImages.InitFromDB(crdb);
                return(cr_TvDB_DownloadImages);

            case CommandRequestType.TvDB_SearchAnime:
                CommandRequest_TvDBSearchAnime cr_TvDB_SearchAnime = new CommandRequest_TvDBSearchAnime();
                cr_TvDB_SearchAnime.InitFromDB(crdb);
                return(cr_TvDB_SearchAnime);

            case CommandRequestType.TvDB_UpdateEpisode:
                CommandRequest_TvDBUpdateEpisode cr_TvDB_Episode =
                    new CommandRequest_TvDBUpdateEpisode();
                cr_TvDB_Episode.InitFromDB(crdb);
                return(cr_TvDB_Episode);

            case CommandRequestType.TvDB_UpdateSeries:
                CommandRequest_TvDBUpdateSeries cr_TvDB_Episodes =
                    new CommandRequest_TvDBUpdateSeries();
                cr_TvDB_Episodes.InitFromDB(crdb);
                return(cr_TvDB_Episodes);

            case CommandRequestType.ValidateAllImages:
                CommandRequest_ValidateAllImages cr_ValidateImages = new CommandRequest_ValidateAllImages();
                cr_ValidateImages.InitFromDB(crdb);
                return(cr_ValidateImages);

            case CommandRequestType.WebCache_DeleteXRefAniDBMAL:
                CommandRequest_WebCacheDeleteXRefAniDBMAL cr_WebCacheDeleteXRefAniDBMAL =
                    new CommandRequest_WebCacheDeleteXRefAniDBMAL();
                cr_WebCacheDeleteXRefAniDBMAL.InitFromDB(crdb);
                return(cr_WebCacheDeleteXRefAniDBMAL);

            case CommandRequestType.WebCache_DeleteXRefAniDBOther:
                CommandRequest_WebCacheDeleteXRefAniDBOther cr_SendXRefAniDBOther =
                    new CommandRequest_WebCacheDeleteXRefAniDBOther();
                cr_SendXRefAniDBOther.InitFromDB(crdb);
                return(cr_SendXRefAniDBOther);

            case CommandRequestType.WebCache_DeleteXRefAniDBTrakt:
                CommandRequest_WebCacheDeleteXRefAniDBTrakt cr_WebCache_DeleteXRefAniDBTrakt =
                    new CommandRequest_WebCacheDeleteXRefAniDBTrakt();
                cr_WebCache_DeleteXRefAniDBTrakt.InitFromDB(crdb);
                return(cr_WebCache_DeleteXRefAniDBTrakt);

            case CommandRequestType.WebCache_DeleteXRefAniDBTvDB:
                CommandRequest_WebCacheDeleteXRefAniDBTvDB cr_DeleteXRefAniDBTvDB =
                    new CommandRequest_WebCacheDeleteXRefAniDBTvDB();
                cr_DeleteXRefAniDBTvDB.InitFromDB(crdb);
                return(cr_DeleteXRefAniDBTvDB);

            case CommandRequestType.WebCache_DeleteXRefFileEpisode:
                CommandRequest_WebCacheDeleteXRefFileEpisode cr_DeleteXRefFileEpisode =
                    new CommandRequest_WebCacheDeleteXRefFileEpisode();
                cr_DeleteXRefFileEpisode.InitFromDB(crdb);
                return(cr_DeleteXRefFileEpisode);

            case CommandRequestType.WebCache_SendXRefAniDBMAL:
                CommandRequest_WebCacheSendXRefAniDBMAL cr_WebCacheSendXRefAniDBMAL =
                    new CommandRequest_WebCacheSendXRefAniDBMAL();
                cr_WebCacheSendXRefAniDBMAL.InitFromDB(crdb);
                return(cr_WebCacheSendXRefAniDBMAL);

            case CommandRequestType.WebCache_SendXRefAniDBOther:
                CommandRequest_WebCacheSendXRefAniDBOther cr_WebCacheSendXRefAniDBOther =
                    new CommandRequest_WebCacheSendXRefAniDBOther();
                cr_WebCacheSendXRefAniDBOther.InitFromDB(crdb);
                return(cr_WebCacheSendXRefAniDBOther);

            case CommandRequestType.WebCache_SendXRefAniDBTrakt:
                CommandRequest_WebCacheSendXRefAniDBTrakt cr_WebCache_SendXRefAniDBTrakt =
                    new CommandRequest_WebCacheSendXRefAniDBTrakt();
                cr_WebCache_SendXRefAniDBTrakt.InitFromDB(crdb);
                return(cr_WebCache_SendXRefAniDBTrakt);

            case CommandRequestType.WebCache_SendXRefAniDBTvDB:
                CommandRequest_WebCacheSendXRefAniDBTvDB cr_SendXRefAniDBTvDB =
                    new CommandRequest_WebCacheSendXRefAniDBTvDB();
                cr_SendXRefAniDBTvDB.InitFromDB(crdb);
                return(cr_SendXRefAniDBTvDB);

            case CommandRequestType.WebCache_SendXRefFileEpisode:
                CommandRequest_WebCacheSendXRefFileEpisode cr_SendXRefFileEpisode =
                    new CommandRequest_WebCacheSendXRefFileEpisode();
                cr_SendXRefFileEpisode.InitFromDB(crdb);
                return(cr_SendXRefFileEpisode);
            }

            return(null);
        }
예제 #4
0
        public ActionResult LinkMultipleFiles([FromBody] File.Input.LinkSeriesMultipleBody body)
        {
            if (body.fileIDs.Length == 0)
            {
                return(BadRequest("`fileIDs` must contain at least one element."));
            }

            // Validate all the file ids.
            var files = new List <SVR_VideoLocal>(body.fileIDs.Length);

            for (int index = 0, fileID = body.fileIDs[0]; index < body.fileIDs.Length; fileID = body.fileIDs[++index])
            {
                var file = RepoFactory.VideoLocal.GetByID(fileID);
                if (file == null)
                {
                    return(BadRequest($"Unable to find file entry for `fileIDs[{index}]`."));
                }

                files[index] = file;
            }

            var series = RepoFactory.AnimeSeries.GetByID(body.seriesID);

            if (series == null)
            {
                return(BadRequest("Unable to find series entry"));
            }

            var episodeType = EpisodeType.Episode;

            var(rangeStart, startType, startErrorMessage) = Helpers.ModelHelper.GetEpisodeNumberAndTypeFromInput(body.rangeStart);
            if (!string.IsNullOrEmpty(startErrorMessage))
            {
                return(BadRequest(string.Format(startErrorMessage, "rangeStart")));
            }

            // Set the episode type if it was included in the input.
            if (startType.HasValue)
            {
                episodeType = startType.Value;
            }

            // Validate the range.
            var rangeEnd      = rangeStart + files.Count - 1;
            var totalEpisodes = Helpers.ModelHelper.GetTotalEpisodesForType(series.GetAnimeEpisodes(), episodeType);

            if (rangeStart < 1)
            {
                return(BadRequest("`rangeStart` cannot be lower than 1"));
            }
            if (rangeStart > totalEpisodes)
            {
                return(BadRequest("`rangeStart` cannot be higher than the total number of episodes for the selected type."));
            }
            if (rangeEnd < rangeStart)
            {
                return(BadRequest("`rangeEnd`cannot be lower than `rangeStart`."));
            }
            if (rangeEnd > totalEpisodes)
            {
                return(BadRequest("`rangeEnd` cannot be higher than the total number of episodes for the selected type."));
            }

            var fileCount     = 1;
            var singleEpisode = body.singleEpisode;
            var episodeNumber = rangeStart;

            foreach (var file in files)
            {
                var anidbEpisode = RepoFactory.AniDB_Episode.GetByAnimeIDAndEpisodeTypeNumber(series.AniDB_ID, episodeType, episodeNumber)[0];
                if (anidbEpisode == null)
                {
                    return(InternalError("Could not find the AniDB entry for episode"));
                }

                var episode = RepoFactory.AnimeEpisode.GetByAniDBEpisodeID(anidbEpisode.EpisodeID);
                if (episode == null)
                {
                    return(InternalError("Could not find episode entry"));
                }

                var command = new CommandRequest_LinkFileManually(file.VideoLocalID, episode.AnimeEpisodeID);
                if (singleEpisode)
                {
                    command.Percentage = (int)Math.Round((double)(fileCount / files.Count * 100));
                }
                else
                {
                    episodeNumber++;
                }

                if (RemoveXRefsForFile(file))
                {
                    return(BadRequest($"Cannot remove associations created from AniDB data for file '{file.VideoLocalID}'"));
                }

                fileCount++;
                command.Save();
            }

            return(Ok());
        }
예제 #5
0
        public ActionResult LinkMultipleEpisodesToFile([FromRoute] int fileID, [FromBody] File.Input.LinkSeriesBody body)
        {
            var file = RepoFactory.VideoLocal.GetByID(fileID);

            if (file == null)
            {
                return(NotFound(FileNotFoundWithFileID));
            }

            var series = RepoFactory.AnimeSeries.GetByID(body.seriesID);

            if (series == null)
            {
                return(BadRequest("Unable to find series entry"));
            }

            var episodeType = EpisodeType.Episode;

            var(rangeStart, startType, startErrorMessage) = Helpers.ModelHelper.GetEpisodeNumberAndTypeFromInput(body.rangeStart);
            if (!string.IsNullOrEmpty(startErrorMessage))
            {
                return(BadRequest(string.Format(startErrorMessage, "rangeStart")));
            }

            var(rangeEnd, endType, endErrorMessage) = Helpers.ModelHelper.GetEpisodeNumberAndTypeFromInput(body.rangeEnd);
            if (!string.IsNullOrEmpty(endErrorMessage))
            {
                return(BadRequest(string.Format(endErrorMessage, "rangeEnd")));
            }

            if (startType != endType)
            {
                return(BadRequest("Unable to use different episode types in the `rangeStart` and `rangeEnd`."));
            }

            // Set the episode type if it was included in the input.
            if (startType.HasValue)
            {
                episodeType = startType.Value;
            }

            // Validate the range.
            var totalEpisodes = Helpers.ModelHelper.GetTotalEpisodesForType(series.GetAnimeEpisodes(), episodeType);

            if (rangeStart < 1)
            {
                return(BadRequest("`rangeStart` cannot be lower than 1"));
            }
            if (rangeStart > totalEpisodes)
            {
                return(BadRequest("`rangeStart` cannot be higher than the total number of episodes for the selected type."));
            }
            if (rangeEnd < rangeStart)
            {
                return(BadRequest("`rangeEnd`cannot be lower than `rangeStart`."));
            }
            if (rangeEnd > totalEpisodes)
            {
                return(BadRequest("`rangeEnd` cannot be higher than the total number of episodes for the selected type."));
            }

            if (RemoveXRefsForFile(file))
            {
                return(BadRequest($"Cannot remove associations created from AniDB data for file '{file.VideoLocalID}'"));
            }

            for (int episodeNumber = rangeStart; episodeNumber <= rangeEnd; episodeNumber++)
            {
                var anidbEpisode = RepoFactory.AniDB_Episode.GetByAnimeIDAndEpisodeTypeNumber(series.AniDB_ID, episodeType, episodeNumber)[0];
                if (anidbEpisode == null)
                {
                    return(InternalError("Could not find the AniDB entry for episode"));
                }

                var episode = RepoFactory.AnimeEpisode.GetByAniDBEpisodeID(anidbEpisode.EpisodeID);
                if (episode == null)
                {
                    return(InternalError("Could not find episode entry"));
                }

                var command = new CommandRequest_LinkFileManually(fileID, episode.AnimeEpisodeID);
                command.Save();
            }

            return(Ok());
        }