Exemple #1
0
        /// <summary>
        /// Get the new path for a specified file.
        /// The target path depends on age restriction and available dubs/subs
        /// </summary>
        /// <param name="args">Arguments for the process, contains FileInfo and more</param>
        public (IImportFolder destination, string subfolder) GetDestination(MoveEventArgs args)
        {
            //get the anime the file in question is linked to
            var anime = args.AnimeInfo.First();

            //get the FileInfo of the file in question
            var video = args.FileInfo;

            //check if the anime in question is restricted to 18+
            bool isPorn = anime.Restricted;

            //instantiate lists for various stream information
            //these include Dub/Sub-Languages as readable by mediainfo
            //as well as Dub/Sub-Languages that AniDB provides for the file, if it is known
            IReadOnlyList <ITextStream>   textStreamsFile     = null;
            IReadOnlyList <IAudioStream>  audioStreamsFile    = null;
            IReadOnlyList <TitleLanguage> textLanguagesAniDB  = null;
            IReadOnlyList <TitleLanguage> audioLanguagesAniDB = null;

            try
            {
                //sub streams as provided by mediainfo
                textStreamsFile = video.MediaInfo.Subs;

                //dub streams as provided by mediainfo
                audioStreamsFile = video.MediaInfo.Audio;

                //sub languages as provided by anidb
                textLanguagesAniDB = video.AniDBFileInfo.MediaInfo.SubLanguages;

                //sub languages as provided by anidb
                audioLanguagesAniDB = video.AniDBFileInfo.MediaInfo.AudioLanguages;
            }
            catch
            {
                // ignored
            }

            //define various bools
            //those will only get set to true if the respective stream in the relevant language is found
            bool isEngDub = false;
            bool isEngSub = false;
            bool isGerDub = false;
            bool isGerSub = false;

            //check if mediainfo provides us with audiostreams. if so, check if the language of any of them matches the desired one.
            //check if anidb provides us with information about the audiostreams. if so, check if the language of any of them matches the desired one.
            //if any of the above is true, set the respective bool to true
            //the same process applies to both dub and sub
            if ((audioStreamsFile != null && audioStreamsFile !.Any(a => a !.LanguageCode?.ToLower() == "ger")) || (audioLanguagesAniDB != null && audioLanguagesAniDB !.Any(a => a == TitleLanguage.German)))
            {
                isGerDub = true;
            }

            if ((textStreamsFile != null && textStreamsFile !.Any(t => t !.LanguageCode?.ToLower() == "ger")) || (textLanguagesAniDB != null && textLanguagesAniDB !.Any(t => t == TitleLanguage.German)))
            {
                isGerSub = true;
            }

            if ((audioStreamsFile != null && audioStreamsFile !.Any(a => a !.LanguageCode?.ToLower() == "eng")) || (audioLanguagesAniDB != null && audioLanguagesAniDB !.Any(a => a == TitleLanguage.English)))
            {
                isGerDub = true;
            }

            if ((textStreamsFile != null && textStreamsFile !.Any(t => t !.LanguageCode?.ToLower() == "eng")) || (textLanguagesAniDB != null && textLanguagesAniDB !.Any(t => t == TitleLanguage.English)))
            {
                isEngSub = true;
            }

            //define location based on the OS shokoserver is currently running on
            var location = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/mnt/array/" : "Z:\\";

            //define the first subfolder depending on age restriction
            location += isPorn ? "Hentai" : "Anime";

            //add a directory separator char. this automatically switches between the proper char for the current OS
            location += Path.DirectorySeparatorChar;

            //a while true loop. be carefull here, since this would always require a default break; otherwise this ever ends
            //used to evaluate the previously set bools and add the 2nd subfolder depending on available dubs/subs
            //if no choice can be made, a fallback folder is used for manual processing
            while (true)
            {
                if (isGerDub)
                {
                    location += "GerDub";
                    break;
                }

                if (isGerSub)
                {
                    location += "GerSub";
                    break;
                }

                if ((isEngDub || isEngSub))
                {
                    location += "Other";
                    break;
                }

                location += "_manual";
                break;
            }

            //add a trailing directory separator char, since the folders in shokoserver are currently forcibly set up with one as well
            location += Path.DirectorySeparatorChar;

            //check if any of the available folders matches the constructed path in location, set it as destination
            var dest = args.AvailableFolders.FirstOrDefault(a => a.Location == location);

            //DestinationPath is the name of the final subfolder containing the episode files. Get it by preferrence
            var destinationPath = GetTitleByPref(anime, TitleType.Official, TitleLanguage.German, TitleLanguage.English, TitleLanguage.Romaji).ReplaceInvalidPathCharacters();

            return(dest, destinationPath);
        }