forked from The-Graze/RobloxAudioChecker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
185 lines (145 loc) · 5.22 KB
/
Program.cs
File metadata and controls
185 lines (145 loc) · 5.22 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
using System.Text.Json;
namespace RobloxAssetChecker;
internal static partial class RobloxAssetChecker
{
private enum ReturnType
{
Public,
PublicArchived,
Moderated
}
private static readonly HttpClient _http = new HttpClient();
private const int BatchSize = 100;
private static void EnsureFile()
{
const string file = "audio.txt";
if (!File.Exists(file))
{
File.WriteAllText(file,
@"# Audio Scan List
# Format: ID - optional name
# Example:
123456789 - cool song
987654321 - background music
");
Console.WriteLine("Created audio.txt template");
}
}
private record AssetEntry(long Id, string? Label);
private static List<AssetEntry> ParseFile(IEnumerable<string> lines)
{
var seen = new HashSet<long>();
var results = new List<AssetEntry>();
foreach (var raw in lines)
{
var line = raw.Trim();
if (string.IsNullOrWhiteSpace(line) || line.StartsWith("#"))
continue;
var parts = line.Split(['-', ':'], 2);
if (!long.TryParse(parts[0].Trim(), out var id))
continue;
if (!seen.Add(id))
continue;
string? label = parts.Length > 1 ? parts[1].Trim() : null;
if (string.IsNullOrWhiteSpace(label))
label = null;
results.Add(new AssetEntry(id, label));
}
return results;
}
private static async Task Main()
{
Console.Clear();
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("Audio Asset Checker (API Version)");
Console.WriteLine(new string('-', 50));
EnsureFile();
var rawLines = await File.ReadAllLinesAsync("audio.txt");
var entries = ParseFile(rawLines);
Console.WriteLine($"Loaded {entries.Count} audio IDs\n");
var publicList = new List<AssetEntry>();
var archivedList = new List<AssetEntry>();
var missingList = new List<AssetEntry>();
for (int i = 0; i < entries.Count; i += BatchSize)
{
var batch = entries.Skip(i).Take(BatchSize).ToList();
var idList = string.Join(",", batch.Select(x => x.Id));
var url =
$"https://apis.roblox.com/toolbox-service/v1/items/details?assetIds={idList}";
string json;
try
{
json = await _http.GetStringAsync(url);
}
catch
{
Console.WriteLine("Request failed, skipping batch.");
continue;
}
using var doc = JsonDocument.Parse(json);
var returned = new HashSet<long>();
if (doc.RootElement.TryGetProperty("data", out var data))
{
foreach (var item in data.EnumerateArray())
{
var asset = item.GetProperty("asset");
var id = asset.GetProperty("id").GetInt64();
returned.Add(id);
var name = asset.GetProperty("name").GetString();
bool published = false;
if (item.TryGetProperty("fiatProduct", out var fiat) &&
fiat.TryGetProperty("published", out var pub))
{
published = pub.GetBoolean();
}
var entry = batch.FirstOrDefault(x => x.Id == id);
var label = entry.Label ?? name;
if (published)
publicList.Add(new AssetEntry(id, label));
else
archivedList.Add(new AssetEntry(id, label));
Console.WriteLine($"{id} -> {(published ? "Public" : "Archived")}");
}
}
foreach (var item in batch)
{
if (!returned.Contains(item.Id))
{
missingList.Add(item);
Console.WriteLine($"{item.Id} -> Moderated / Missing");
}
}
}
// =========================
// SAFE JSON BUILDER (FIX)
// =========================
string Escape(string s)
{
return s
.Replace("\\", "\\\\")
.Replace("\"", "\\\"")
.Replace("\n", "\\n")
.Replace("\r", "");
}
string BuildJson(List<AssetEntry> list)
{
return "[\n" + string.Join(",\n",
list.Select(x =>
x.Label is null
? $" {{ \"id\": {x.Id} }}"
: $" {{ \"id\": {x.Id}, \"label\": \"{Escape(x.Label)}\" }}"
)
) + "\n]";
}
var jsonOutput =
$@"{{
""public"": {BuildJson(publicList)},
""archived"": {BuildJson(archivedList)},
""missing"": {BuildJson(missingList)}
}}";
await File.WriteAllTextAsync("audio - Sorted.json", jsonOutput);
Console.WriteLine("\nDone! Saved to audio - Sorted.json");
}
private static string Format(AssetEntry e)
=> e.Label is null ? $"{e.Id}" : $"{e.Id} - {e.Label}";
}