Beispiel #1
0
        /// <summary>
        /// Retourne un film et toute ses données à partir de l'id
        /// </summary>
        /// <param name="id">l'id du film</param>
        /// <returns>un objet contenant toute les infos utiles liées au film</returns>
        public async Task <DataFromInternet> GetFilmJson(int id)
        {
            var lien = ConstructeurLien(MovieDbRequeteEnum.GETMOVIE, id.ToString(), 0);

            using (var client = new HttpClient())
            {
                var retour   = new DataFromInternet();
                var response = await client.GetAsync(new Uri(lien));

                var jsonString = await response.Content.ReadAsStringAsync();

                var serializer = new DataContractJsonSerializer(typeof(MovieJson));
                var ms         = new MemoryStream(Encoding.UTF8.GetBytes(jsonString));
                var film       = (MovieJson)serializer.ReadObject(ms);

                retour.Film = film;
                retour.Film.vote_average = (retour.Film.vote_average > 0)?retour.Film.vote_average / 2:0;
                retour.Casting           = await GetCasting(film.id, TypeFilmEnum.FILM, true);

                retour.Affiche = (BitmapImage)(await GetAffiche(film.poster_path, false))[0];
                if (film.belongs_to_collection?.id != null && film.belongs_to_collection?.id > 0)
                {
                    retour.Collection = await GetCollectionInternet(film.belongs_to_collection.id);

                    foreach (var partJson in retour.Collection.parts)
                    {
                        partJson.affiche = (BitmapImage)(await GetAffiche(partJson.poster_path, false))[0];
                    }
                }
                retour.SimilarMovie = await GetSimilarMovieLight(film.id);

                return(retour);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Retourne une série et toute ses données à partir de l'id
        /// </summary>
        /// <param name="id">l'id de la série</param>
        /// <returns>un objet contenant toute les infos utiles liées à la série</returns>
        public async Task <DataFromInternet> GetSerieJson(int id)
        {
            var lien = ConstructeurLien(MovieDbRequeteEnum.GETTV, id.ToString(), 0);

            using (var client = new HttpClient())
            {
                var retour   = new DataFromInternet();
                var response = await client.GetAsync(new Uri(lien));

                var jsonString = await response.Content.ReadAsStringAsync();

                var serializer = new DataContractJsonSerializer(typeof(TvJson));
                var ms         = new MemoryStream(Encoding.UTF8.GetBytes(jsonString));
                var tv         = (TvJson)serializer.ReadObject(ms);

                retour.Tv = tv;
                retour.Tv.vote_average = (retour.Tv.vote_average > 0)?retour.Tv.vote_average / 2:0;
                retour.Casting         = await GetCasting(tv.id, TypeFilmEnum.SERIE, true);

                retour.Affiche   = (BitmapImage)(await GetAffiche(tv.poster_path, false))[0];
                retour.SimilarTv = await GetSimilarTvLight(tv.id);

                return(retour);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Retourne une personne à partir de son id
        /// </summary>
        /// <param name="id">l'id de la personne</param>
        /// <returns>un objet contenant toute les infos utiles liées à la personne</returns>
        public async Task <DataFromInternet> GetPersonneJson(int id)
        {
            var lien = ConstructeurLien(MovieDbRequeteEnum.GETPERSON, id.ToString(), 0);

            using (var client = new HttpClient())
            {
                //la personne
                var retour   = new DataFromInternet();
                var response = await client.GetAsync(new Uri(lien));

                var jsonString = await response.Content.ReadAsStringAsync();

                var serializer = new DataContractJsonSerializer(typeof(PersonJson));
                var ms         = new MemoryStream(Encoding.UTF8.GetBytes(jsonString));
                var person     = (PersonJson)serializer.ReadObject(ms);

                //ces films
                lien     = ConstructeurLien(MovieDbRequeteEnum.GETPERSONCREDIT, id.ToString(), 0);
                response = await client.GetAsync(new Uri(lien));

                jsonString = await response.Content.ReadAsStringAsync();

                serializer = new DataContractJsonSerializer(typeof(CreditPersonJson));
                ms         = new MemoryStream(Encoding.UTF8.GetBytes(jsonString));
                var creditPerson = (CreditPersonJson)serializer.ReadObject(ms);
                creditPerson.cast = creditPerson.cast.OrderByDescending(x => x.release_date).ThenByDescending(x => x.first_air_date).ToList();

                //la photo
                retour.Affiche = new BitmapImage(new Uri(AdresseRootPhotoActeur + person.profile_path));

                //retour
                retour.Person       = person;
                retour.CreditPerson = creditPerson;

                creditPerson.crew = creditPerson.crew.OrderBy(x => x.media_type).ToList();
                creditPerson.cast = creditPerson.cast.OrderBy(x => x.media_type).ToList();

                foreach (var crewPersonJson in creditPerson.crew)
                {
                    if (string.IsNullOrEmpty(crewPersonJson.title))
                    {
                        crewPersonJson.title = crewPersonJson.name;
                    }

                    if (string.IsNullOrEmpty(crewPersonJson.release_date))
                    {
                        crewPersonJson.release_date = crewPersonJson.first_air_date;
                    }
                }

                foreach (var castPersonJson in creditPerson.cast)
                {
                    if (string.IsNullOrEmpty(castPersonJson.title))
                    {
                        castPersonJson.title = castPersonJson.name;
                    }

                    if (string.IsNullOrEmpty(castPersonJson.release_date))
                    {
                        castPersonJson.release_date = castPersonJson.first_air_date;
                    }
                }
                return(retour);
            }
        }