Esempio n. 1
0
        public static SortFileInfo PopulateFileInfo(this SortFile _sortFile)
        {
            if (!string.IsNullOrEmpty(_sortFile.FilePath))
            {
                var info = new FileInfo(_sortFile.FilePath);

                SortFileInfo _SortInfo = new SortFileInfo
                {
                    CreationTime   = info.CreationTime,
                    Directory      = info.Directory,
                    DirectoryName  = info.DirectoryName,
                    Extension      = info.Extension,
                    FileAttributes = info.Attributes,
                    FullName       = info.FullName,
                    Name           = info.Name,
                    LastWriteTime  = info.LastWriteTime,
                    Length         = info.Length
                };

                return(_SortInfo);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 2
0
        public static TelevisionEpisode GetEpisode(this SortFile _sortFile)
        {
            if (_sortFile != null)
            {
                string patternTV = @"(?<ShowName>.+)[.|\s]+[Ss](?<ShowSeasonNumber>\d?\d)[Ee]?(?<ShowEpisodeNumber>\d?\d)[.|\s]+.*(?<ShowFileExtension>mkv|avi|mp4)";
                Regex  _reg      = new Regex(patternTV);

                var match = Regex.Match(_sortFile.FileName, patternTV);

                TelevisionEpisode _episode = new TelevisionEpisode
                {
                    ShowName      = match.Groups[1].Value.Replace(".", " "),
                    SeasonNumber  = match.Groups[2].Value,
                    EpisodeNumber = match.Groups[3].Value,
                    FileName      = _sortFile.FileName,
                    FilePath      = _sortFile.FilePath,
                    FileSize      = _sortFile.FileSize,
                    PriorityLevel = _sortFile.PriorityLevel
                };

                return(_episode);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 3
0
 private async Task sortMapnumeric(string fileName, string directoryName, int keyColumn = 0)
 {
     // Sort csv-like map
     SortFile.SortDelimitedByNumericKey(
         sourcefilePath: fileName + ".map",
         destinationFolder: directoryName,
         delimiter: Delimiters.Tab,
         keyColumn: keyColumn,
         hasHeader: false,
         isUniqueKey: false,
         sortDir: SortDirection.Ascending
         );
     // Replace unsorted with sorted ones
     if (File.Exists(fileName + ".map") && File.Exists(fileName + "_sorted.map"))
     {
         File.Delete(fileName + ".map");
         File.Move(fileName + "_sorted.map", fileName + ".map");
     }
 }
Esempio n. 4
0
 private async Task sortTitles(string fileName, string directoryName)
 {
     // Create sorted txt file for node search
     SortFile.SortDelimitedByAlphaNumKey(
         sourcefilePath: fileName + ".map",
         destinationFolder: directoryName,
         delimiter: Delimiters.Tab,
         keyColumn: 1,
         keyLength: 0,
         hasHeader: false,
         isUniqueKey: false,
         sortDir: SortDirection.Ascending
         );
     // Renaming sorted file
     if (File.Exists(fileName + "_sorted.map"))
     {
         File.Move(fileName + "_sorted.map", fileName + "-search.map");
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Attempt to physically move the sort file to the file library destination
        /// </summary>
        /// <param name="_sortFile"></param>
        /// <returns></returns>
        public static bool TryMoveSortFile(this SortFile _sortFile)
        {
            string showDirectory = _sortFile.SanitizedFilePath.Replace(_sortFile.SanitizedFileName, "");

            if (Directory.Exists(showDirectory))
            {
                try
                {
                    //To Do: replace with progress bar move after testing
                    File.Move(_sortFile.FilePath, _sortFile.SanitizedFilePath);

                    return(true);
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }
            else
            {
                return(false);
            }
        }
Esempio n. 6
0
        public static bool SanitizeTelevisionEpisode(this SortFile _sortFile, out string SanitizedTitle, out string DisplayShowName, out string SeasonNumber, out string EpisodeNumber)
        {
            if (_sortFile != null)
            {
                string unsanitizedTitle    = _sortFile.FileName;
                string unsanitizedShowName = string.Empty;

                string TelevisionShowPattern = @"(?<ShowName>.+)[.|\s]+[Ss](?<ShowSeasonNumber>\d?\d)[Ee]?(?<ShowEpisodeNumber>\d?\d)[.|\s]+.*(?<ShowFileExtension>mkv|avi|mp4)";

                var RegResults = new Regex(TelevisionShowPattern).Match(unsanitizedTitle);

                unsanitizedShowName = RegResults.Groups["ShowName"].Value;


                if (RegResults.Groups.Count == 5)
                {
                    StringBuilder _finalTitle = new StringBuilder();
                    _finalTitle.Append(RegResults.Groups["ShowName"]);
                    _finalTitle.Append(".S");
                    _finalTitle.Append(RegResults.Groups["ShowSeasonNumber"]);
                    _finalTitle.Append("E");
                    _finalTitle.Append(RegResults.Groups["ShowEpisodeNumber"]);
                    _finalTitle.Append("." + RegResults.Groups["ShowFileExtension"]);

                    SanitizedTitle = _finalTitle.ToString();
                    string SanitizedShowName = RegResults.Groups["ShowName"].Value.Replace(".", " ");

                    //Get CultureInfo and capture TextInfo and apply TitleCase to the show name
                    CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture;
                    TextInfo    textInfo    = cultureInfo.TextInfo;

                    DisplayShowName = textInfo.ToTitleCase(SanitizedShowName);

                    //If season is only one digit in length, assume we need to prepend a 0
                    if (RegResults.Groups["ShowSeasonNumber"].Value.Length == 1)
                    {
                        SeasonNumber = "0" + RegResults.Groups["ShowSeasonNumber"].Value;
                    }
                    else
                    {
                        SeasonNumber = RegResults.Groups["ShowSeasonNumber"].Value;
                    }

                    //Same with episode number, if length == 1 then prepend 0
                    if (RegResults.Groups["ShowEpisodeNumber"].Value.Length == 1)
                    {
                        EpisodeNumber = ")" + RegResults.Groups["ShowEpisodeNumber"].Value;
                    }
                    else
                    {
                        EpisodeNumber = RegResults.Groups["ShowEpisodeNumber"].Value;
                    }

                    _sortFile.SanitizedFileName = SanitizedTitle;
                    _sortFile.SanitizedFilePath = _sortFile.FilePath.Replace(_sortFile.FileName, SanitizedTitle);
                    _sortFile.PriorityLevel     = "1";

                    return(true);
                }
                else
                {
                    SanitizedTitle  = null;
                    DisplayShowName = null;
                    SeasonNumber    = null;
                    EpisodeNumber   = null;

                    return(false);
                    //throw new Exception("Filename does not match Television Episode format.");
                }
            }
            else
            {
                SanitizedTitle  = null;
                DisplayShowName = null;
                SeasonNumber    = null;
                EpisodeNumber   = null;
                return(false);
            }
        }
Esempio n. 7
0
        public static bool IsTelevisionFileNameSanitized(this SortFile _sortFile)
        {
            string TelevisionShowPattern = @"(?<ShowName>.+)[.][Ss](?<ShowSeasonNumber>\d\d)[Ee](?<ShowEpisodeNumber>\d\d)(?<ShowFileExtension>.mkv|.avi|.mp4)";

            return(Regex.IsMatch(_sortFile.FileName, TelevisionShowPattern));
        }