Skip to content

Commit

Permalink
PCGW 1.4.2 for real - actually fixed bulk import matching on URL enco…
Browse files Browse the repository at this point in the history
…ded slugs
  • Loading branch information
Jeshibu committed Jan 21, 2025
1 parent 5e47747 commit f2857f0
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 21 deletions.
6 changes: 3 additions & 3 deletions manifests/Metadata_PCGamingWiki.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@ Packages:
- Development taken over by Jeshibu for now
- Version: 1.4.2
RequiredApiVersion: 6.11.0
ReleaseDate: 2025-01-21
ReleaseDate: 2025-01-22
PackageUrl: https://github.com/Jeshibu/PlayniteExtensions/releases/download/2025-01-18/PCGamingWikiMetadata_1_4_2.pext
Changelog:
- Fixed getting no results on search
- Fixed getting no results in search
- Fixed property import for series targeting the publishers field by default
- Property import names now take the prefix setting checkbox into account
- Made property import gracefully handle URL escaped PCGW links to match on
- "Made property import gracefully handle URL encoded PCGW links to match on. If you have PCGW links with %20 in the URLs you might want to run any bulk property import you've run in the past few days again."
34 changes: 34 additions & 0 deletions source/PCGamingWikiMetadata.Tests/MatchOnUrlEscapedSlugsTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using PCGamingWikiBulkImport;
using Playnite.SDK.Models;
using PlayniteExtensions.Common;
using PlayniteExtensions.Metadata.Common;
using System.Collections.ObjectModel;
using Xunit;

namespace PCGamingWikiMetadata.Tests
{
public class MatchOnUrlEscapedSlugsTest
{
[Fact]
public void NormalSlugMatchesEscapedSlug()
{
var libraryGame = new Game("Vivisector")
{
Links = new ObservableCollection<Link>
{
new Link("PCGamingWiki", "https://www.pcgamingwiki.com/wiki/Vivisector%20-%20Beast%20Within")
}
};

var matchHelper = new GameMatchingHelper(new PCGamingWikiIdUtility(), 1);
matchHelper.Prepare(new[] { libraryGame }, default);

var slug = "Vivisector - Beast Within".TitleToSlug();
var expectedId = (ExternalDatabase.PCGamingWiki, PCGamingWikiIdUtility.SlugToId(slug));

Assert.True(matchHelper.TryGetGamesById(expectedId, out var games));

Assert.NotEmpty(games);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,6 @@ protected override string GetGameIdFromUrl(string url)
return null;
}

protected override string GetIdFromGameLibrary(Guid libraryPluginId, string gameId)
{
var db = DatabaseIdUtility.GetDatabaseFromPluginId(libraryPluginId);
if (db == ExternalDatabase.None)
return null;

return IdToString(db, gameId);
}

private static string IdToString(ExternalDatabase db, string id) => $"{db}:{id}";

protected override PCGamingWikiSelectedValues SelectGameProperty()
Expand Down
16 changes: 12 additions & 4 deletions source/PCGamingWikiMetadata/BulkImport/PCGamingWikiIdUtility.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using PlayniteExtensions.Common;
using System;
using System.Collections.Generic;
using System.Net;
using System.Text.RegularExpressions;

namespace PCGamingWikiBulkImport
{
public class PCGamingWikiIdUtility : SingleExternalDatabaseIdUtility
{
private readonly Regex PCGamingWikiUrlRegex = new Regex(@"^https?://(www\.)?pcgamingwiki\.com/(api/appid\.php\?appid=(?<steamId>[0-9]+)|wiki/(?<title>[^?#]+))", RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase);
private readonly Regex PCGamingWikiUrlRegex = new Regex(@"^https?://(www\.)?pcgamingwiki\.com/(api/appid\.php\?appid=(?<steamId>[0-9]+)|wiki/(?<slug>[^?#]+))", RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase);

public override ExternalDatabase Database { get; } = ExternalDatabase.PCGamingWiki;

Expand All @@ -22,15 +23,22 @@ public override (ExternalDatabase Database, string Id) GetIdFromUrl(string url)
if (!match.Success)
return (ExternalDatabase.None, null);

var titleGroup = match.Groups["title"];
if (titleGroup.Success)
return (ExternalDatabase.PCGamingWiki, titleGroup.Value);
var slugGroup = match.Groups["slug"];
if (slugGroup.Success)
return (ExternalDatabase.PCGamingWiki, SlugToId(slugGroup.Value));

var steamIdGroup = match.Groups["steamId"];
if (steamIdGroup.Success)
return (ExternalDatabase.Steam, steamIdGroup.Value);

return (ExternalDatabase.None, null);
}

/// <summary>
/// Convert a wiki URL slug to a universal ID - used to convert old format PCGW slugs that were just the titles URL escaped to something equatable to the current format
/// </summary>
/// <param name="slug"></param>
/// <returns></returns>
public static string SlugToId(string slug) => WebUtility.UrlDecode(slug).Replace(' ', '_');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private GameDetails ToGameDetails(CargoResultGame g)
var slug = name.TitleToSlug();
var game = new GameDetails
{
Id = slug,
Id = PCGamingWikiIdUtility.SlugToId(slug),
Names = new List<string> { name },
Url = slug.SlugToUrl(),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ protected virtual TSearchItem SelectGameProperty()

protected abstract string GetGameIdFromUrl(string url);

protected virtual string GetIdFromGameLibrary(Guid libraryPluginId, string gameId) => null;

private GamePropertyImportViewModel PromptGamePropertyImportUserApproval(TSearchItem selectedItem, List<GameDetails> gamesToMatch)
{
var importSetting = GetPropertyImportSetting(selectedItem, out string propName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ protected override PropertyImportSetting GetPropertyImportSetting(SteamProperty
};
}

protected override string GetIdFromGameLibrary(Guid libraryPluginId, string gameId) => steamIdUtility.GetDatabaseFromPluginId(libraryPluginId) == ExternalDatabase.Steam ? gameId : null;

private static PropertyImportTarget GetTarget(string param)
{
switch (param)
Expand Down

0 comments on commit f2857f0

Please sign in to comment.