-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathremove_id_from_cache.py
62 lines (49 loc) · 1.38 KB
/
remove_id_from_cache.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
import os
import sys
import json
from sb_cache import SBRemoteCache
args = sys.argv[1:]
fname = "vidcache.json"
if len(args) == 0:
bn = os.path.basename(sys.argv[0])
print (f"Usage: python {bn} youtubeID\n")
sys.exit(1)
sbcache = SBRemoteCache()
sbcache.remove_id_from_cache(args[0])
# txt = open(fname, "r").read()
# j = json.loads(txt)
# titles = j["titles"]
# new_titles = {}
# tfnd = False
# for t in titles:
# obj = titles[t]
# if obj["id"] == args[0]:
# tfnd = True
# print (f"Found segment entry for ID \"{args[0]}\"")
# else:
# new_titles[t] = obj
# if not tfnd:
# print (f'ID "{args[0]}" not found in titles')
# sfnd = False
# new_segments = {}
# segments = j["segments"]
# for id in segments:
# obj = segments[id]
# if id == args[0]:
# sfnd = True
# print (f"Found segment entry for ID \"{id}\"")
# else:
# new_segments[id] = obj
# if not sfnd:
# print (f'ID "{args[0]}" not found in segments')
# if (not sfnd) and (not tfnd):
# print ("No changes to cache, cache not resaved")
# sys.exit(0)
# new_cache = {"titles": new_titles, "segments": new_segments }
# backup_fname = f"{fname}.bak"
# with open(backup_fname, "w") as f:
# f.write(txt)
# print (f"Saved backup file to {backup_fname}")
# with open(fname, "w") as f:
# json.dump(new_cache, f)
# print (f"Cache saved to {fname}")