Skip to content

Commit

Permalink
Fix: GOG metadata download not working after latest website redesign
Browse files Browse the repository at this point in the history
  • Loading branch information
JosefNemec committed Oct 1, 2018
1 parent 6caaa41 commit bc9461d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 28 deletions.
11 changes: 10 additions & 1 deletion source/Playnite/Metadata/MetadataDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,16 @@ private GameMetadata ProcessDownload(Game game, ref GameMetadata data)
{
if (data == null)
{
data = GetMetadataDownloader(game.PluginId)?.GetMetadata(game);
var downloader = GetMetadataDownloader(game.PluginId);
try
{
data = downloader?.GetMetadata(game);
}
catch (Exception e) when (!PlayniteEnvironment.ThrowAllErrors)
{
logger.Error(e, $"Failed to download metadat from plugin downloader.");
data = null;
}
}

return data;
Expand Down
13 changes: 6 additions & 7 deletions source/Plugins/GogLibrary/GOGMetadataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,16 @@ internal GogGameMetadata UpdateGameWithMetadata(Game game)

if (metadata.StoreDetails != null)
{
game.Genres = new ComparableList<string>(metadata.StoreDetails.genres.Select(a => a.name));
game.Developers = new ComparableList<string>() { metadata.StoreDetails.developer.name };
game.Publishers = new ComparableList<string>() { metadata.StoreDetails.publisher.name };
game.CommunityScore = metadata.StoreDetails.rating != 0 ? metadata.StoreDetails.rating * 2 : (int?)null;
game.Genres = new ComparableList<string>(metadata.StoreDetails.genres?.Select(a => a.name));
game.Tags = new ComparableList<string>(metadata.StoreDetails.tags?.Select(a => a.name));
game.Developers = new ComparableList<string>(metadata.StoreDetails.developers.Select(a => a.name));
game.Publishers = new ComparableList<string>() { metadata.StoreDetails.publisher };

var cultInfo = new CultureInfo("en-US", false).TextInfo;
game.Tags = new ComparableList<string>(metadata.StoreDetails.features?.Select(a => cultInfo.ToTitleCase(a.title)));

if (game.ReleaseDate == null && metadata.StoreDetails.releaseDate != null)
if (game.ReleaseDate == null && metadata.StoreDetails.globalReleaseDate != null)
{
game.ReleaseDate = DateTimeOffset.FromUnixTimeSeconds(metadata.StoreDetails.releaseDate.Value).DateTime;
game.ReleaseDate = metadata.StoreDetails.globalReleaseDate;
}
}

Expand Down
19 changes: 6 additions & 13 deletions source/Plugins/GogLibrary/Models/StorePageResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,20 @@ public class StorePageResult
{
public class ProductDetails
{
public class Feature
{
public string title;
public string slug;
}

public class SluggedName
{
public string name;
public string slug;
}

public List<SluggedName> genres;
public List<Feature> features;
public SluggedName publisher;
public SluggedName developer;
public int? releaseDate;
public int id;
public int rating;
public List<SluggedName> tags;
public string publisher;
public List<SluggedName> developers;
public DateTime? globalReleaseDate;
public string id;
}

public ProductDetails gameProductData;
public ProductDetails cardProduct;
}
}
27 changes: 20 additions & 7 deletions source/Plugins/GogLibrary/Services/GogApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,37 @@ public StorePageResult.ProductDetails GetGameStoreData(string gameUrl)
}
}

var dataStarted = false;
var stringData = string.Empty;
foreach (var line in data)
{
var trimmed = line.TrimStart();
if (line.TrimStart().StartsWith("var gogData"))
if (line.TrimStart().StartsWith("window.productcardData"))
{
var stringData = trimmed.Substring(14).TrimEnd(';');
var desData = JsonConvert.DeserializeObject<StorePageResult>(stringData);
dataStarted = true;
stringData = trimmed.Substring(25).TrimEnd(';');
continue;
}

if (desData.gameProductData == null)
if (line.TrimStart().StartsWith("window.activeFeatures"))
{
var desData = JsonConvert.DeserializeObject<StorePageResult>(stringData);
if (desData.cardProduct == null)
{
return null;
}

return desData.gameProductData;
return desData.cardProduct;
}
}

throw new Exception("Failed to get store data from page, no data found. " + gameUrl);
if (dataStarted)
{
stringData += trimmed;
}
}

logger.Warn("Failed to get store data from page, no data found. " + gameUrl);
return null;
}

public ProductApiDetail GetGameDetails(string id)
Expand Down

0 comments on commit bc9461d

Please sign in to comment.