2017-07-17 19:42:36 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Discord;
|
2016-12-22 03:49:33 +00:00
|
|
|
|
using NadekoBot.Extensions;
|
2017-05-27 08:19:27 +00:00
|
|
|
|
using NadekoBot.Services;
|
2016-12-08 20:20:13 +00:00
|
|
|
|
using Newtonsoft.Json;
|
2016-10-15 21:14:28 +00:00
|
|
|
|
|
2017-07-17 19:42:36 +00:00
|
|
|
|
namespace NadekoBot.Modules.Searches.Common
|
2016-10-15 21:14:28 +00:00
|
|
|
|
{
|
|
|
|
|
public static class OmdbProvider
|
|
|
|
|
{
|
2017-06-06 00:13:43 +00:00
|
|
|
|
private const string queryUrl = "https://omdbapi.nadekobot.me/?t={0}&y=&plot=full&r=json";
|
2016-10-15 21:14:28 +00:00
|
|
|
|
|
2017-05-27 08:19:27 +00:00
|
|
|
|
public static async Task<OmdbMovie> FindMovie(string name, IGoogleApiService google)
|
2016-10-15 21:14:28 +00:00
|
|
|
|
{
|
|
|
|
|
using (var http = new HttpClient())
|
|
|
|
|
{
|
|
|
|
|
var res = await http.GetStringAsync(String.Format(queryUrl,name.Trim().Replace(' ','+'))).ConfigureAwait(false);
|
|
|
|
|
var movie = JsonConvert.DeserializeObject<OmdbMovie>(res);
|
2017-01-03 20:12:21 +00:00
|
|
|
|
if (movie?.Title == null)
|
|
|
|
|
return null;
|
2017-05-27 08:19:27 +00:00
|
|
|
|
movie.Poster = await google.ShortenUrl(movie.Poster);
|
2016-10-15 21:14:28 +00:00
|
|
|
|
return movie;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class OmdbMovie
|
|
|
|
|
{
|
|
|
|
|
public string Title { get; set; }
|
|
|
|
|
public string Year { get; set; }
|
|
|
|
|
public string ImdbRating { get; set; }
|
|
|
|
|
public string ImdbId { get; set; }
|
|
|
|
|
public string Genre { get; set; }
|
|
|
|
|
public string Plot { get; set; }
|
|
|
|
|
public string Poster { get; set; }
|
|
|
|
|
|
2016-12-16 18:43:57 +00:00
|
|
|
|
public EmbedBuilder GetEmbed() =>
|
2016-12-22 03:49:33 +00:00
|
|
|
|
new EmbedBuilder().WithOkColor()
|
2016-12-08 20:20:13 +00:00
|
|
|
|
.WithTitle(Title)
|
|
|
|
|
.WithUrl($"http://www.imdb.com/title/{ImdbId}/")
|
2017-06-11 21:48:46 +00:00
|
|
|
|
.WithDescription(Plot.TrimTo(1000))
|
2016-12-08 20:20:13 +00:00
|
|
|
|
.AddField(efb => efb.WithName("Rating").WithValue(ImdbRating).WithIsInline(true))
|
|
|
|
|
.AddField(efb => efb.WithName("Genre").WithValue(Genre).WithIsInline(true))
|
|
|
|
|
.AddField(efb => efb.WithName("Year").WithValue(Year).WithIsInline(true))
|
2016-12-16 18:43:57 +00:00
|
|
|
|
.WithImageUrl(Poster);
|
2016-12-08 20:20:13 +00:00
|
|
|
|
|
2016-10-15 21:14:28 +00:00
|
|
|
|
public override string ToString() =>
|
|
|
|
|
$@"`Title:` {Title}
|
|
|
|
|
`Year:` {Year}
|
|
|
|
|
`Rating:` {ImdbRating}
|
|
|
|
|
`Genre:` {Genre}
|
|
|
|
|
`Link:` http://www.imdb.com/title/{ImdbId}/
|
|
|
|
|
`Plot:` {Plot}";
|
|
|
|
|
}
|
|
|
|
|
}
|