Beispiel #1
0
        //will search for movie info given the incomplete movie object and its title
        //for now the input can only be of the form <Movie title>(correct year) or else the search will get funny
        //the year must be included as well
        public movObj movInfo(String title, movObj m)
        {
            string prepare = "";

            string movTitle = m.title;
            string year     = m.year;

            if (movTitle.Contains("&"))
            {
                movTitle = movTitle.Replace("&", "and");
            }
            try
            {
                prepare = String.Format("https://api.themoviedb.org/3/search/movie?year={0}&include_adult=false&page=1&query={1}&language=en-US&api_key={2}", year, movTitle, api_key);
                dynamic returned = restRequest(prepare);

                if (returned.total_results > 0)
                {
                    //initialize lists
                    m.actor_id  = new List <string>();
                    m.actor_img = new List <string>();
                    m.character = new List <string>();
                    m.actors    = new List <string>();
                    m.genres    = new List <string>();
                    m.numbering = new List <string>();


                    //gets the full movie info
                    var    parser = ((IEnumerable <dynamic>)returned.results);
                    var    pars   = parser.First();
                    string movId  = Convert.ToString(pars.id);

                    //prepare strings for full movie info and actors
                    prepare = String.Format("https://api.themoviedb.org/3/movie/{0}?language=en-US&api_key={1}", movId, api_key);
                    string prepare0 = String.Format("https://api.themoviedb.org/3/movie/{0}/credits?api_key={1}", movId, api_key);


                    //requests for various movie data
                    dynamic returned0 = restRequest(prepare);
                    dynamic returned1 = restRequest(prepare0);

                    m = movDataIn(returned0, returned1, m);
                }
            }
            catch (RuntimeBinderException z) { }
            //Console.WriteLine(Convert.ToString(returned.overview));
            return(m);
        }
Beispiel #2
0
        //interprets the json data gathered on a movie
        private movObj movDataIn(dynamic b, dynamic c, movObj m)
        {
            //general movie data
            m.title       = b.title;
            m.description = b.overview;
            m.imgPath     = poster_first + b.poster_path;
            m.numbering.Add(Convert.ToString(b.runtime));
            m.numbering.Add(Convert.ToString(b.vote_average));
            m.numbering.Add(Convert.ToString(b.Budget));
            m.numbering.Add(Convert.ToString(b.revenue));


            //genres
            var parser = ((IEnumerable <dynamic>)b.genres);

            foreach (var par in parser)
            {
                String genreTemp = par.name;
                m.genres.Add(Convert.ToString(genreTemp));
            }

            //credits
            parser = ((IEnumerable <dynamic>)c.cast);
            for (int i = 0; i < 4; i++)
            {
                try
                {
                    string imgpath = String.Format("https://image.tmdb.org/t/p/w264_and_h264_bestv2{0}", parser.ElementAt(i).profile_path);
                    m.actor_id.Add(Convert.ToString(parser.ElementAt(i).id));
                    m.actors.Add(parser.ElementAt(i).name);
                    m.character.Add(parser.ElementAt(i).character);
                    m.actor_img.Add(imgpath);
                }
                catch (ArgumentNullException e) { }
            }

            return(m);
        }