-
Notifications
You must be signed in to change notification settings - Fork 0
/
blocktube-list-deduplicator.jshell
50 lines (45 loc) · 1.7 KB
/
blocktube-list-deduplicator.jshell
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
// Clear duplicated records
// Usage: jshell -v -R-Dlist=list.txt blocktube-list-deduplicator.jshell
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.LinkedHashMap;
String fileName = System.getProperty("list");
int count = 0;
var map = new LinkedHashMap<>();
try (var br = new BufferedReader(new FileReader(fileName))) {
for (String line; (line = br.readLine()) != null; ) {
try {
String channelName;
String channelId;
if (line.startsWith("// Blocked")) {
int start = line.indexOf("(") + 1;
int end = line.indexOf(")");
channelName = line.substring(start, end);
channelId = br.readLine();
map.put(channelId, channelName);
br.readLine();
count++;
}
} catch (Exception e) {
System.out.println("Error " + e + " with line \n" + line);
}
}
}
System.out.println("Count of channels: " + count + ". After deduplicate: " + map.size());
var sb = new StringBuilder(
"// BlockTube https://chrome.google.com/webstore/detail/blocktube/bbeaicapbccfllodepmimpkgecanonai")
sb.append("\n");
for (var entry : map.entrySet()) {
sb.append("\n").append("// Blocked by context menu (").append(entry.getValue()).append(")");
sb.append("\n").append(entry.getKey());
sb.append("\n");
}
var deduplicatedFilename = "deduplicated-" + fileName;
var writer = new BufferedWriter(new FileWriter(deduplicatedFilename));
writer.write(sb.toString());
writer.close();
System.out.println("Created file: " + deduplicatedFilename);
/exit