forked from RPCS3/discord-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPsnMetaExtensions.cs
47 lines (40 loc) · 1.67 KB
/
PsnMetaExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Extensions.Caching.Memory;
using PsnClient.POCOs;
namespace CompatBot.Utils;
public static class PsnMetaExtensions
{
private static readonly MemoryCache ParsedData = new(new MemoryCacheOptions {ExpirationScanFrequency = TimeSpan.FromHours(1)});
private static readonly TimeSpan CacheDuration = TimeSpan.FromDays(1);
internal static List<(string resolution, string aspectRatio)> GetSupportedResolutions(this TitleMeta meta)
=> GetSupportedResolutions(meta.Resolution);
internal static List<(string resolution, string aspectRatio)> GetSupportedResolutions(string resolutionList)
{
if (ParsedData.TryGetValue(resolutionList, out List<(string, string)>? result) && result is not null)
return result;
var resList = resolutionList
.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
.Select(Convert)
.ToList();
ParsedData.Set(resolutionList, resList, CacheDuration);
return resList;
}
private static (string resolution, string aspectRatio) Convert(string verticalRes)
=> verticalRes.ToUpper() switch
{
"480SQ" => ("720x480", "4:3"),
"576SQ" => ("720x576", "4:3"),
"480" => ("720x480", "16:9"),
"576" => ("720x576", "16:9"),
"720" => ("1280x720", "16:9"),
"1080" => ("1920x1080", "16:9"),
#if DEBUG
_ => throw new InvalidDataException($"Unknown resolution {verticalRes} in PSN meta data"),
#else
_ => (verticalRes, "16:9"),
#endif
};
}