-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen_media_metadata.py
More file actions
525 lines (464 loc) · 19.7 KB
/
gen_media_metadata.py
File metadata and controls
525 lines (464 loc) · 19.7 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
#!/usr/bin/env python3
from tagem import TagemDB
from collections import Counter
import json
import magic
import base64
import os
import mimetype_utils
import re
mimetype_utils.load_cached_mimetypes("cached_mimetypes.json")
subtitle_langs:tuple = ("en","de")
FAKETAG_hassubtitles:int = 1234567890
tagemdb = TagemDB(user_id=4)
def get_files_directly_tagged(tagid:int):
return [x[0] for x in tagemdb.qry(f"SELECT file FROM file2tag WHERE tag={tagid}")]
def get_thumb_fp(fileid:int, tagids:list):
fp:str = fileid2alternative_thumbnail.get(fileid)
if fp is None:
if fileid not in (
1691872,7321,7315,7313,7309,7308, # Civilization 6
7059, # Civilization 5
2199868, # Ride of the Valkyries
27221,1726479, # Vikings (use tag thumbnail)
1526,1527,1528,27240,1532,1534,1720, # Santiano
1973848, # Holding out for a hero (orchestral cover)
1973838, # Firework (orchestral cover)
1746,1919276, # Spanish anthem
7177,7176,7175,7174,7173,7172,7171,7170,7169,7168,7167,7166,7165,7164,7163,7162,7161,7160,7159,7158,7157,7156,7155,7154,7153,7152,7151,7150,7149,7148,7147,7146,7145,7144,7143,7142, # Endless Space soundtrack
80899,1719645, # Medieval covers
3536811, # Retrowave (worse quality version of tag's cover image)
7190, # Roman Empire (worse quality version of tag's cover image)
3559968, # French socialist (same as tag's cover image)
7275,6309, # French socialist song from Les Miserables
):
fp_maybe:str = f"/media/vangelic/DATA/tagem_thumbnails__subdir/tagem_thumbnails/{fileid}"
if os.path.exists(fp_maybe):
if os.stat(fp_maybe).st_size != 169: # Youtube "Deleted" thumbnail
fp = fp_maybe
if not os.path.islink(f"/media/vangelic/DATA/static-server-files/links_to_used_tagem_thumbs/{fileid}"):
os.symlink(fp, f"/media/vangelic/DATA/static-server-files/links_to_used_tagem_thumbs/{fileid}")
else:
del fileid2alternative_thumbnail[fileid]
return fp
tagem_fileids:list = list(set(get_files_directly_tagged(237870)+get_files_directly_tagged(65574)+get_files_directly_tagged(239895)+get_files_directly_tagged(239896)+get_files_directly_tagged(239897)+get_files_directly_tagged(239898)+get_files_directly_tagged(239900)+get_files_directly_tagged(116236)+get_files_directly_tagged(3020)+get_files_directly_tagged(6810)+get_files_directly_tagged(239922)+get_files_directly_tagged(236111)+get_files_directly_tagged(239901)+get_files_directly_tagged(239902)+get_files_directly_tagged(239926)+get_files_directly_tagged(239923)+get_files_directly_tagged(240024)+[2200548,4900172,2199768,1985,2203575,2199933,4829561]))
# TODO: 55 Days in Peking: (sure there are other languages too) /media/vangelic/DATA/media/music/by-source/KarlSternau/Botho- Lucas Chor - 55 Tage in Peking _55 Days in Peking [Colonial Song 1900][+ English Translation]-m-GVAGyBZB4.m4a
tagem_fileid2skipfirstseconds:dict = {
"that fallout video intro":16.108312,
}
introduction_to_each_category:dict = {
969:1689587, # Roman Empire -> TV intro
116236:3537631, # Retrowave
1254:47763, # Vangelis -> conquest of paradise film scene
104184:1918, # Religious Imagery -> conquest of paradise music video
1610:2199847, # Happy Music -> Harald Foss - Eirik Jarl
236111:4829577, # KPop -> techno guitar orchestra
237005:4825269, # Vietnam War -> Ballad of Ho Chi Minh war video
2607:1930, # English Language song -> Scotland the Brave
1987:5832, # Sad Song -> Burning Bridges
66172:2064058, # Artistic Music video -> Freedom Fighters (Orwellian)
2539:1743834, # TV Theme Music -> The Expanse
3020:7169, # Orchestra1 (i.e. Endless Space) -> Riftborn Prologue
5507:27228, # Yugoslavian Music Video
1238:1955216, # Vikings -> aurora (or maybe 1955 for that violin lady)
239917:2199768, # Historic Event -> Stanford Bridge
2550:1726594, # Bear McCreary
2568:2557, # Romantic -> Rowan Atkinson examins Loxie
1292:3091, # Funny -> Rat hygiene
40844:25446, # CovidPunk -> street disinfecting
10057:2652, # French Language Song -> Demain Nous Appartient
3031:2200324, # European Language Song -> Trava u Doma
2494:1844, # German Language Song -> Alexa Fesa - Wir Sind Hier
743:1845, # Traditional Music -> Greensleeves orchestra
239898:1955972, # Weird song -> moo
1219:1847, # Progress Music Video -> Baba Yetu
239922:4895481, # Dictator's Playlist -> Angry German man (or 1936==European Superstate)
235314:4829650, # Anti-War Song -> Ich Bin Soldat
}
tagem_tagids:dict = { # NOTE: As of Python 3.7, regular dicts are guaranteed to be ordered
# 65574:"notcompsky.github.io Prepopulated",
237870:"Bit of everything playlist",
749:"Instrumental Music",
1054:"Piano", # Piano Music; NOTE there is also a "Safe Piano Music Playlist",tagid==239901
116236:"Retrowave", # Sovietwave
239896:"Film Scores",# SAFE Film Scores
239897:"Orchestralishy Style", # Safe Epic Music
3020:"Orchestra1", # Endless Space Soundtrack
3002:"Orchestra2", # Sword of the Stars Soundtrack
3065:"Orchestra3", # Civilization VI Soundtrack
2566:"LotR", # Lord of the Rings Soundtrack
# 1309:"History Music Video",
81956:"E-Style Orchestral Cover",
2995:"E-Style Music",
744:"Sad Music",
991:"Film Score",
238488:"Bittersweet Song",
1610:"Happy Music",
#2498:"Happy Song",
2568:"Romantic Song",
1987:"Sad Song",
2841:"Inspiring Music",# TODO: remove?
239903:"Misc Electronic Musics", # Leftover Electronic Musics
21346:"Medieval Instrumental Cover",
2607:"English Language Song",
3031:"European Language Song",
2494:"German Language Song",
2652:"French Language Song",
240031:"Spain",
5557:"Latin Song",
5507:"Yugoslavian Music Video",
237781:"German Pop Song",
235314:"Anti-War Song",
237178:"Anti-Alien Song",
239922:"Dictator's Playlist", # Safe Authority Music Playlist
87330:"Song Video",
# 235305:"Happy Song Video",
2539:"TV Theme Music",
#3032:"TV Show Intro",
236829:"Sad Music Video",
66172:"Artistic Music Video",
1219:"Brainwashing", # Progress Music Video",
1221:"Cinematic Music Video",
1202:"SciFi Music Video",
239923:"Apocalypse",
239917:"Historic Event",
969:"Roman Empire",
237005:"Vietnam War Song",
743:"Traditional Music",
239900:"Traditional Song", # Safe Traditional Song Playlist
5585:"European Culture",
1238:"Vikings",
239938:"Sailing",
1254:"Vangelis",
115438:"Harald Foss",
9438:"Christopher Tin",
1010:"Two Steps",
# 6810:"Santiano",
2550:"Bear McCreary",
1210:"Alexa Fesa",
72541:"Karl Sternau",
237310:"Nationhood", # Fatherland Playlist,
81788:"Covid Culture",
40844:"CovidPunk",
1292:"Funny",
5131:"Meymeys",
104184:"Religious Imagery",
#378:"Animal",
236111:"KPop",
FAKETAG_hassubtitles:"Has subtitles",
239898:"Weird songs or songs with weird backstories",
239895:"CRINGE ALERT! DON'T WATCH!",
240024:"Cute",
239926:"Reminds me of a dead person :(",
}
remove_a_if_already_tagged_b:tuple = (
(743,239900), # Traditional (Music,Song)
(744,1987), # Sad (Music,Song)
)
tagem_tagids__ordered_keys:list = [key for key in tagem_tagids]
tagem_tagids__as_indices:list = [tagem_tagids[key] for key in tagem_tagids__ordered_keys]
tagem_tagids__ordered_keys__including_hidden_tagids:list = tagem_tagids__ordered_keys+[
217409, # French Socialist Song
]
total_filesize:int = 0
filesizes:list = []
all_filepaths_added_to_server:list = []
def fp_of_file_added_to_server(fileid:int, fp:str):
global total_filesize
fsz:int = os.stat(fp).st_size
filesizes.append((fsz,fileid,fp))
total_filesize += fsz
all_filepaths_added_to_server.append(fp)
def set_symlink(linkat:str, linkto:str):
must_add_link:bool = True
if os.path.islink(linkat):
if os.path.realpath(linkat) == os.path.realpath(linkto):
must_add_link = False
else:
os.remove(linkat)
if must_add_link:
os.symlink(linkto, linkat)
all_tags_associated_with_chosen_files:list = []
fileid2associatedtags:list = []
i:int = 0
for fp in (
,
):
set_symlink(f"/home/vangelic/repos/compsky/static-and-chat-server/files/large/{i:04d}", fp)
fp_of_file_added_to_server(None, fp)
i += 1
for fp in (
, # "files/.../path/to/some.html",
):
final_result:list = []
is_modified:bool = False
with open(fp,"r") as f:
for orig_line in f.read().split("\n"):
line:str = orig_line
m = re.search(''' data-src="(/media/vangelic/DATA/[^"]+)"''', line)
if m is not None:
_fp:str = m.group(1)
set_symlink(f"files/large/{i:04d}", _fp)
fp_of_file_added_to_server(None, _fp)
if ' src="' in line:
line = re.sub(' src="[^"]*"', f' src="../large/{i:04d}"', line)
else:
line = re.sub(' data-src="', f' src="../large/{i:04d}" data-src="', line)
i += 1
final_result.append(line)
if line != orig_line:
is_modified = True
if final_result[-1] == "":
final_result.pop()
if is_modified:
with open(fp,"w") as f:
for line in final_result:
f.write(line+"\n")
captcha_video_fps:list = []
captcha_questions:list = []
process_captcha_clips_and_questions(i, captcha_video_fps, captcha_questions)
for fp in captcha_video_fps:
set_symlink(f"/home/vangelic/repos/compsky/static-and-chat-server/files/large/{i:04d}", fp)
fp_of_file_added_to_server(None, fp)
i += 1
tagem_fileid2indx:dict = {}
fileid2alternative_thumbnail:dict = {}
def fileid2alternative_thumbnail__process(dirpath:str):
for fname in os.listdir(dirpath):
fp:str = f"{dirpath}/{fname}"
if os.path.isdir(fp):
fileid2alternative_thumbnail__process(fp)
else:
m = re.search("^([0-9]+)(?:$|_.*)", fname)
if m is None:
print(f"ERROR: Bad thumbnail: {fp}")
else:
fileid2alternative_thumbnail[int(m.group(1))] = fp
fileid2alternative_thumbnail__process("/media/vangelic/DATA/static-server-files/audio-thumbs")
print(f"Registered {len(fileid2alternative_thumbnail)} alternative thumbnails")
tag2thumbnail:dict = {
0:"/DEFAULT.jpg",
240031:"/spain.jpg",
116236:"/retr.webp", # Retrowave
969:"/rome.webp",
239922:"/poli.webp", # police state
2568:"/roma.jpg", # romantic
21346:"/medi.jpg", # medieval
1238:"/vikings.jpg",
239938:"/sailing.webp",
217409:"/french_socialist.jpg",
2652:"/fren.jpg",
2494:"/deut.jpg",
236111:"/kpop.jpg",
}
for key,val in tag2thumbnail.items():
if type(val) is tuple:
tag2thumbnail[key] = val[1]
else:
mimetype:str = "image/jpeg" if val.endswith(".jpg") else ("image/webp" if val.endswith(".webp") else "image/png")
with open(f"/media/vangelic/DATA/static-server-files/tag-thumbs{val}","rb") as f:
tag2thumbnail[key] = "data:"+mimetype+";base64,"+base64.encodebytes(f.read()).replace(b"\n",b"").decode()
fileid2subtitles:dict = {}
def get_subtitle_vtt_for_fileid(fp:str, lang:str, fileid:int):
with open(fp,"rb") as f:
subtitle:list = [subtitle_langs.index(lang),"data:text/vtt;base64,"+base64.encodebytes(process_vtt_contents(f.read())).replace(b"\n",b"").decode()]
return subtitle
def process_vtt_contents(s:str):
lines:list = []
for line in s.split(b"\n"):
if line.startswith(b"#"):
continue
lines.append(line)
return b"\n".join(lines)
for fname in os.listdir("/media/vangelic/DATA/static-server-files/audio-subtitles"):
if fname.startswith("test."):
continue
fp:str = f"/media/vangelic/DATA/static-server-files/audio-subtitles/{fname}"
m = re.search("^([0-9]+)[.](.*)$", fname)
if m is None:
continue
fileid:int = int(m.group(1))
lang:str = m.group(2)
if lang not in subtitle_langs:
print(f"WARNING: Skipping unrecognised subtitle language: {lang}")
continue
subtitle:str = get_subtitle_vtt_for_fileid(fp,lang,fileid)
if fileid in fileid2subtitles:
fileid2subtitles[fileid].append(subtitle)
else:
fileid2subtitles[fileid] = [subtitle]
for fileid in tagem_fileids:
if fileid == 7155: # Endless Space 2 hour compilation
continue
fp:str = None
if os.path.exists(f"/media/vangelic/DATA/static-server-files/compressed_videos/by-tagem-fileid/{fileid}"):
fp = f"/media/vangelic/DATA/static-server-files/compressed_videos/by-tagem-fileid/{fileid}"
if fp is None:
fp = tagemdb.qry("SELECT CONCAT(d.full_path,f.name) FROM file f JOIN dir d ON d.id=f.dir WHERE f.id="+str(fileid))[0][0]
if type(fp) is bytes:
fp = fp.decode()
if not os.path.isfile(fp):
fp = None
if fp is None:
for (_fp,) in tagemdb.qry("SELECT CONCAT(d.full_path,f.name) FROM file_backup f JOIN dir d ON d.id=f.dir WHERE f.file="+str(fileid)):
if os.path.isfile(_fp):
fp = _fp.decode()
break
if fp is None:
print(f"Can't find file for id {fileid}")
continue
tagids:list = [x[0] for x in tagemdb.qry(f"SELECT t2pt.parent FROM file2tag f2t JOIN tag2parent_tree t2pt ON t2pt.id=f2t.tag WHERE f2t.file={fileid}")]
# tagids = [116236 if (x==229017) else x for x in tagids] # Include Fashwave in Retrowave
if fileid == 4902000:
tagids = [239926]
if fileid == 7678:
tagids.append(1219)
if fileid == 4900220: # Field of poppies piano
tagids.append(235314) # Anti-War Song
if fileid == 6722: # Dear White People
tagids = [239898] # weird songs
all_tags_associated_with_chosen_files += tagids
thumb_fp:str = get_thumb_fp(fileid, tagids)
thumb_str:str = 0
if fileid == 1919273: # German anthem -> deutsch
thumb_str = tagem_tagids__ordered_keys__including_hidden_tagids.index(2494)
elif fileid == 1919275: # French anthem -> fren
thumb_str = tagem_tagids__ordered_keys__including_hidden_tagids.index(2652)
elif thumb_fp is None:
for tagid in tag2thumbnail:
if fileid == 1534:
print(tagid, tagid in tagids)
if tagid == 0:
continue
if tagid in tagids:
thumb_str = tagem_tagids__ordered_keys__including_hidden_tagids.index(tagid)
break
else:
contents:bytes = None
with open(thumb_fp,"rb") as f:
contents = f.read()
mimetype:str = None
if thumb_fp.endswith(".jpg"):
mimetype = "image/jpeg"
elif thumb_fp.endswith(".webp"):
mimetype = "image/webp"
elif thumb_fp.endswith(".png"):
mimetype = "image/png"
else:
mimetype = magic.from_buffer(contents, mime=True)
if mimetype not in ("image/jpeg","image/webp","image/png"):
raise ValueError(f"ERROR: mimetype is {mimetype} for {thumb_fp}")
thumb_str = "data:"+mimetype+";base64,"+base64.encodebytes(contents).replace(b"\n",b"").decode()
file_mimetype:str = mimetype_utils.guess_mimetype(fp)
file_mimetype = mimetype_utils.standardise_mimetype(file_mimetype, fp)
filtered_tagids:list = [x for x in tagids]
for a,b in remove_a_if_already_tagged_b:
if (b in filtered_tagids) and (a in filtered_tagids):
filtered_tagids = [x for x in filtered_tagids if x!=a]
file_visible_tagids:list = list(set([tagem_tagids__ordered_keys.index(x) for x in filtered_tagids if x in tagem_tagids]))
subtitles:list = fileid2subtitles.get(fileid)
if subtitles is None:
subtitles = []
else:
file_visible_tagids.append(tagem_tagids__ordered_keys.index(FAKETAG_hassubtitles))
if len(file_visible_tagids) == 0:
tagnames:list = [x[0].decode() for x in tagemdb.qry(f"SELECT name FROM tag t JOIN file2tag f2t ON f2t.tag=t.id WHERE f2t.file={fileid}")]
print(f"WARNING: No visible tagids for file {fileid} {fp} {json.dumps(tagnames)}")
continue
tagem_fileid2indx[fileid] = i
fileid2associatedtags.append([i,thumb_str,file_visible_tagids,file_mimetype,subtitles])
set_symlink(f"/home/vangelic/repos/compsky/static-and-chat-server/files/large/{i:04d}", fp)
fp_of_file_added_to_server(fileid, fp)
i += 1
tag2thumbnail = {(0 if (key==0) else tagem_tagids__ordered_keys__including_hidden_tagids.index(key)):val for key,val in tag2thumbnail.items()}
for name,description,firstmedia,filepaths in (
,
):
tagindx:int = None
default_thumb_str:str = 0
if name in tagem_tagids__as_indices:
tagindx = tagem_tagids__as_indices.index(name)
if tagindx in tag2thumbnail:
default_thumb_str = tag2thumbnail[tagindx]
else:
tagindx = len(tagem_tagids__as_indices)
tagem_tagids__as_indices.append(name)
for fp_indx_in_set, fp in enumerate(filepaths):
thumb_str:str = default_thumb_str
if type(fp) is tuple:
if fp[0] == "PICK_ONE":
fp = fp[1][0] # TODO: Choose at random, but only when browser_cache_is_different (i.e. version v=? updated)
if type(fp) is tuple:
thumb_str = fp[1]
fp = fp[0]
if fp in all_filepaths_added_to_server:
print("WARNING: file already included:", fp)
continue
file_visible_tagids:list = [tagindx]
subtitles:list = []
fake_fileid:int = max(tagem_fileid2indx) + 1
tagem_fileid2indx[fake_fileid] = i
if os.path.isfile(fp+".vtt"):
print("Found VTT: "+fp+".vtt")
subtitles.append(get_subtitle_vtt_for_fileid(fp+".vtt", "en", fake_fileid))
file_visible_tagids.append(tagem_tagids__ordered_keys.index(FAKETAG_hassubtitles))
if firstmedia == fp_indx_in_set:
introduction_to_each_category[tagindx] = fake_fileid
file_mimetype:str = mimetype_utils.guess_mimetype(fp)
file_mimetype = mimetype_utils.standardise_mimetype(file_mimetype, fp)
fileid2associatedtags.append([i,thumb_str,file_visible_tagids,file_mimetype,subtitles])
set_symlink(f"/home/vangelic/repos/compsky/static-and-chat-server/files/large/{i:04d}", fp)
fp_of_file_added_to_server(None, fp)
i += 1
while os.path.exists(f"/home/vangelic/repos/compsky/static-and-chat-server/files/large/{i:04d}"):
os.remove(f"/home/vangelic/repos/compsky/static-and-chat-server/files/large/{i:04d}")
i += 1
all_tags_associated_with_chosen_files = [x for x in all_tags_associated_with_chosen_files if x not in tagem_tagids]
for tagid, count in Counter(all_tags_associated_with_chosen_files).most_common(50):
tagname:str = tagemdb.qry(f"SELECT name FROM tag WHERE id={tagid}")[0][0].decode()
print(f"Excluded tag associated with {count} chosen files: {tagid} {tagname}")
prev_all_filepaths_added_to_server:list = None
with open("prev_all_filepaths_added_to_server.json","r") as f:
prev_all_filepaths_added_to_server = json.load(f)
browser_cache_is_different:bool = False
for i in range(len(all_filepaths_added_to_server)):
if i == len(prev_all_filepaths_added_to_server):
break
if all_filepaths_added_to_server[i] != prev_all_filepaths_added_to_server[i]:
browser_cache_is_different = True
break
browser_cache_version:int = 0
with open("browser_cache_version.txt","r") as f:
browser_cache_version = int(f.read())
if browser_cache_is_different:
browser_cache_version += 1
with open("browser_cache_version.txt","w") as f:
f.write(str(browser_cache_version))
introduction_to_each_category = {tagem_tagids__ordered_keys.index(tagid):tagem_fileid2indx[fileid] for tagid,fileid in introduction_to_each_category.items() if (fileid in tagem_fileid2indx) and (tagid in tagem_tagids__ordered_keys)}
with open("/home/vangelic/repos/compsky/static-and-chat-server/files/static/all_.json","w") as f:
json.dump([tagem_tagids__as_indices,fileid2associatedtags,tag2thumbnail,introduction_to_each_category],f,indent=None,separators=(",",":"))
for fsz,fileid,fp in sorted(filesizes,key=lambda x:x[0],reverse=True)[:50]:
print(f"{fsz}\t{fileid}\t{fp}")
print(f"Total size of all files used by server: {total_filesize//(1024*1024)} MiB")
for fileid in fileid2alternative_thumbnail:
print(f"ERROR: Failed to use alternative thumbnail for {fileid}")
def apparmor_escstr(s:str):
return s.replace("\\","\\\\").replace("\"","\\\"").replace("[","\\[").replace("]","\\]")
if browser_cache_is_different or (len(all_filepaths_added_to_server) != len(prev_all_filepaths_added_to_server)):
with open("prev_all_filepaths_added_to_server.json.new","w") as f:
json.dump(all_filepaths_added_to_server, f)
os.rename("prev_all_filepaths_added_to_server.json.new","prev_all_filepaths_added_to_server.json")
with open("profile.largefiles.apparmor","w") as f:
for fp in all_filepaths_added_to_server:
f.write(f'"{apparmor_escstr(fp)}" r,\n')
if True:
tagem_tagnames:list = [tagem_tagids[tagid] for tagid in tagem_tagids]
def subfn(m):
return m.group(1) + str(1+tagem_tagnames.index(m.group(3))) + m.group(2)
mainpage_contents:str = None
with open("files/static/index.html","r") as f:
mainpage_contents = f.read()
mainpage_contents = re.sub('(<a href="rand.html#\\[)[0-9]+(,[^"]+\\]"><img .*alt="([^"]+)".*</img></a>)', subfn, mainpage_contents)
with open("files/static/index.html","w") as f:
f.write(mainpage_contents)
mimetype_utils.save_cached_mimetypes("cached_mimetypes.json")