Ejemplo n.º 1
0
        /// <summary>
        /// Naming Macro Replacment
        /// </summary>
        /// <param name="theNameMask">Pass in a naming file mask</param>
        /// <param name="theSeason">The Season Number</param>
        /// <param name="theEpisode">The Episode Number</param>
        /// <returns></returns>
        private string ReplaceMacros(string theNameMask, int theSeason, int theEpisode)
        {
            // Format theSeason and theEpisode into 0 padded left strings
            string season  = String.Format("{0:00}", theSeason);
            string episode = String.Format("{0:00}", theEpisode);

            // Return the eipsode information from the list
            DataEpisode de = GetEpisode(theSeason, theEpisode);

            if (de == null)
            {
                return(String.Empty);
            }

            // Standard naming replacments for macros
            theNameMask = theNameMask.Replace("%SHOW_NAME%", Series.SeriesName);
            theNameMask = theNameMask.Replace("%SEASON%", season);
            theNameMask = theNameMask.Replace("%EPISODE%", episode);
            theNameMask = theNameMask.Replace("%NAME%", de.EpisodeName);

            // Extended naming replacments
            theNameMask = theNameMask.Replace("%FIRSTAIRED%", de.FirstAired);
            theNameMask = theNameMask.Replace("%RATING%", de.Rating);

            // NOTE: Would be nice to reflect the assemblie and provide thoes macro replacmens from the XML

            return(theNameMask);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Return the DataEpisode for the given season nad episode number
        /// </summary>
        /// <param name="theSeason">The Season Number</param>
        /// <param name="theEpisode">The Episode Number</param>
        /// <returns></returns>
        public DataEpisode GetEpisode(int theSeason, int theEpisode)
        {
            DataEpisode x = null;

            foreach (DataEpisode de in _Episodes)
            {
                int seasonNumber  = Convert.ToInt32(de.SeasonNumber);
                int episodeNumber = Convert.ToInt32(de.EpisodeNumber);

                if (theSeason == seasonNumber && theEpisode == episodeNumber)
                {
                    x = de;
                }
            }

            return(x);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            //if (false)
            //{
            //    const string theXML = "C:\\repos\\svn\\src\\TheTVDB\\xml-samples\\77345.xml";

            //    TVSeries tvFile = new TVSeries();

            //    tvFile.LoadFromFile(theXML);

            //    if (tvFile.HasEpisodes())
            //    {
            //        foreach (DataEpisode Episode in tvFile.Episodes)
            //        {
            //            Console.WriteLine("{0} {1}x{2} {3}", tvFile.Series.SeriesName, Episode.SeasonNumber,
            //                              Episode.EpisodeNumber, Episode.EpisodeName);

            //        }
            //    }

            //    TVSeries tvSearch = new TVSeries();

            //    //            tvSearch.LoadFromURL("http://thetvdb.com/api/GetSeries.php?seriesname=american"); // Many results
            //    tvSearch.LoadFromURL("http://thetvdb.com/api/GetSeries.php?seriesname=american%20dad"); // One result

            //    if (tvSearch.IsSearchResult())
            //    {
            //        foreach (DataSeries s in tvSearch.Shows)
            //        {
            //            Console.WriteLine("{0} First Aired:{1}", s.SeriesName, s.FirstAired);

            //        }
            //    }
            //}

//            string showFolder = "\\\\JBOD\\video\\TV\\..\\TV\\Classic\\Gilligans Island\\Gilligans_Island_-_s01e00_Original_Pilot.avi";
//            string showFolder = @"\\JBOD\video\TV\..\TV\Classic\Gilligans Island\";

            const string showFolder = @"\\JBOD\video\TV\Classic\Tru Calling";


            TVShowFolder myShow = new TVShowFolder(showFolder);

            if (myShow.IsValid)
            {
                Console.WriteLine("Show name is {0}", myShow.ShowName);
            }
            else
            {
                Console.WriteLine("Error! {0}", myShow.ErrorMessage);

                Console.WriteLine("Press <ENTER> to continue...");
                Console.ReadLine();
                Environment.Exit(1);
            }


            TVSeries tvSearch = new TVSeries();

            string show = HttpUtility.UrlEncode(myShow.ShowName);

            string url = "http://thetvdb.com/api/GetSeries.php?seriesname=" + show;

            tvSearch.LoadFromURL(url);

            if (tvSearch.IsSearchResult())
            {
                foreach (DataSeries s in tvSearch.Shows)
                {
                    Console.WriteLine("{0} First Aired:{1}", s.SeriesName, s.FirstAired);
                }
            }

            if (tvSearch.Shows.Count != 1)
            {
                Console.WriteLine("Ambigious search for {0}", myShow.ShowName);
                Console.WriteLine("Press <ENTER> to continue...");
                Console.ReadLine();
                Environment.Exit(1);
            }

            string showID = tvSearch.Series.id;

            TVSeries tvShow = new TVSeries();

            //showID = "77345";

            string foo = "http://www.thetvdb.com/api/713541F4CE28A6D8/series/" + showID + "/all/en.xml";

            tvShow.LoadFromURL(foo);

            if (tvShow.HasEpisodes())
            {
                Console.WriteLine("We have episodes!");
            }

            Console.WriteLine("This show has {0} seasons.", tvShow.Seasons);


            System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(myShow.Location);
            foreach (System.IO.FileInfo f in dir.GetFiles("*.*"))
            {
                TVShowNameParser myNameParser = new TVShowNameParser(f.Name);

                string fileExtension = Path.GetExtension(f.Name);

                if (myNameParser.Matched())
                {
                    Console.WriteLine("{0} Season {1}, Episode{2}", f.Name, myNameParser.Season, myNameParser.Episode);

                    DataEpisode mine = tvShow.GetEpisode(myNameParser.Season, myNameParser.Episode);

                    if (mine != null)
                    {
                        string season  = String.Format("{0:00}", myNameParser.Season);
                        string episode = String.Format("{0:00}", myNameParser.Episode);

                        Console.WriteLine("Located Show: {0}", mine.EpisodeName);

                        string newName = String.Format("{0} - {1}x{2} - {3}{4}", tvShow.Series.SeriesName, season, episode, mine.EpisodeName, Path.GetExtension(f.Name));

                        if (newName != f.Name)
                        {
                            Console.WriteLine("Rename me!");
                        }
                    }
                }
                else
                {
                    if (myNameParser.AmbigiousNaming)
                    {
                        Console.WriteLine("AMBIGIOUS NAMING: {0}", f.Name);
                    }
                    else
                    {
                        Console.WriteLine("CAN'T MATCH: {0}", f.Name);
                    }
                }
            }


            Console.WriteLine("Press <ENTER> to continue...");
            Console.ReadLine();
        }
Ejemplo n.º 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);

            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();
        }