/// <summary> /// Search a title and return a list back /// </summary> /// <param name="title"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public static async Task <List <string> > Search_GetSeries_list(string title, CancellationToken cancellationToken) { List <string> result = new List <string>(); string result_text = null; string WebContent = await WebRequestAPI(string.Format(SearchLink, Uri.EscapeUriString(title))); int x = 0; while (result_text != "") { result_text = await One_line_regex(new Regex("<tr align=\"" + @"left(.*?)tr>"), WebContent, 1, x); if (result_text != "") { //get id string id = await One_line_regex(new Regex("class=\"entry" + @"(.*?)" + "\">"), result_text); string a_name = await One_line_regex(new Regex("#top\">" + @"(.*?)</a>"), result_text); if (await Equals_check.Compare_strings(a_name, title, cancellationToken)) { result.Add(id); return(result); } if (Int32.TryParse(id, out int n)) { result.Add(id); } } x++; } return(result); }
/// <summary> /// MyAnimeListAPI call to find a series /// </summary> /// <param name="title"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <string> FindSeries(string title, CancellationToken cancellationToken) { string aid = await Search_GetSeries(title, cancellationToken); if (!string.IsNullOrEmpty(aid)) { return(aid); } else { int x = 0; foreach (string a_name in anime_search_names) { if (await Equals_check.Compare_strings(a_name, title, cancellationToken)) { return(anime_search_ids[x]); } x++; } } aid = await Search_GetSeries(await Equals_check.Clear_name(title, cancellationToken), cancellationToken); if (!string.IsNullOrEmpty(aid)) { return(aid); } return(null); }
public async Task <MetadataResult <Series> > GetMetadata(SeriesInfo info, CancellationToken cancellationToken) { var result = new MetadataResult <Series>(); var aid = info.ProviderIds.GetOrDefault(ProviderNames.AniDb); if (string.IsNullOrEmpty(aid) && !string.IsNullOrEmpty(info.Name)) { aid = await Equals_check.Fast_xml_search(info.Name, info.Name, cancellationToken, true); if (string.IsNullOrEmpty(aid)) { aid = await Equals_check.Fast_xml_search(await Equals_check.Clear_name(info.Name, cancellationToken), await Equals_check.Clear_name(info.Name, cancellationToken), cancellationToken, true); } } if (!string.IsNullOrEmpty(aid)) { result.Item = new Series(); result.HasMetadata = true; result.Item.ProviderIds.Add(ProviderNames.AniDb, aid); var seriesDataPath = await GetSeriesData(_appPaths, _httpClient, aid, cancellationToken); FetchSeriesInfo(result, seriesDataPath, info.MetadataLanguage ?? "en"); } return(result); }
/// <summary> /// API call to search a title and return a list back /// </summary> /// <param name="title"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <List <string> > Search_GetSeries_list(string title, CancellationToken cancellationToken) { List <string> result = new List <string>(); RootObject WebContent = await WebRequestAPI(SearchLink.Replace("{0}", title)); foreach (Medium media in WebContent.data.Page.media) { //get id try { if (await Equals_check.Compare_strings(media.title.romaji, title, cancellationToken)) { result.Add(media.id.ToString()); } if (await Equals_check.Compare_strings(media.title.english, title, cancellationToken)) { result.Add(media.id.ToString()); } //Disabled due to false result. /*if (await Task.Run(() => Equals_check.Compare_strings(media.title.native, title))) * { * result.Add(media.id.ToString()); * }*/ } catch (Exception) { } } return(result); }
/// <summary> /// MyAnimeListAPI call to search the right series /// </summary> /// <param name="title"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public static async Task <string> Search_GetSeries(string title, CancellationToken cancellationToken) { anime_search_names.Clear(); anime_search_ids.Clear(); string result = null; string result_text = null; string WebContent = await WebRequestAPI(string.Format(SearchLink, Uri.EscapeUriString(title)), Plugin.Instance.Configuration.MyAnimeList_API_Name, Plugin.Instance.Configuration.MyAnimeList_API_Pw); int x = 0; while (result_text != "") { result_text = await one_line_regex(new Regex(@"<entry>(.*?)<\/entry>"), WebContent, 1, x); if (result_text != "") { //get id string id = await one_line_regex(new Regex(@"<id>(.*?)<\/id>"), result_text); string a_name = await one_line_regex(new Regex(@"<title>(.*?)<\/title>"), result_text); string b_name = await one_line_regex(new Regex(@"<english>(.*?)<\/english>"), result_text); string c_name = await one_line_regex(new Regex(@"<synonyms>(.*?)<\/synonyms>"), result_text); if (Equals_check.Compare_strings(a_name, title)) { result = id; return(result); } if (Equals_check.Compare_strings(b_name, title)) { result = id; return(result); } foreach (string d_name in c_name.Split(';')) { if (Equals_check.Compare_strings(d_name, title)) { result = id; return(result); } } int n; if (Int32.TryParse(id, out n)) { anime_search_names.Add(a_name); anime_search_ids.Add(id); } } x++; } return(result); }
/// <summary> /// API call to search a title and return the right one back /// </summary> /// <param name="title"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public static async Task <string> Search_GetSeries(string title, CancellationToken cancellationToken) { anime_search_names.Clear(); anime_search_ids.Clear(); string result = null; string result_text = null; string WebContent = await WebRequestAPI(string.Format(SearchLink, title)); int x = 0; while (result_text != "") { result_text = await One_line_regex(new Regex("<th scope=\"row\" class=\"showpop\" data-width=\"200\"" + @".*?>(.*)<\/th>"), WebContent, 1, x); if (result_text != "") { //get id int _x = 0; string a_name = null; while (a_name != "") { try { string id = await One_line_regex(new Regex(@"anime\/(.*?),"), result_text); a_name = Regex.Replace(await One_line_regex(new Regex(@"((<a|<d).*?>)(.*?)(<\/a>|<\/div>)"), result_text, 3, _x), "<.*?>", String.Empty); if (a_name != "") { if (await Task.Run(() => Equals_check.Compare_strings(a_name, title))) { return(id); } int n; if (Int32.TryParse(id, out n)) { anime_search_names.Add(a_name); anime_search_ids.Add(id); } } } catch (Exception) { } _x++; } } x++; } return(result); }
/// <summary> /// SEARCH Title /// </summary> public async Task <string> FindSeries(string title, CancellationToken cancellationToken) { string aid = await Search_GetSeries(title, cancellationToken); if (!string.IsNullOrEmpty(aid)) { return(aid); } aid = await Search_GetSeries(await Equals_check.Clear_name(title, cancellationToken), cancellationToken); if (!string.IsNullOrEmpty(aid)) { return(aid); } return(null); }
public async Task <MetadataResult <Series> > GetMetadata(SeriesInfo info, CancellationToken cancellationToken) { var animeId = info.ProviderIds.GetOrDefault(ProviderNames.AniDb); if (string.IsNullOrEmpty(animeId) && !string.IsNullOrEmpty(info.Name)) { animeId = await Equals_check.XmlFindId(info.Name, cancellationToken); } if (!string.IsNullOrEmpty(animeId)) { return(await GetMetadataForId(animeId, info, cancellationToken)); } return(new MetadataResult <Series>()); }
/// <summary> /// Search a title and return the right one back /// </summary> /// <param name="title"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public static async Task <string> Search_GetSeries(string title, CancellationToken cancellationToken, bool bettersearchresults = false) { anime_search_names.Clear(); anime_search_ids.Clear(); string result = null; string result_text = null; string WebContent = ""; if (bettersearchresults) { WebContent = await WebRequestAPI(string.Format(SearchLink, Uri.EscapeUriString(Equals_check.Half_string(title, 4, 60)))); } else { WebContent = await WebRequestAPI(string.Format(SearchLink, Uri.EscapeUriString(title))); } int x = 0; while (result_text != "") { result_text = await one_line_regex(new Regex("<tr align=\"" + @"left(.*?)tr>"), WebContent, 1, x); if (result_text != "") { //get id string id = await one_line_regex(new Regex("class=\"entry" + @"(.*?)" + "\">"), result_text); string a_name = await one_line_regex(new Regex("#top\">" + @"(.*?)</a>"), result_text); if (Equals_check.Compare_strings(a_name, title)) { result = id; return(result); } int n; if (Int32.TryParse(id, out n)) { anime_search_names.Add(a_name); anime_search_ids.Add(id); } } x++; } return(result); }
/// <summary> /// Search for anime with the given title. Attempts to fuzzy search by removing special characters /// </summary> /// <param name="title"></param> /// <returns></returns> public async Task <string> FindSeries(string title, CancellationToken cancellationToken) { MediaSearchResult result = await Search_GetSeries(title, cancellationToken); if (result != null) { return(result.id.ToString()); } result = await Search_GetSeries(await Equals_check.Clear_name(title, cancellationToken), cancellationToken); if (result != null) { return(result.id.ToString()); } return(null); }
public async Task <List <RemoteSearchResult> > GetSearchResultsByName(string name, SeriesInfo searchInfo, CancellationToken cancellationToken) { var imageProvider = new AniDbImageProvider(_appPaths); var results = new List <RemoteSearchResult>(); List <string> ids = await Equals_check.XmlSearch(name, cancellationToken); foreach (string id in ids) { var resultMetadata = await GetMetadataForId(id, searchInfo, cancellationToken); if (resultMetadata.HasMetadata) { var images = await imageProvider.GetImages(id, cancellationToken); results.Add(MetadataToRemoteSearchResult(resultMetadata, images)); } } return(results); }
/// <summary> /// MyAnimeListAPI call to search the series and return a list /// </summary> /// <param name="title"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <List <string> > Search_GetSeries_list(string title, CancellationToken cancellationToken) { List <string> result = new List <string>(); string result_text = null; //API if (!string.IsNullOrEmpty(Plugin.Instance.Configuration.MyAnimeList_API_Name) && !string.IsNullOrEmpty(Plugin.Instance.Configuration.MyAnimeList_API_Pw)) { string WebContent = await WebRequestAPI(string.Format(SearchLink, Uri.EscapeUriString(title)), cancellationToken, Plugin.Instance.Configuration.MyAnimeList_API_Name, Plugin.Instance.Configuration.MyAnimeList_API_Pw); int x = 0; while (result_text != "") { result_text = await One_line_regex(new Regex(@"<entry>(.*?)<\/entry>"), WebContent, 1, x); if (result_text != "") { //get id string id = await One_line_regex(new Regex(@"<id>(.*?)<\/id>"), result_text); string a_name = await One_line_regex(new Regex(@"<title>(.*?)<\/title>"), result_text); string b_name = await One_line_regex(new Regex(@"<english>(.*?)<\/english>"), result_text); string c_name = await One_line_regex(new Regex(@"<synonyms>(.*?)<\/synonyms>"), result_text); if (await Equals_check.Compare_strings(a_name, title, cancellationToken)) { result.Add(id); return(result); } if (await Equals_check.Compare_strings(b_name, title, cancellationToken)) { result.Add(id); return(result); } foreach (string d_name in c_name.Split(';')) { if (await Equals_check.Compare_strings(d_name, title, cancellationToken)) { result.Add(id); return(result); } } if (Int32.TryParse(id, out int n)) { result.Add(id); } } x++; } } else { //Fallback to Web string WebContent = await WebRequestAPI(string.Format(FallbackSearchLink, Uri.EscapeUriString(title)), cancellationToken); string regex_id = "-"; int x = 0; while (!string.IsNullOrEmpty(regex_id)) { regex_id = ""; regex_id = await One_line_regex(new Regex(@"(#revInfo(.*?)" + '"' + "(>(.*?)<))"), WebContent, 2, x); if (!string.IsNullOrEmpty(regex_id)) { try { int.Parse(regex_id); if (await Equals_check.Compare_strings(await One_line_regex(new Regex(@"(#revInfo(.*?)" + '"' + "(>(.*?)<))"), WebContent, 4, x), title, cancellationToken)) { result.Add(regex_id); return(result); } } catch (Exception) { //AnyLog } } x++; } } return(result); }
public async Task <MetadataResult <Series> > GetMetadata(SeriesInfo info, CancellationToken cancellationToken) { var result = new MetadataResult <Series>(); var aid = info.ProviderIds.GetOrDefault(ProviderNames.AniList); if (string.IsNullOrEmpty(aid) && !string.IsNullOrEmpty(info.Name)) { var search = await _api.Search(info.Name); foreach (var a in search) { if (string.IsNullOrEmpty(aid)) { if (Equals_check.Compare_strings(a.title_english, info.Name)) { aid = a.id.ToString(); } if (Equals_check.Compare_strings(a.title_japanese, info.Name)) { aid = a.id.ToString(); } if (Equals_check.Compare_strings(a.title_romaji, info.Name)) { aid = a.id.ToString(); } _log.Log(LogSeverity.Info, a.title_romaji + "vs" + info.Name); } } if (string.IsNullOrEmpty(aid)) { var cleaned = AniDbTitleMatcher.GetComparableName(Equals_check.clear_name(info.Name)); if (String.Compare(cleaned, info.Name, StringComparison.OrdinalIgnoreCase) != 0) { search = await _api.Search(cleaned); foreach (var b in search) { if (Equals_check.Compare_strings(b.title_english, info.Name)) { aid = b.id.ToString(); } if (Equals_check.Compare_strings(b.title_japanese, info.Name)) { aid = b.id.ToString(); } if (Equals_check.Compare_strings(b.title_romaji, info.Name)) { aid = b.id.ToString(); } } } } if (string.IsNullOrEmpty(aid)) { search = await _api.Search(Equals_check.clear_name(info.Name)); foreach (var b in search) { if (Equals_check.Compare_strings(b.title_english, info.Name)) { aid = b.id.ToString(); } if (Equals_check.Compare_strings(b.title_japanese, info.Name)) { aid = b.id.ToString(); } if (Equals_check.Compare_strings(b.title_romaji, info.Name)) { aid = b.id.ToString(); } } } } if (!string.IsNullOrEmpty(aid)) { result.Item = new Series(); result.HasMetadata = true; result.Item.ProviderIds.Add(ProviderNames.AniList, aid); var anime = await _api.GetAnime(aid); result.Item.Name = SelectName(anime, Plugin.Instance.Configuration.TitlePreference, info.MetadataLanguage ?? "en"); result.Item.Overview = anime.description; DateTime start; if (DateTime.TryParse(anime.start_date, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out start)) { result.Item.PremiereDate = start; } DateTime end; if (DateTime.TryParse(anime.end_date, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out end)) { result.Item.EndDate = end; } if (anime.genres != null) { foreach (var genre in anime.genres) { if (!string.IsNullOrEmpty(genre)) { result.Item.AddGenre(genre); } } GenreHelper.CleanupGenres(result.Item); } if (!string.IsNullOrEmpty(anime.image_url_lge)) { StoreImageUrl(aid, anime.image_url_lge, "image"); } if (!string.IsNullOrEmpty(anime.image_url_banner)) { StoreImageUrl(aid, anime.image_url_banner, "banner"); } if (string.IsNullOrEmpty(result.Item.Name)) { if (!string.IsNullOrEmpty(anime.title_romaji)) { result.Item.Name = anime.title_romaji; } } } return(result); }