public void ParseS99E99Namgs() { string[] goodNames = { @"My Show Season 1 Episode 4.avi", @"s001e001.avi", @"My Show - S01E02 - Show Name.avi", @"My Show - s01e02 - Show Name.avi", @"s001e001.avi", @"s001m001.avi", }; string[] badNames = { @"my show se01.avi", @"myinese02.avi", @"My Show Season1 Episode4.avi", }; foreach (string name in goodNames) { TVShowNameParser show = new TVShowNameParser(name); Assert.That((show.Episode > -1) && (show.Episode < 100), String.Format("{0} should pass (Episode not in range)", name)); Assert.That((show.Season > -1) && (show.Season < 100), String.Format("{0} should pass (Season not in range)", name)); } foreach (string name in badNames) { TVShowNameParser show = new TVShowNameParser(name); Assert.That((show.Episode == -1) || (show.Episode == -1), String.Format("{0} should NOT pass", name)); } }
/// <summary> /// TVFiles constructor. Given the show folder, load the shows into the dictionary /// </summary> /// <param name="path">The TV Show folder</param> public TVFiles(string path) { TVShowFolder f = new TVShowFolder(path); if (!f.IsValid) { return; } DirectoryInfo dir = new DirectoryInfo(f.Location); foreach (FileInfo fi in dir.GetFiles("*.*")) { // Ignore any . files if (fi.Name.StartsWith(".")) continue; TVShowNameParser myNameParser = new TVShowNameParser(fi.Name); if (myNameParser.Matched()) { try { _ShowList.Add(Name(myNameParser.Season, myNameParser.Episode), Name(myNameParser.Season, myNameParser.Episode)); } catch (ArgumentException) { // TODO: This should perhaps write to a delgate and not to the console Console.WriteLine("ERROR! Already exists! You have a duplicate! {0}", Name(myNameParser.Season, myNameParser.Episode)); } } } }
/// <summary> /// TVFiles constructor. Given the show folder, load the shows into the dictionary /// </summary> /// <param name="path">The TV Show folder</param> public TVFiles(string path) { TVShowFolder f = new TVShowFolder(path); if (!f.IsValid) { return; } DirectoryInfo dir = new DirectoryInfo(f.Location); foreach (FileInfo fi in dir.GetFiles("*.*")) { // Ignore any . files if (fi.Name.StartsWith(".")) { continue; } TVShowNameParser myNameParser = new TVShowNameParser(fi.Name); if (myNameParser.Matched()) { try { _ShowList.Add(Name(myNameParser.Season, myNameParser.Episode), Name(myNameParser.Season, myNameParser.Episode)); } catch (ArgumentException) { // TODO: This should perhaps write to a delgate and not to the console Console.WriteLine("ERROR! Already exists! You have a duplicate! {0}", Name(myNameParser.Season, myNameParser.Episode)); } } } }
private static void Main(string[] args) { ProgramOptions options = new ProgramOptions(); // Parse command line options any errors and you get Usage if (options.ParseArgs(args) == false) ProgramOptions.Usage(); // We must have at least 1 path to process files, else Usage and exit if (options.PathList.Count < 1) ProgramOptions.Usage("You must specify at least one TVShowFolder."); List<String> validPaths = new List<string>(); foreach (string p in options.PathList) { Console.WriteLine("Processing: {0}", p); TVShowFolder f = new TVShowFolder(p); if (f.IsValid) { validPaths.Add(p); } else { Console.WriteLine("INGNORED! NOT A VALID PATH: {0}", p); } } // Read program options from the App.Config AppConfigOptions AppConfig = new AppConfigOptions(); // Setup new search object TVSearcher tvSearcher = new TVSearcher(AppConfig.ApiKey); foreach (string p in validPaths) { int TotalEpisodes = 0; int RenamedEpisodes = 0; int ErrorsEpisodes = 0; TVShowFolder myShow = new TVShowFolder(p); if (myShow.HasError()) { Console.WriteLine("Error parsing show name: {0}", myShow.ErrorMessage); continue; } Console.WriteLine("Looking for show: {0}", myShow.ShowName); string outputFile = String.Empty; if (String.IsNullOrEmpty(options.OutputPath)) { outputFile = Platform.IsWindows() ? Path.Combine(myShow.Location, ".rename.bat") : Path.Combine(myShow.Location, ".rename.sh"); } else { outputFile = Path.Combine(options.OutputPath, Path.ChangeExtension(myShow.ShowName, Platform.IsWindows() ? "bat" : "sh")); } TextWriter tw = new StreamWriter(outputFile); string showID; if (myShow.HasAssignedID) { showID = myShow.AssignedID; Console.WriteLine("Has Assigned ID: {0}", showID); } else { TVSeries tvSearch = new TVSeries(); tvSearch = tvSearcher.GetSeries(myShow.ShowName); if (tvSearch.IsSearchResult()) { foreach (DataSeries s in tvSearch.Shows) { Console.WriteLine("Located: {0} {1} {2}", s.id, s.FirstAired, s.SeriesName); } } if (tvSearch.Shows.Count > 1) { Console.WriteLine("Ambigious search for: {0}", myShow.ShowName); Console.WriteLine("Create a .thetvdb.id file wiht the show ID as the 1st line."); continue; } if (tvSearch.Shows.Count == 0) { Console.WriteLine("Unable to locate: {0}", myShow.ShowName); continue; } showID = tvSearch.Series.id; } Console.WriteLine("Located show Number: {0}", showID); TVSeries tvShow = new TVSeries(); tvShow = tvSearcher.GetShow(showID); if (!tvShow.HasEpisodes()) { Console.WriteLine("Unable to locate any episode data!"); continue; } DirectoryInfo dir = new DirectoryInfo(myShow.Location); foreach (FileInfo f in dir.GetFiles("*.*")) { // Ignore any . files if (f.Name.StartsWith(".")) continue; TotalEpisodes++; TVShowNameParser myNameParser = new TVShowNameParser(f.Name); if (myNameParser.Matched()) { DataEpisode thisShow = tvShow.GetEpisode(myNameParser.Season, myNameParser.Episode); tvShow.nameMaskS99E99 = AppConfig.namemasks99e99; tvShow.nameMask99x99 = AppConfig.namemask99x99; if (thisShow != null) { string newName = String.Empty; if (myNameParser.wasSENaming) { newName = tvShow.SEFileName(myNameParser.Season, myNameParser.Episode, Path.GetExtension(f.Name)); } if (myNameParser.wasXNaming) { newName = tvShow.XFileName(myNameParser.Season, myNameParser.Episode, Path.GetExtension(f.Name)); } if (myNameParser.wasSMNaming) { newName = tvShow.SMFileName(myNameParser.Season, myNameParser.Episode, Path.GetExtension(f.Name)); } if (options.ForceXNaming) { newName = tvShow.XFileName(myNameParser.Season, myNameParser.Episode, Path.GetExtension(f.Name)); } if (options.ForceENaming) { newName = tvShow.SEFileName(myNameParser.Season, myNameParser.Episode, Path.GetExtension(f.Name)); } if (newName != f.Name) { RenamedEpisodes++; string sourcePath; string destpath; if (options.UseRelativeNaming) { sourcePath = f.Name; destpath = newName; } else { sourcePath = Path.Combine(myShow.Location, f.Name); destpath = Path.Combine(myShow.Location, newName); } if (File.Exists(destpath)) { Console.WriteLine("WARNING! {0} already exists!"); } if (Platform.IsWindows()) { tw.WriteLine(@"ren ""{0}"" ""{1}"" ", sourcePath, destpath); } else { tw.WriteLine(@"mv ""{0}"" ""{1}"" ", sourcePath, destpath); } Console.WriteLine("RENAME: {0}", newName); } else { Console.WriteLine("GOOD: {0}", f.Name); } } else { ErrorsEpisodes++; Console.WriteLine("ERROR: {0} (Can't Locate)", f.Name); } } else { if (myNameParser.AmbigiousNaming) { ErrorsEpisodes++; Console.WriteLine("ERROR: {0} (AMBIGIOUS NAMING)", f.Name); } else { ErrorsEpisodes++; Console.WriteLine("ERROR: {0} (CAN'T MATCH)", f.Name); } } } Console.WriteLine(""); Console.WriteLine("Total Episodes : {0}", TotalEpisodes); Console.WriteLine("Renamed Episodes: {0}", RenamedEpisodes); Console.WriteLine("Episode Errors : {0}", ErrorsEpisodes); if (RenamedEpisodes > 0) { Console.WriteLine(""); Console.WriteLine("Created {0} for renaming.", outputFile); Console.WriteLine("Please inspect and execute CAREFULLY!"); Console.WriteLine(""); } tw.Close(); // If we didn't rename anything, remove the empty outputFile if (RenamedEpisodes == 0) { File.Delete(outputFile); } } Misc.PauseIfInIDE(); }