Пример #1
0
        public static Schema.NET.Movie ToStructuredData(this Details model)
        {
            var actors     = model.Actors.Split(",");
            var actorsList = new List <Person>();

            foreach (var actor in actors)
            {
                var actorStructured = new Person
                {
                    Name = actor
                };
                actorsList.Add(actorStructured);
            }

            var aggregateRatingList = new List <AggregateRating>
            {
                new AggregateRating
                {
                    Author = new Values <IOrganization, IPerson>(new Organization
                    {
                        Name = "IMDb"
                    }),
                    RatingValue = model.ImdbRating,
                    RatingCount = int.Parse(model.ImdbVotes, NumberStyles.AllowThousands, new CultureInfo("en-au")),
                    BestRating  = 10,
                    WorstRating = 0
                }
            };

            var movieStructuredSchema = new Schema.NET.Movie
            {
                Name     = model.Title,
                Director = new OneOrMany <IPerson>(new Person
                {
                    Name = model.Director
                }),
                CountryOfOrigin = new OneOrMany <ICountry>(new Country
                {
                    Name = model.Country
                }),
                ContentRating   = model.Rated,
                DateCreated     = DateTime.Parse(model.Released),
                Actor           = new OneOrMany <IPerson>(actorsList),
                Genre           = new Values <string, Uri>(model.Genre),
                Award           = new OneOrMany <string>(model.Awards),
                AggregateRating = new OneOrMany <IAggregateRating>(aggregateRatingList)
            };

            try
            {
                movieStructuredSchema.Image = new Uri(model.Poster);
                movieStructuredSchema.Url   = new Uri($"https://www.imdb.com/title/{model.ImdbID}");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error converting to ld+json: {ex.Message}");
            }

            return(movieStructuredSchema);
        }
Пример #2
0
        public static Schema.NET.Movie ToStructuredData(this SearchResult model, int position)
        {
            var movieStructuredSchema = new Schema.NET.Movie
            {
                Name     = model.Title,
                Position = position
            };

            try
            {
                movieStructuredSchema.Image = new Uri(model.Poster);
                movieStructuredSchema.Url   = new Uri($"https://www.imdb.com/title/{model.ImdbID}");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error converting to ld+json: {ex.Message}");
            }

            return(movieStructuredSchema);
        }
Пример #3
0
        public async Task <IActionResult> Details(string i)
        {
            string apiUrl = configuration.GetValue <string>("api:url");
            string apiKey = configuration.GetValue <string>("api:key");

            UriBuilder baseUri = new UriBuilder(apiUrl + "?apiKey=" + apiKey);

            Details details = null;

            if (i != null && i.Length > 0)
            {
                string queryToAppend = "i=" + i;
                if (baseUri.Query != null && baseUri.Query.Length > 1)
                {
                    baseUri.Query = baseUri.Query.Substring(1) + "&" + queryToAppend;
                }
                else
                {
                    baseUri.Query = queryToAppend;
                }

                string url = baseUri.ToString();

                using (var httpClient = new HttpClient())
                {
                    using (var response = await httpClient.GetAsync(url))
                    {
                        string apiResponse = await response.Content.ReadAsStringAsync();

                        JObject o = JObject.Parse(apiResponse);
                        if ((string)o["Response"] == "True")
                        {
                            details = JsonConvert.DeserializeObject <Details>(apiResponse);
                        }
                    }
                }
            }

            Person actor = new Person()
            {
                Name = new List <String>()
                {
                    details.Actors
                }
            };

            Person director = new Person()
            {
                Name = details.Director
            };

            Country c = new Country()
            {
                Name = details.Country
            };

            int minDuration = 0;

            if (details.Runtime.Length > 0 && details.Runtime.Contains(' '))
            {
                string[] sDuration = details.Runtime.Split(' ');
                if (sDuration.Length > 0)
                {
                    minDuration = int.Parse(sDuration[0]);
                }
            }
            int hours   = 0,
                minutes = 0;

            if (minDuration > 0)
            {
                hours   = minDuration / 60;
                minutes = minDuration % 60;
            }
            OneOrMany <TimeSpan?> duration = new OneOrMany <TimeSpan?>(new TimeSpan(hours, minutes, 0));

            var organization = new Organization()
            {
                Name = details.Production
            };

            var movieSchema = new Schema.NET.Movie()
            {
                Actor             = actor,
                CountryOfOrigin   = c,
                Director          = director,
                Duration          = duration,
                SubtitleLanguage  = details.Language,
                ProductionCompany = organization
            };

            ViewBag.JsonLd = movieSchema.ToString();

            return(View(details));
        }