/// <summary> /// Fetches the images. /// </summary> /// <param name="game">The game.</param> /// <param name="mediaType">Type of the media.</param> /// <param name="type">The type.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>Task{IEnumerable{RemoteImageInfo}}.</returns> private async Task <IEnumerable <RemoteImageInfo> > FetchImages(Game game, EmuMoviesMediaTypes mediaType, ImageType type, CancellationToken cancellationToken) { var sessionId = await Plugin.Instance.GetEmuMoviesToken(cancellationToken); var list = new List <RemoteImageInfo>(); if (sessionId == null) { return(list); } var url = string.Format(EmuMoviesUrls.Search, WebUtility.UrlEncode(game.Name), GetEmuMoviesPlatformFromGameSystem(game.GameSystem), mediaType, sessionId); using (var response = await _httpClient.SendAsync(new HttpRequestOptions { Url = url, CancellationToken = cancellationToken, ResourcePool = Plugin.Instance.EmuMoviesSemiphore }, "GET").ConfigureAwait(false)) { using (var stream = response.Content) { var doc = new XmlDocument(); doc.Load(stream); if (doc.HasChildNodes) { var nodes = doc.SelectNodes("Results/Result"); if (nodes != null) { foreach (XmlNode node in nodes) { if (node != null && node.Attributes != null) { var urlAttribute = node.Attributes["URL"]; if (urlAttribute != null && !string.IsNullOrEmpty(urlAttribute.Value)) { list.Add(new RemoteImageInfo { ProviderName = Name, Type = type, Url = urlAttribute.Value }); } } } } } } } return(list); }
/// <summary> /// Fetches the images. /// </summary> /// <param name="game">The game.</param> /// <param name="mediaType">Type of the media.</param> /// <param name="type">The type.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>Task{IEnumerable{RemoteImageInfo}}.</returns> private async Task<IEnumerable<RemoteImageInfo>> FetchImages(Game game, EmuMoviesMediaTypes mediaType, ImageType type, CancellationToken cancellationToken) { var sessionId = await Plugin.Instance.GetEmuMoviesToken(cancellationToken); var list = new List<RemoteImageInfo>(); if (sessionId == null) return list; var url = string.Format(EmuMoviesUrls.Search, HttpUtility.UrlEncode(game.Name), GetEmuMoviesPlatformFromGameSystem(game.GameSystem), mediaType, sessionId); using (var stream = await _httpClient.Get(url, Plugin.Instance.EmuMoviesSemiphore, cancellationToken).ConfigureAwait(false)) { var doc = new XmlDocument(); doc.Load(stream); if (doc.HasChildNodes) { var nodes = doc.SelectNodes("Results/Result"); if (nodes != null) { foreach (XmlNode node in nodes) { if (node != null && node.Attributes != null) { var urlAttribute = node.Attributes["URL"]; if (urlAttribute != null && !string.IsNullOrEmpty(urlAttribute.Value)) { list.Add(new RemoteImageInfo { ProviderName = Name, Type = type, Url = urlAttribute.Value }); } } } } } } return list; }
public async Task <List <string> > FetchImages(string search, string system, EmuMoviesMediaTypes mediaType) { if (string.IsNullOrWhiteSpace(sessionId)) { sessionId = GetEmuMoviesToken(); } List <string> list = new List <string>(); try { if (sessionId == null) { return(list); } var url = string.Format(EmuMoviesUrls.Search, HttpUtility.UrlEncode(search), system, mediaType, sessionId); Debug.WriteLine(url); using (var wc = new System.Net.WebClient()) { string contents = wc.DownloadString(url); EmuMoviesClasses.Results result = contents.XmlDeserializeFromString <EmuMoviesClasses.Results>(); if (bool.Parse(result.Result.Found)) { list.Add(result.Result.URL); } } } catch (Exception e) { Debug.WriteLine(e.Message); } return(list); }