Example #1
0
        private static List <ScannedFileInfo> GetFilesInScanDirs()
        {
            List <string>          paths = new List <string>();
            List <ScannedFileInfo> files = new List <ScannedFileInfo>();

            if (Directory.Exists(Settings.FirstScanLocation))
            {
                paths.AddRange(Directory.GetFiles(Settings.FirstScanLocation, "*", SearchOption.AllDirectories));
            }
            if (Directory.Exists(Settings.SecondScanLocation))
            {
                paths.AddRange(Directory.GetFiles(Settings.SecondScanLocation, "*", SearchOption.AllDirectories));
            }
            if (Directory.Exists(Settings.ThirdScanLocation))
            {
                paths.AddRange(Directory.GetFiles(Settings.ThirdScanLocation, "*", SearchOption.AllDirectories));
            }
            foreach (var path in paths)
            {
                ScannedFileInfo sfi = new ScannedFileInfo();
                sfi.origFile = path;
                files.Add(sfi);
            }
            return(FilterExtensions(files));
        }
Example #2
0
        private static ScannedFile Convert(ScannedFileInfo info)
        {
            ScannedFile sf = new ScannedFile();

            sf.OriginalName = info.origFile;
            sf.NewName      = info.newFile;
            sf.Type         = info.type;
            return(sf);
        }
Example #3
0
 private static bool CheckAliases(ScannedFileInfo file, Series series)
 {
     foreach (string alias in series.aliases)
     {
         if (Path.GetFileName(file.origFile.ToUpper()).StartsWith(alias.ToUpper()))
         {
             return(true);
         }
     }
     return(false);
 }
Example #4
0
        public static DBFileInfo Convert(ScannedFileInfo scannedFileInfo)
        {
            if (null == scannedFileInfo || null == scannedFileInfo.File)
            {
                return(Create());
            }

            return(new DBFileInfo()
            {
                Name = scannedFileInfo.File.Name, Path = scannedFileInfo.File.FullName, Extension = scannedFileInfo.File.Extension, Category = scannedFileInfo.Category
            });
        }
Example #5
0
        public async static Task RenameSingle(string file, Series series, Episode episode)
        {
            var sfi = new ScannedFileInfo();

            sfi.origFile  = file;
            sfi.extension = Path.GetExtension(file);
            sfi.series    = series;
            sfi.episode   = episode;
            sfi.type      = GetFileType(file);
            var result = await Rename(sfi);

            episode = AddToDatabase(episode, sfi);
            Database.EditEpisode(series.id, episode.id, episode);
        }
Example #6
0
        private static List <ScannedFileInfo> GetFilesInDirectory(string path)
        {
            List <ScannedFileInfo> files = new List <ScannedFileInfo>();
            List <string>          paths = new List <string>();

            paths.AddRange(Directory.GetFiles(path, "*", SearchOption.AllDirectories));
            foreach (var file in paths)
            {
                ScannedFileInfo sfi = new ScannedFileInfo();
                sfi.origFile = file;
                files.Add(sfi);
            }
            return(FilterExtensions(files));
        }
Example #7
0
        private static bool CheckAliasesParentDir(ScannedFileInfo path, Series series)
        {
            string pathDir = Path.GetFileName(Path.GetDirectoryName(path.origFile.ToUpper()));

            foreach (string alias in series.aliases)
            {
                string temp = alias.ToUpper();
                if ((pathDir.StartsWith(temp) ||
                     (pathDir.Contains("SEASON") && Path.GetFileName(Path.GetDirectoryName(Path.GetDirectoryName(path.origFile.ToUpper()))).StartsWith(temp))) &&
                    IsMatchToIdentifiers(path.origFile))
                {
                    return(true);
                }
            }
            return(false);
        }
Example #8
0
 private static List <ScannedFileInfo> GetFilesInLibrary(Series series)
 {
     if (series.libraryPath == null)
     {
         CreateDirectoryForSeries(series);
         return(new List <ScannedFileInfo>());
     }
     else
     {
         List <ScannedFileInfo> list = new List <ScannedFileInfo>();
         foreach (var file in Directory.GetFiles(series.libraryPath, "*", SearchOption.AllDirectories))
         {
             ScannedFileInfo sfi = new ScannedFileInfo();
             sfi.origFile    = file;
             sfi.fromLibrary = true;
             list.Add(sfi);
         }
         return(FilterExtensions(list));
     }
 }
Example #9
0
        private static Tuple <int, int> GetInfo(ScannedFileInfo file)
        {
            Match season  = new Regex("[s][0-9][0-9]", RegexOptions.IgnoreCase).Match(file.origFile);
            Match episode = new Regex("[e][0-9][0-9]", RegexOptions.IgnoreCase).Match(file.origFile);
            Match special = new Regex("[0-9][0-9][x][0-9][0-9]", RegexOptions.IgnoreCase).Match(file.origFile);

            if (season.Success && episode.Success)
            {
                int s = Int32.Parse(season.Value.Remove(0, 1));
                int e = Int32.Parse(episode.Value.Remove(0, 1));
                return(new Tuple <int, int>(s, e));
            }
            else if (special.Success)
            {
                int s = Int32.Parse(special.Value.Substring(0, 2));
                int e = Int32.Parse(special.Value.Substring(3, 2));
                return(new Tuple <int, int>(s, e));
            }
            return(null);
        }
Example #10
0
        private async static Task <ScannedFileInfo> Rename(ScannedFileInfo info)
        {
            info.newFile = GetPath(info);
            if (info.newFile != info.origFile)
            {
                try {
                    File.Move(info.origFile, info.newFile);
                } catch (IOException) {
                    MessageBoxResult result = MessageBoxResult.Cancel;
                    await Application.Current.Dispatcher.Invoke(async() => {
                        result = await MessageBox.Show("File " + info.origFile + " is probably in use. \n\nTry again?", "Error", MessageBoxButtons.YesNoCancel);
                    });

                    if (result == MessageBoxResult.Yes)
                    {
                        return(await Rename(info));
                    }
                }
            }
            return(info);
        }
Example #11
0
        private static Episode AddToDatabase(Episode episode, ScannedFileInfo sfi)
        {
            bool add = true;

            if (episode.files.Count > 0)
            {
                foreach (ScannedFile sf in episode.files)
                {
                    if (sf.NewName == sfi.origFile)
                    {
                        sf.NewName = sfi.newFile;
                        add        = false;
                    }
                }
            }
            if (add)
            {
                episode.files.Add(Convert(sfi));
            }
            return(episode);
        }
Example #12
0
        private static string GetPath(ScannedFileInfo info)
        {
            string name      = Helper.GenerateName(info.series, info.episode);
            string directory = null;
            int?   season    = info.episode.airedSeason;

            if (season < 10)
            {
                directory = info.series.libraryPath + @"\Season 0" + season + "\\";
                Directory.CreateDirectory(directory);
            }
            else if (season >= 10)
            {
                directory = info.series.libraryPath + @"\Season " + season + "\\";
                Directory.CreateDirectory(directory);
            }
            if (info.origFile == directory + name + info.extension)
            {
                return(info.origFile);
            }
            string old   = Path.GetFileNameWithoutExtension(info.origFile);
            Match  match = new Regex(name + "_[0-9]?[0-9]").Match(old);

            if (match.Success)
            {
                if (!LowerAvailable(info.origFile, name))
                {
                    return(info.origFile);
                }
            }
            int    filenumber = 1;
            string final      = directory + name + info.extension;

            while (File.Exists(final))
            {
                final = directory + name + "_" + filenumber + info.extension;
                filenumber++;
            }
            return(final);
        }