Пример #1
0
        // Generates a list of movies/shows from OMDB results
        public static List <Movie> CreateListOfOmdbResults(Search[] results)
        {
            List <Movie> userSearch = new List <Movie>();

            foreach (var result in results)
            {
                if (result.Type != "game") // This prevents garbage results later
                {
                    var   newResults = WebInteraction.SearchOmdbForId(result.ImdbId);
                    Movie movie      = new Movie
                    {
                        Title      = result.Title,
                        ImdbId     = result.ImdbId,
                        Year       = result.Year,
                        Poster     = result.Poster,
                        Actors     = newResults.Actors,
                        Director   = newResults.Director,
                        ImdbRating = newResults.ImdbRating,
                        Metascore  = newResults.Metascore,
                        Plot       = newResults.Plot,
                        Rated      = newResults.Rated,
                        Ratings    = newResults.Ratings,
                    };
                    userSearch.Add(movie);
                    Task.Delay(1200); //OMDB does not like getting hammered
                }
            }
            return(userSearch);
        }
Пример #2
0
        private static void MainSearch()
        {
            List <Movie> searchedMovieList = new List <Movie>();

            Console.Clear();

            // Gets something to search for
            Console.WriteLine(_banner + "Type the name of the movie or show you want to search for:");
            var input = Console.ReadLine().Trim();

            while (string.IsNullOrWhiteSpace(input))
            {
                Console.WriteLine("Please type something.");
                input = Console.ReadLine().Trim();
            }
            var movieChoice = input;

            // Perform serch on OMDB
            Search[] omdbSearchResults = WebInteraction.SearchOmdbByString(movieChoice);

            // Put results into a list of movies with titles, directors, ratings, etc
            if (omdbSearchResults == null)
            {
                // Getting null is usually a "too many results" error, so we'll take what we get here
                OmdbResult newOmdbResults = WebInteraction.SearchOmdbForTitle(movieChoice);
                Movie      movie          = new Movie
                {
                    Title      = newOmdbResults.Title,
                    ImdbId     = newOmdbResults.ImdbId,
                    Year       = newOmdbResults.Year,
                    Poster     = newOmdbResults.Poster,
                    Actors     = newOmdbResults.Actors,
                    Director   = newOmdbResults.Director,
                    ImdbRating = newOmdbResults.ImdbRating,
                    Metascore  = newOmdbResults.Metascore,
                    Plot       = newOmdbResults.Plot,
                    Rated      = newOmdbResults.Rated,
                    Ratings    = newOmdbResults.Ratings,
                };
                searchedMovieList.Add(movie);
            }
            else
            {
                searchedMovieList = MovieInteraction.CreateListOfOmdbResults(omdbSearchResults);
            }

            Console.Clear();
            Console.WriteLine($"You searched for {movieChoice}.\r\n\r\n");
            ShowAndPickOmdbSearch(searchedMovieList);
        }
Пример #3
0
        private static void UserListInteraction(List <Movie> movies, string fileName)
        {
            Console.Clear();

            Console.WriteLine($"File Loaded: {fileName}.json\r\n\r\n");
            Console.WriteLine(DisplayMovieInfo(movies));

            Console.WriteLine("\r\nType \"S\" to save movie to a different file, type \"C\" to Copy list to another file, type \"D\" to Delete movie from list, or type \"R\" to Reload streaming providers for a result.\r\nType \"F\" to find a new movie or show, type \"L\" to load another file.\r\nType \"Q\" to quit.");
            var menuChoice = Console.ReadLine().ToUpper().Trim();

            while (menuChoice != "S" && menuChoice != "C" && menuChoice != "D" && menuChoice != "R" && menuChoice != "F" && menuChoice != "L" && menuChoice != "Q")
            {
                Console.WriteLine("Please enter S (Save movie to different file), C (Copy list to another list), D (Delete a movie), R (Reload providers), F (Find a movie), L (Load a file), or Q (Quit)");
                menuChoice = Console.ReadLine().ToUpper().Trim();
            }
            switch (menuChoice)
            {
            case "S":
                int i = UserPicksArray();
                while (i >= movies.Count || i < 0)
                {
                    Console.WriteLine("Selection is out of range, please pick again");
                    i = UserPicksArray();
                }
                UserSaveMovie(movies[i]);
                Console.WriteLine("List may need to be reloaded. Press any key to continue");
                Console.ReadKey();
                UserListInteraction(movies, fileName);
                break;

            case "C":
                UserSaveList(movies);
                Console.WriteLine("Press any key to continue");
                Console.ReadKey();
                UserListInteraction(movies, fileName);
                break;

            case "D":
                i = UserPicksArray();
                while (i >= movies.Count || i < 0)
                {
                    Console.WriteLine("Selection is out of range, please pick again");
                    i = UserPicksArray();
                }
                movies.RemoveAt(i);
                MovieInteraction.SaveMoviesToList(movies, fileName + _extension);
                Console.WriteLine("Press any key to continue");
                Console.ReadKey();
                UserListInteraction(movies, fileName);
                break;

            case "R":
                i = UserPicksArray();
                while (i >= movies.Count || i < 0)
                {
                    Console.WriteLine("Selection is out of range, please pick again");
                    i = UserPicksArray();
                }
                var results = WebInteraction.SearchUtellyById(movies[i].ImdbId);
                movies[i].Locations = results.collection.Locations;
                MovieInteraction.SaveMoviesToList(movies, fileName + _extension);
                Console.WriteLine("Press any key to continue");
                Console.ReadKey();
                UserListInteraction(movies, fileName);
                break;

            case "F":
                MainSearch();
                break;

            case "L":
                UserLoadMovieList();
                break;

            case "Q":
                break;
            }
        }
Пример #4
0
// TODO: Allow user to save result from OMDB list before Utelly search?
        private static List <Movie> ShowAndPickOmdbSearch(List <Movie> movies)
        {
            Movie selectedMovie = null;

            // Display results and ask for user to select one
            Console.WriteLine(DisplayMovieInfo(movies));
            if (movies.Count != 0 && movies[0].Title != null)
            {
                int userSelection;
                userSelection = UserPicksArray();
                while (userSelection >= movies.Count || userSelection < 0)
                {
                    Console.WriteLine("Selection is out of range, please pick again");
                    userSelection = UserPicksArray();
                }
                selectedMovie = movies[userSelection];

                // Search for streaming providers for selection using Utelly
                var utellyResult = WebInteraction.SearchUtellyById(selectedMovie.ImdbId);
                // Put streaming locations on our selected movie object
                selectedMovie.Locations = utellyResult.collection.Locations;
                //Can we search by ID? If not here we go:
                // var utellyResult = WebInteraction.SearchUtelly(selectedMovie.Title);
                // selectedMovie.Locations = utellyResult[0].Locations;

                Console.Clear();
                Console.WriteLine($"Here are your results for {selectedMovie.Title}:\r\n\r\n");
                Console.WriteLine(DisplayStreamingLocations(selectedMovie));
            }

            // Search again, save results to file, return to results, or exit?
            Console.WriteLine("\r\nType \"F\" to find another movie or show, type \"S\" to save result to a list file, type \"L\" to load a previous list.\r\nType \"R\" to return to results, and type \"Q\" to quit.");
            var menuChoice = Console.ReadLine().ToUpper().Trim();

            while (menuChoice != "F" && menuChoice != "S" && menuChoice != "L" && menuChoice != "R" && menuChoice != "Q")
            {
                Console.WriteLine("Please enter F (Find another), S (Save result to a list), L (Load list from file), R (Return to results), or Q (quit)");
                menuChoice = Console.ReadLine().ToUpper().Trim();
            }
            switch (menuChoice)
            {
            case "F":
                MainSearch();
                break;

            case "S":
                UserSaveMovie(selectedMovie);
                Console.WriteLine("Press any key to go back to main menu");
                Console.ReadKey();
                MainMenu();
                break;

            case "L":
                UserLoadMovieList();
                break;

            case "R":
                Console.Clear();
                ShowAndPickOmdbSearch(movies);
                break;

            case "Q":
                break;
            }

            return(movies);
        }