From 3612f46940131d9ed5e45b9ecf96f9ea61b7ba1e Mon Sep 17 00:00:00 2001 From: Marcus Sanchez <9328629+sharkusmanch@users.noreply.github.com> Date: Tue, 19 Apr 2022 10:56:00 -0700 Subject: [PATCH] V1.0.5 (#29) Fix search escaping --- extension.yaml | 2 +- manifest.yaml | 6 ++++++ src/PCGWClient.cs | 15 ++++++++++----- src/PCGamingWikiHTMLParser.cs | 3 --- src/PCGamingWikiMetadata.csproj | 2 +- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/extension.yaml b/extension.yaml index ac6ff11..fec15ef 100644 --- a/extension.yaml +++ b/extension.yaml @@ -1,7 +1,7 @@ Id: PCGamingWikiMetadata_c038558e-427b-4551-be4c-be7009ce5a8d Name: PCGamingWiki Metadata Provider Author: sharkusmanch -Version: 1.0.4 +Version: 1.0.5 Module: PCGamingWikiMetadata.dll Type: MetadataProvider Icon: icon.png diff --git a/manifest.yaml b/manifest.yaml index 2fa8e85..c98966a 100644 --- a/manifest.yaml +++ b/manifest.yaml @@ -1,5 +1,11 @@ AddonId: PCGamingWikiMetadata_c038558e-427b-4551-be4c-be7009ce5a8d Packages: +- Version: 1.0.5 + RequiredApiVersion: 6.2.2 + ReleaseDate: 2022-04-18 + PackageUrl: https://github.com/sharkusmanch/playnite-pcgamingwiki-metadata-provider/releases/download/v1.0.5/PCGamingWiki_Metadata_Provider_v1.0.5.pext + Changelog: + - Fix search matching when game title contains special characters - Version: 1.0.4 RequiredApiVersion: 6.2.2 ReleaseDate: 2022-04-12 diff --git a/src/PCGWClient.cs b/src/PCGWClient.cs index edfc2ed..f5df6a6 100644 --- a/src/PCGWClient.cs +++ b/src/PCGWClient.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using Newtonsoft.Json.Linq; using System.Linq; +using System.Text; namespace PCGamingWikiMetadata { @@ -19,6 +20,8 @@ public class PCGWClient public PCGWClient(MetadataRequestOptions options, PCGWGameController gameController) { client = new RestClient(baseUrl); + client.UserAgent = "Playnite"; + client.Encoding = Encoding.UTF8; this.options = options; this.gameController = gameController; } @@ -26,9 +29,10 @@ public PCGWClient(MetadataRequestOptions options, PCGWGameController gameControl public JObject ExecuteRequest(RestRequest request) { request.AddParameter("format", "json", ParameterType.QueryString); - request.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; }; + var fullUrl = client.BuildUri(request); logger.Info(fullUrl.ToString()); + var response = client.Execute(request); if (response.ErrorException != null) @@ -44,9 +48,7 @@ public JObject ExecuteRequest(RestRequest request) private string NormalizeSearchString(string search) { - string updated = search.Replace("-", " "); - - return updated; + return search.Replace("-", " "); } public List SearchGames(string searchName) @@ -55,11 +57,14 @@ public List SearchGames(string searchName) logger.Info(searchName); var request = new RestRequest("/", Method.GET); + request.AddHeader("Content-Type", "application/x-www-form-urlencoded"); + request.AddHeader("Accept", "application/json, text/json, text/x-json"); + request.AddParameter("action", "query", ParameterType.QueryString); request.AddParameter("list", "search", ParameterType.QueryString); request.AddParameter("srlimit", 300, ParameterType.QueryString); request.AddParameter("srwhat", "title", ParameterType.QueryString); - request.AddParameter("srsearch", NormalizeSearchString(searchName), ParameterType.QueryString); + request.AddParameter("srsearch", $"\"{NormalizeSearchString(searchName)}\"", ParameterType.QueryString); try { diff --git a/src/PCGamingWikiHTMLParser.cs b/src/PCGamingWikiHTMLParser.cs index eb9998f..a3c4c56 100644 --- a/src/PCGamingWikiHTMLParser.cs +++ b/src/PCGamingWikiHTMLParser.cs @@ -56,7 +56,6 @@ private IList SelectTableRowsByClass(string tableId, string rowClass) private void ParseVideo() { var rows = SelectTableRowsByClass("table-settings-video", "template-infotable-body table-settings-video-body-row"); - logger.Debug($"Video row count: {rows.Count}"); string feature = ""; string rating = ""; @@ -68,11 +67,9 @@ private void ParseVideo() { case "table-settings-video-body-parameter": feature = child.FirstChild.InnerText.Trim(); - logger.Debug(feature); break; case "table-settings-video-body-rating": rating = child.FirstChild.Attributes["title"].Value; - logger.Debug(rating); break; } } diff --git a/src/PCGamingWikiMetadata.csproj b/src/PCGamingWikiMetadata.csproj index 24f3e92..8012cbd 100644 --- a/src/PCGamingWikiMetadata.csproj +++ b/src/PCGamingWikiMetadata.csproj @@ -9,7 +9,7 @@ - +