Skip to content

Commit

Permalink
V0.2.1 - Company and link fixes
Browse files Browse the repository at this point in the history
* Fix company parsing

* Cleanup link parsing. Properly name GOG Database and Official Site links
  • Loading branch information
sharkusmanch authored Aug 31, 2021
1 parent 7a7d0e1 commit 7827dfd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
2 changes: 1 addition & 1 deletion extension.yaml
Original file line number Diff line number Diff line change
@@ -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
43 changes: 26 additions & 17 deletions src/PCGamingWikiHTMLParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "")
Expand Down Expand Up @@ -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<string> list)
{
string company = ParseCompany(node);
Expand All @@ -117,16 +134,8 @@ private void AddCompany(HtmlNode node, IList<string> 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;
}
}
}

0 comments on commit 7827dfd

Please sign in to comment.