From 7827dfd27cf9142b9713dc6bb581be823fd46915 Mon Sep 17 00:00:00 2001 From: Marcus Sanchez <9328629+sharkusmanch@users.noreply.github.com> Date: Tue, 31 Aug 2021 10:21:51 -0700 Subject: [PATCH] V0.2.1 - Company and link fixes * Fix company parsing * Cleanup link parsing. Properly name GOG Database and Official Site links --- extension.yaml | 2 +- src/PCGamingWikiHTMLParser.cs | 43 +++++++++++++++++++++-------------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/extension.yaml b/extension.yaml index bff64b5..9092449 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: 0.2.0 +Version: 0.2.1 Module: PCGamingWikiMetadata.dll Type: MetadataProvider Icon: icon.png diff --git a/src/PCGamingWikiHTMLParser.cs b/src/PCGamingWikiHTMLParser.cs index 6b5c5ea..03519b7 100644 --- a/src/PCGamingWikiHTMLParser.cs +++ b/src/PCGamingWikiHTMLParser.cs @@ -50,13 +50,7 @@ public void ApplyGameMetadata() key = text; break; case "template-infobox-icons": - foreach (var c in child.ChildNodes) - { - string[] linkTitle = c.Attributes["Title"].Value.Split(' '); - string title = linkTitle[linkTitle.Length - 1]; - string url = c.ChildNodes[0].Attributes["href"].Value; - this.game.Links.Add(new Playnite.SDK.Models.Link(title, url)); - } + AddLinks(child); break; case "template-infobox-info": if (text == "") @@ -104,6 +98,29 @@ private void ApplyReleaseDate(string platform, string releaseDate) } } + private void AddLinks(HtmlNode icons) + { + string url; + foreach (var c in icons.ChildNodes) + { + url = c.ChildNodes[0].Attributes["href"].Value; + switch (c.Attributes["Title"].Value) + { + case var title when new Regex(@"^Official site$").IsMatch(title): + this.game.Links.Add(new Playnite.SDK.Models.Link("Official site", url)); + break; + case var title when new Regex(@"GOG Database$").IsMatch(title): + this.game.Links.Add(new Playnite.SDK.Models.Link("GOG Database", url)); + break; + default: + string[] linkTitle = c.Attributes["Title"].Value.Split(' '); + string titleComp = linkTitle[linkTitle.Length - 1]; + this.game.Links.Add(new Playnite.SDK.Models.Link(titleComp, url)); + break; + } + } + } + private void AddCompany(HtmlNode node, IList list) { string company = ParseCompany(node); @@ -117,16 +134,8 @@ private void AddCompany(HtmlNode node, IList list) private string ParseCompany(HtmlNode node) { - // foreach (var c in node.ChildNodes) - // { - // var attr = c.Attributes["target"]; - // if (attr != null) - // { - // return c.InnerText; - // } - // } - - return node.ChildNodes[1].InnerText; + var nodes = node.SelectNodes("./a"); + return nodes[nodes.Count - 1].InnerText; } } }