-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathnp-strings-extract.py
72 lines (55 loc) · 2.16 KB
/
np-strings-extract.py
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
#!/usr/bin/env python3
# adapted from https://github.com/gitanuj/nowplayinghistory/blob/master/script.py
import os
import sys
def dump_strings_file(filepath, line):
file = open(filepath, "w")
file.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
file.write("<resources>\n")
file.write(line)
file.write("</resources>\n")
def main(decompiledDir, stringNameToExtract, outputFileSuffix):
# stringNameToExtract = "song_format_string" for pixel now playing
# or "auto_shazam_now_playing" for Shazam
fsSet = set()
resDir = os.path.join(decompiledDir, "res")
prevLang = "00"
prevFs = ""
for folder in os.listdir(resDir):
path = os.path.join(resDir, folder)
if not os.path.isdir(path):
continue
for file in os.listdir(path):
if file != "strings.xml":
continue
filepath = os.path.join(path, file)
for line in open(filepath):
if stringNameToExtract in line:
i1 = line.find(">")
i2 = line.find("</")
fs = line[i1+1:i2]
fsSet.add(fs)
lang = folder.split('-')[0]
shouldBreak = False
if prevLang == lang and prevFs == fs:
shouldBreak = True
prevFs = fs
prevLang = lang
if shouldBreak:
break
outdir = os.path.join("../app/src/main/res", folder)
os.makedirs(outdir, exist_ok=True)
dump_strings_file(os.path.join(outdir, f"strings-{outputFileSuffix}.xml"), line)
break
print("val fs = arrayOf(")
for item in fsSet:
print('"'+item+'",')
print(")")
if __name__ == "__main__":
if len(sys.argv) != 4:
print("Usage: python np-strings-extract.py <decompiled-dir> <string-name-to-extract> <output-file-suffix>")
sys.exit(1)
decompiledDir = sys.argv[1]
stringNameToExtract = sys.argv[2]
outputFileSuffix = sys.argv[3]
main(decompiledDir, stringNameToExtract, outputFileSuffix)