diff --git a/src/NadekoBot/Modules/Searches/Commands/IMDB/ImdbScraper.cs b/src/NadekoBot/Modules/Searches/Commands/IMDB/ImdbScraper.cs deleted file mode 100644 index 3f635099..00000000 --- a/src/NadekoBot/Modules/Searches/Commands/IMDB/ImdbScraper.cs +++ /dev/null @@ -1,168 +0,0 @@ -ο»Ώusing NadekoBot.Extensions; -using NadekoBot.Modules.Searches.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Text.RegularExpressions; -using System.Threading.Tasks; - -/******************************************************************************* -* Free ASP.net IMDb Scraper API for the new IMDb Template. -* Author: Abhinay Rathore -* Website: http://www.AbhinayRathore.com -* Blog: http://web3o.blogspot.com -* More Info: http://web3o.blogspot.com/2010/11/aspnetc-imdb-scraping-api.html - -* Updated By: Gergo Torcsvari -* Last Updated: Feb, 2016 -*******************************************************************************/ - -namespace NadekoBot.Modules.Searches.IMDB -{ - public static class ImdbScraper - { - //Search Engine URLs - private static string GoogleSearch = "https://www.google.com/search?q=imdb+"; - //Constructor - public static async Task ImdbScrape(string MovieName, bool GetExtraInfo = true) - { - ImdbMovie mov = new ImdbMovie(); - string imdbUrl = await GetIMDbUrlAsync(System.Uri.EscapeUriString(MovieName)); - mov.Status = false; - if (!string.IsNullOrWhiteSpace(imdbUrl)) - { - await ParseIMDbPage(imdbUrl, GetExtraInfo, mov); - } - - return mov; - } - - public static async Task ImdbScrapeFromId(string imdbId, bool GetExtraInfo = true) - { - ImdbMovie mov = new ImdbMovie(); - string imdbUrl = "http://www.imdb.com/title/" + imdbId + "/"; - mov.Status = false; - await ParseIMDbPage(imdbUrl, GetExtraInfo, mov); - return mov; - } - - public static async Task GetIMDBId(string MovieName) - { - string imdbUrl = await GetIMDbUrlAsync(System.Uri.EscapeUriString(MovieName)); - return Match(@"http://www.imdb.com/title/(tt\d{7})", imdbUrl); - } - //Get IMDb URL from search results - private static async Task GetIMDbUrlAsync(string MovieName) - { - string url = GoogleSearch + MovieName; - string html = await GetUrlDataAsync(url); - List imdbUrls = MatchAll(@".*?", html); - if (imdbUrls.Count > 0) - return (string)imdbUrls[0]; - else return String.Empty; - } - //Parse IMDb page data - private static async Task ParseIMDbPage(string imdbUrl, bool GetExtraInfo, ImdbMovie mov) - { - string html = await GetUrlDataAsync(imdbUrl + "combined"); - mov.Id = Match(@"", html); - if (!string.IsNullOrEmpty(mov.Id)) - { - mov.Status = true; - mov.Title = Match(@"(IMDb \- )*(.*?) \(.*?", html, 2); - mov.OriginalTitle = Match(@"title-extra"">(.*?)<", html); - mov.Year = Match(@".*?\(.*?(\d{4}).*?\).*?", Match(@"(.*?)", html)); - mov.Rating = Match(@"(\d.\d)/10", html); - mov.Genres = MatchAll(@"(.*?)", Match(@"Genre.?:((.|\n)*?)(<\/div>|See more)", html)).Cast().ToList(); - mov.Plot = Match(@"Plot:\n
\n((.|\n)*?)( release = new Dictionary(); - string releasehtml = await GetUrlDataAsync("http://www.imdb.com/title/" + mov.Id + "/releaseinfo"); - foreach (string r in MatchAll(@"(.*?)", Match(@"\n*?(.*?)
", releasehtml))) - { - Match rd = new Regex(@"(.*?)\n*?.*?(.*?)", RegexOptions.Multiline).Match(r); - release[StripHTML(rd.Groups[1].Value.Trim())] = StripHTML(rd.Groups[2].Value.Trim()); - } - //mov.ReleaseDates = release; - - Dictionary aka = new Dictionary(); - List list = MatchAll(@".*?(.*?)", Match(@"\n*?(.*?)
", releasehtml)); - foreach (string r in list) - { - Match rd = new Regex(@"\n*?.*?(.*?)\n*?.*?(.*?)", RegexOptions.Multiline).Match(r); - aka[StripHTML(rd.Groups[1].Value.Trim())] = StripHTML(rd.Groups[2].Value.Trim()); - } - mov.Aka = aka; - - - - } - //Get all media images - private static async Task> GetMediaImages(ImdbMovie mov) - { - List list = new List(); - string mediaurl = "http://www.imdb.com/title/" + mov.Id + "/mediaindex"; - string mediahtml = await GetUrlDataAsync(mediaurl); - int pagecount = MatchAll(@"", Match(@"(.*?)", mediahtml)).Count; - for (int p = 1; p <= pagecount + 1; p++) - { - mediahtml = await GetUrlDataAsync(mediaurl + "?page=" + p); - foreach (Match m in new Regex(@"src=""(.*?)""", RegexOptions.Multiline).Matches(Match(@"
(.*?)
", mediahtml))) - { - String image = m.Groups[1].Value; - list.Add(Regex.Replace(image, @"_V1\..*?.jpg", "_V1._SY0.jpg")); - } - } - return list; - } - //Get Recommended Titles - private static async Task> GetRecommendedTitlesAsync(ImdbMovie mov) - { - List list = new List(); - string recUrl = "http://www.imdb.com/widget/recommendations/_ajax/get_more_recs?specs=p13nsims%3A" + mov.Id; - string json = await GetUrlDataAsync(recUrl); - return MatchAll(@"title=\\""(.*?)\\""", json); - } - /*******************************[ Helper Methods ]********************************/ - //Match single instance - private static string Match(string regex, string html, int i = 1) - { - var m = new Regex(regex, RegexOptions.Multiline).Match(html); - return m.Groups[i].Value.Trim(); - } - //Match all instances and return as List - private static List MatchAll(string regex, string html, int i = 1) - { - List list = new List(); - foreach (Match m in new Regex(regex, RegexOptions.Multiline).Matches(html)) - list.Add(m.Groups[i].Value.Trim()); - return list; - } - //Strip HTML Tags - private static string StripHTML(string inputString) - { - return Regex.Replace(inputString, @"<.*?>", string.Empty); - } - //Get URL Data - private static async Task GetUrlDataAsync(string url) - { - using (var http = new HttpClient()) - { - http.AddFakeHeaders(); - return await http.GetStringAsync(url); - } - } - } -} \ No newline at end of file diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index d18d94a9..8118e011 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -12,11 +12,11 @@ using System.Text.RegularExpressions; using System.Net; using Discord.WebSocket; using NadekoBot.Modules.Searches.Models; -using NadekoBot.Modules.Searches.IMDB; using System.Collections.Generic; using ImageProcessorCore; using NadekoBot.Extensions; using System.IO; +using NadekoBot.Modules.Searches.Commands.OMDB; namespace NadekoBot.Modules.Searches { @@ -66,10 +66,6 @@ $@"🌍 **Weather for** 【{obj["target"]}】 await channel.SendMessageAsync(result).ConfigureAwait(false); } - //todo move to omdb - // | - // v - //{"Title":"Shutter Island","Year":"2010","Rated":"R","Released":"19 Feb 2010","Runtime":"138 min","Genre":"Mystery, Thriller","Director":"Martin Scorsese","Writer":"Laeta Kalogridis (screenplay), Dennis Lehane (novel)","Actors":"Leonardo DiCaprio, Mark Ruffalo, Ben Kingsley, Max von Sydow","Plot":"In 1954, a U.S. marshal investigates the disappearance of a murderess who escaped from a hospital for the criminally insane.","Language":"English, German","Country":"USA","Awards":"8 wins & 59 nominations.","Poster":"https://images-na.ssl-images-amazon.com/images/M/MV5BMTMxMTIyNzMxMV5BMl5BanBnXkFtZTcwOTc4OTI3Mg@@._V1_SX300.jpg","Metascore":"63","imdbRating":"8.1","imdbVotes":"798,447","imdbID":"tt1130884","Type":"movie","Response":"True"} [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] public async Task Imdb(IUserMessage umsg, [Remainder] string query = null) @@ -78,21 +74,14 @@ $@"🌍 **Weather for** 【{obj["target"]}】 if (!(await ValidateQuery(channel, query).ConfigureAwait(false))) return; await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false); - string result; - try - { - var movie = await ImdbScraper.ImdbScrape(query, true); - if (movie.Status) result = movie.ToString(); - else result = "Failed to find that movie."; - } - catch (Exception ex) + + var movie = await OmdbProvider.FindMovie(query); + if (movie == null) { await channel.SendMessageAsync("Failed to find that movie.").ConfigureAwait(false); - _log.Warn(ex); return; } - - await channel.SendMessageAsync(result.ToString()).ConfigureAwait(false); + await channel.SendMessageAsync(movie.ToString()).ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] diff --git a/src/NadekoBot/Resources/CommandStrings.Designer.cs b/src/NadekoBot/Resources/CommandStrings.Designer.cs index 787a437f..0dfd896a 100644 --- a/src/NadekoBot/Resources/CommandStrings.Designer.cs +++ b/src/NadekoBot/Resources/CommandStrings.Designer.cs @@ -3111,7 +3111,7 @@ namespace NadekoBot.Resources { } /// - /// Looks up a localized string similar to imdb. + /// Looks up a localized string similar to imdb omdb. /// public static string imdb_cmd { get { @@ -3120,7 +3120,7 @@ namespace NadekoBot.Resources { } /// - /// Looks up a localized string similar to Queries imdb for movies or series, show first result.. + /// Looks up a localized string similar to Queries omdb for movies or series, show first result.. /// public static string imdb_desc { get { diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index 55d78219..753dea51 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -2044,10 +2044,10 @@ `~ani aquarion evol` - imdb + imdb omdb - Queries imdb for movies or series, show first result. + Queries omdb for movies or series, show first result. `~imdb Batman vs Superman`