Пример #1
0
        public static ImdbMovie GetImdbMovie(String movieName)
        {
            ImdbMovie           movie       = null;
            String              requestName = movieName.Replace(" ", "+");
            HttpResponseMessage response    = null;

            using (HttpClient client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://www.omdbapi.com");
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                response = client.GetAsync(String.Format("http://www.omdbapi.com/?apikey=526156d3&t={0}", requestName)).Result;
            }

            if (response.IsSuccessStatusCode)
            {
                movie = response.Content.ReadAsAsync <ImdbMovie>().Result;
            }

            return(movie);
        }
Пример #2
0
        private static void ProcessMovieFile(FileInfo movieFile)
        {
            fr.Common.WriteLine($"Processing movie file '{movieFile.Name}'");

            String lookupName = movieFile.Name.Replace(movieFile.Extension, String.Empty);

            // movieFile.Name might be 'Star Wars (1976,99).mkv' or 'Star Wars (1976).mkv'
            lookupName = lookupName.GetUntilOrEmpty("(").Trim();

            // Contact IMDB
            fr.Common.WriteLine($"  Asking IMDB for '{lookupName}'");
            ImdbMovie movie            = ImdbConnection.GetImdbMovie(lookupName);
            float     ratingStringTemp = 0;

            if (movie == null || movie.Title == null)
            {
                fr.Common.DrawWarning($"Unable to locate '{lookupName}' in IMDB");
            }
            else if (!float.TryParse(movie.ImdbRating, out ratingStringTemp))
            {
                fr.Common.DrawWarning($"Unable to derive rating for '{lookupName}' from IMDB");
            }
            else
            {
                String ratingString = (ratingStringTemp * 10).ToString();
                String newName      = movieFile.Name.Replace(")", String.Format(",{0})", ratingString));

                switch (GetFileNameFormat(movieFile.Name))
                {
                case NameFormat.Rated:
                    // TODO: compare ratings and update if different
                    Console.Write("   Already rated");
                    break;

                case NameFormat.Unrated:
                    Console.Write("   Rename to '{0}'?", newName);
                    ConsoleKeyInfo cki = Console.ReadKey();

                    if (cki.KeyChar.ToString().ToLower() == "y")
                    {
                        String newFullMoviePath = Path.Combine(movieFile.DirectoryName, newName);
                        File.Move(movieFile.FullName, newFullMoviePath);
                        String originalSrtFileName = movieFile.FullName.Replace(movieFile.Extension, ".srt");

                        if (File.Exists(originalSrtFileName))
                        {
                            String newSrtFilePath = newFullMoviePath.Replace(movieFile.Extension, ".srt");
                            File.Move(originalSrtFileName, newSrtFilePath);
                        }

                        Console.WriteLine("  Renamed.");
                    }
                    else
                    {
                        Console.WriteLine("  Not renamed.");
                    }
                    break;

                case NameFormat.Unknown:
                    fr.Common.DrawWarning($"Unknown filename format: '{lookupName}'");
                    break;
                }
            }

            Console.WriteLine();
        }