Beispiel #1
0
        ///<summary>
        ///</summary>
        ///<param name="APIKey"></param>
        ///<param name="path"></param>
        public TVTool(string APIKey, string path)
        {
            _HasError     = true;
            _Path         = path;
            _APIKey       = APIKey;
            _ErrorMessage = String.Empty;

            TVShowFolder myShow = new TVShowFolder(_Path);

            if (myShow.HasError())
            {
                _HasError     = true;
                _ErrorMessage = myShow.ErrorMessage;
                return;
            }


            if (myShow.HasAssignedID)
            {
                _ID = myShow.AssignedID;

                _HasError = false;

                return;
            }

            // If we don't have an assigned ID, we have to search for the show

            TVSeries tvSearch = new TVSeries();

            // Setup new search object
            TVSearcher tvSearcher = new TVSearcher(_APIKey);

            tvSearch = tvSearcher.GetSeries(myShow.ShowName);

            if (tvSearch.Shows.Count > 1)
            {
                _ErrorMessage = String.Format("Ambigious search for: {0}", myShow.ShowName);
                _HasError     = true;

                return;
            }

            if (tvSearch.Shows.Count == 0)
            {
                _ErrorMessage = String.Format("Unable to locate: {0}", myShow.ShowName);
                _HasError     = true;

                return;
            }

            // Set the ID and the error condition to false;
            _ID       = tvSearch.Series.id;
            _HasError = false;

            return;
        }
Beispiel #2
0
        ///<summary>
        ///</summary>
        ///<param name="APIKey"></param>
        ///<param name="path"></param>
        public TVTool(string APIKey, string path)
        {
            _HasError = true;
            _Path = path;
            _APIKey = APIKey;
            _ErrorMessage = String.Empty;

            TVShowFolder myShow = new TVShowFolder(_Path);

            if (myShow.HasError())
            {
                _HasError = true;
                _ErrorMessage = myShow.ErrorMessage;
                return;
            }

            if (myShow.HasAssignedID)
            {
                _ID = myShow.AssignedID;

                _HasError = false;

                return;
            }

            // If we don't have an assigned ID, we have to search for the show

            TVSeries tvSearch = new TVSeries();

            // Setup new search object
            TVSearcher tvSearcher = new TVSearcher(_APIKey);

            tvSearch = tvSearcher.GetSeries(myShow.ShowName);

            if (tvSearch.Shows.Count > 1)
            {
                _ErrorMessage = String.Format("Ambigious search for: {0}", myShow.ShowName);
                _HasError = true;

                return;
            }

            if (tvSearch.Shows.Count == 0)
            {
                _ErrorMessage = String.Format("Unable to locate: {0}", myShow.ShowName);
                _HasError = true;

                return;
            }

            // Set the ID and the error condition to false;
            _ID = tvSearch.Series.id;
            _HasError = false;

            return;
        }
Beispiel #3
0
        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();
        }
Beispiel #4
0
        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);

            // Search each path
            foreach (string p in validPaths)
            {

                TVShowFolder myShow = new TVShowFolder(p);

                Console.WriteLine("Looking for show: {0}", myShow.ShowName);

                string showID;

                if (myShow.HasAssignedID)
                {
                    showID = myShow.AssignedID;
                    Console.WriteLine("Has Assigned ID: {0}", showID);
                }
                else
                {
                    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 with 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;
                }

                TVSeries tvShow = tvSearcher.GetShow(showID);

                if (!tvShow.HasEpisodes())
                {
                    Console.WriteLine("Unable to locate any episode data!");
                    continue;
                }

                if (tvShow.Series.Status == "Ended")
                {
                    Console.WriteLine("No more episodes :-( The show has ended!");
                    continue;
                }

                // Load up a list of the existing files in this folder
                TVFiles myTVFiles = new TVFiles(p);

                bool foundNewEpisode = false;

                foreach (DataEpisode de in tvShow.Episodes)
                {
                    DateTime date;

                    try
                    {
                        date = DateTime.ParseExact(de.FirstAired, "yyyy-MM-dd",
                                                   System.Globalization.CultureInfo.InvariantCulture);
                    }
                    catch
                    {
                        // Probably a blank date so it is in the future.
                        continue;
                    }

                    if (date >= DateTime.Now)
                    {
                        foundNewEpisode = true;
                        Console.WriteLine("NEXT AIR: {0}\t{1}\t{2}\t{3}x{4}\t{5}", de.FirstAired, tvShow.Series.id, tvShow.Series.SeriesName, de.SeasonNumber, de.EpisodeNumber, de.EpisodeName);
                        break;
                    }

                    if (!myTVFiles.Exist(Convert.ToInt32(de.SeasonNumber), Convert.ToInt32(de.EpisodeNumber)))
                    {
                        Console.WriteLine("MISSING!  {0}\t{1}\t{2}\t{3}x{4}\t{5}", de.FirstAired, tvShow.Series.id, tvShow.Series.SeriesName, de.SeasonNumber, de.EpisodeNumber, de.EpisodeName);
                    }

                }

                if (!foundNewEpisode)
                {
                    Console.WriteLine("Unable to locate a new episode.");
                }

            }

            Misc.PauseIfInIDE();
        }