示例#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;
        }
示例#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;
        }
示例#3
0
        /// <summary>
        /// Given a show ID, get the show information
        /// </summary>
        /// <param name="id">The series ID</param>
        /// <returns>TVSerise</returns>
        public TVSeries GetSeriesByID(string id)
        {
            string url = GetMirrorURL() + "/api/" + _apiKey + "/series/" + id + "/en.xml";

            TVSeries ts = new TVSeries();

            ts.LoadFromURL(url);

            return(ts);
        }
示例#4
0
        /// <summary>
        /// Try to match a series by showName
        /// If you get more than one match by show name, try to match by the year in the show name, if present
        /// </summary>
        /// <param name="showName">The show name to search</param>
        /// <returns></returns>
        public TVSeries GetSeries(string showName)
        {
            int year = -1;

            // Remove any thing that looks like a (year) in the name, we will use the year later
            MatchCollection matches = YearRegex.Matches(showName);

            foreach (Match y in matches)
            {
                showName = showName.Replace(y.Value, "");

                string yy = y.Value;
                // Remove beginning ( and ending )
                yy = yy.Replace("(", "");
                yy = yy.Replace(")", "");

                year = Convert.ToInt32(yy);
            }

            string show = HttpUtility.UrlEncode(showName);

            string url = GetMirrorURL() + "/api/GetSeries.php?seriesname=" + show;

            TVSeries ts = new TVSeries();

            ts.LoadFromURL(url);

            // If we have more that 1 show returned
            if (ts.Shows.Count > 1)
            {
                // Try and match by the year
                foreach (DataSeries s in ts.Shows)
                {
                    // Some shows don't have a FirstAired field!
                    if (!String.IsNullOrEmpty(s.FirstAired))
                    {
                        string x = s.FirstAired;
                        x = x.Substring(0, 4);

                        if (Convert.ToInt32(x) == year)
                        {
                            return (GetSeriesByID(s.id));
                        }
                    }
                }
            }

            return (ts);
        }
示例#5
0
        /// <summary>
        /// Try to match a series by showName
        /// If you get more than one match by show name, try to match by the year in the show name, if present
        /// </summary>
        /// <param name="showName">The show name to search</param>
        /// <returns></returns>
        public TVSeries GetSeries(string showName)
        {
            int year = -1;

            // Remove any thing that looks like a (year) in the name, we will use the year later
            MatchCollection matches = YearRegex.Matches(showName);

            foreach (Match y in matches)
            {
                showName = showName.Replace(y.Value, "");

                string yy = y.Value;
                // Remove beginning ( and ending )
                yy = yy.Replace("(", "");
                yy = yy.Replace(")", "");

                year = Convert.ToInt32(yy);
            }

            string show = HttpUtility.UrlEncode(showName);

            string url = GetMirrorURL() + "/api/GetSeries.php?seriesname=" + show;

            TVSeries ts = new TVSeries();

            ts.LoadFromURL(url);

            // If we have more that 1 show returned
            if (ts.Shows.Count > 1)
            {
                // Try and match by the year
                foreach (DataSeries s in ts.Shows)
                {
                    // Some shows don't have a FirstAired field!
                    if (!String.IsNullOrEmpty(s.FirstAired))
                    {
                        string x = s.FirstAired;
                        x = x.Substring(0, 4);

                        if (Convert.ToInt32(x) == year)
                        {
                            return(GetSeriesByID(s.id));
                        }
                    }
                }
            }

            return(ts);
        }
示例#6
0
        /// <summary>
        /// Get a specific how given a show ID (i.e. Episode)
        /// </summary>
        /// <param name="showID">The Episode Number</param>
        /// <returns>TVSeries</returns>
        public TVSeries GetShow(string showID)
        {
            if (!_InternetAccess)
            {
                throw new System.Net.WebException("Internet set to down");
            }

            string url = GetMirrorURL() + "/api/" + _apiKey + "/series/" + showID + "/all/en.xml";

            TVSeries ts = new TVSeries();

            ts.LoadFromURL(url);

            return(ts);
        }
        ///<summary>
        ///</summary>
        ///<param name="theShowName"></param>
        ///<param name="theFolder"></param>
        ///<returns></returns>
        public TVSeries GetSeries(string theShowName, string theFolder)
        {
            TVSeries showResult = new TVSeries();

            string cacheFile = Path.Combine(theFolder, ".show.xml");

            if (File.Exists(cacheFile))
            {
                showResult.LoadFromFile(theFolder);
            }
            else
            {
                showResult = GetSeries(theShowName);

                showResult.WriteCache(cacheFile);

                return(showResult);
            }

            return(showResult);
        }
        ///<summary>
        ///</summary>
        ///<param name="theShowName"></param>
        ///<param name="theFolder"></param>
        ///<returns></returns>
        public TVSeries GetSeries(string theShowName, string theFolder)
        {
            TVSeries showResult = new TVSeries();

            string cacheFile = Path.Combine(theFolder, ".show.xml");

            if (File.Exists(cacheFile))
            {
                showResult.LoadFromFile(theFolder);
            }
            else
            {
                showResult = GetSeries(theShowName);

                showResult.WriteCache(cacheFile);

                return (showResult);
            }

            return (showResult);
        }
示例#9
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();
        }
示例#10
0
        ///<summary>
        ///</summary>
        ///<param name="showID"></param>
        ///<returns></returns>
        public TVSeries GetShowData(int showID)
        {
            TVSeries show = new TVSeries();

            return (show);
        }
示例#11
0
        ///<summary>
        ///</summary>
        ///<param name="showID"></param>
        ///<returns></returns>
        public TVSeries GetShowData(int showID)
        {
            TVSeries show = new TVSeries();

            return(show);
        }
示例#12
0
        /// <summary>
        /// Get a specific how given a show ID (i.e. Episode)
        /// </summary>
        /// <param name="showID">The Episode Number</param>
        /// <returns>TVSeries</returns>
        public TVSeries GetShow(string showID)
        {
            if (!_InternetAccess) throw new System.Net.WebException("Internet set to down");

            string url = GetMirrorURL() + "/api/" + _apiKey +"/series/" + showID + "/all/en.xml";

            TVSeries ts = new TVSeries();

            ts.LoadFromURL(url);

            return (ts);
        }
示例#13
0
        /// <summary>
        /// Given a show ID, get the show information
        /// </summary>
        /// <param name="id">The series ID</param>
        /// <returns>TVSerise</returns>
        public TVSeries GetSeriesByID(string id)
        {
            string url = GetMirrorURL() + "/api/" + _apiKey +"/series/" + id + "/en.xml";

            TVSeries ts = new TVSeries();

            ts.LoadFromURL(url);

            return (ts);
        }