forked from valdearg/big-finish
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_abs_json_function.py
More file actions
186 lines (165 loc) · 7.61 KB
/
Copy pathcreate_abs_json_function.py
File metadata and controls
186 lines (165 loc) · 7.61 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
import json
import os
import glob
from pathlib import Path
import numpy as np
"""
{
"tags": [],
"chapters": [],
"metadata": {
"title": "MR 001 - The Sirens of Time",
"subtitle": null,
"authors": [
"1. The Classic Series"
],
"narrators": [],
"series": [
"1. Main Range (MR) #1"
],
"genres": [
"Audio Drama"
],
"publishedYear": "1999",
"publishedDate": null,
"publisher": null,
"description": "New description\n\nfdkgjdfkgljgdflkj",
"isbn": null,
"asin": null,
"language": "Eng",
"explicit": false,
"abridged": false
}
}
"""
if not os.path.exists("ABS_JSON"):
os.makedirs("ABS_JSON")
# Define a mapping for series title transformations
series_mapping = {
"Class": "Class (CL)",
"Counter-Measures": "Counter Measures (CM)",
"Cyberman": "Cyberman (CY)",
"Doctor Who - The Monthly Adventures": "D0. Dr Who - Main Range (MR)",
"Doctor Who - The First Doctor Adventures": "D1. The First Doctor Adventures (1DA)",
"Doctor Who - The Tenth Doctor Adventures": "D10. The Tenth Doctor Adventures (10DA)",
"Doctor Who - The Second Doctor Adventures": "D2. The Second Doctor Adventures (2DA)",
"Doctor Who - The Third Doctor Adventures": "D3. The Third Doctor Adventures (3DA)",
"Doctor Who - The Fourth Doctor Adventures": "D4. The Fourth Doctor Adventures (4DA)",
"Doctor Who - The Fifth Doctor Adventures": "D5. The Fifth Doctor Adventures (5DA)",
"Doctor Who - The Sixth Doctor Adventures": "D6. The Sixth Doctor Adventures (6DA)",
"Doctor Who - The Seventh Doctor Adventures": "D7. The Seventh Doctor Adventures (7DA)",
"Doctor Who - The Eighth Doctor Adventures": "D8. The Eighth Doctor Adventures (8DA)",
"Doctor Who - The Ninth Doctor Adventures": "D9. The Ninth Doctor Adventures (9DA)",
"Dalek Empire": "Dalek Empire (DE)",
"Dark Gallifrey (DG)": "Dark Gallifrey (DG)",
"Doctor Who - Destiny of the Doctor": "Destiny of the Doctor",
"Doom's Day": "Doom's Day (DD)",
"Bernice Summerfield": "F1. Bernice Summerfield (BS)",
"Bernice Summerfield - Books & Audiobooks": "F2. Bernice Summerfield Audiobooks (BSAB)",
"Doctor Who - The New Adventures of Bernice Summerfield": "F3. The New Adventures of Bernice Summerfield (NABS)",
"Gallifrey": "Gallifrey (GAL)",
"I, Davros": "I, DAVROS",
"Jago & Litefoot": "Jago & Litefoot (J&L)",
"Missy": "Missy (MIS)",
"Doctor Who - Once and Future": "Once and Future (O&F)",
"Doctor Who - Philip Hinchcliffe Presents": "Philip Hincliffe Presents (PHP)",
"Doctor Who - Short Trips Rarities": "Rarities & Subcriber Short Trips (SST)",
"Rose Tyler": "Rose Tyler The Dimension Cannon (RT)",
"Sarah Jane Smith": "Sarah Jane Smith (SJS)",
"Doctor Who - Short Trips": "Short Trips (ST)",
"Doctor Who - Short Trips Rarities": "Short Trips Rarities",
"The Worlds of Doctor Who - Special Releases": "Special Releases (SP)",
"Torchwood - Monthly Range": "T0. Torchwood Main Range (TMR)",
"Torchwood - Special Releases": "T1. Torchwood - Specials (TWsp)",
"Torchwood One": "T2. Torchwood One (TW1)",
"Torchwood - The Story Continues": "T3. Torchwood - The Story Continues",
"Torchwood Soho": "T4. Torchwood Soho (TWS)",
"Doctor Who - The Audio Novels": "The Audio Novels",
"Doctor Who - The Companion Chronicles": "The Companion Chronicles (CC)",
"River Song": "The Diary of River Song (RS)",
"Doctor Who - The Doctor Chronicles": "The Doctor Chronicles (TDC)",
"Doctor Who - The Early Adventures": "The Early Adventures (EA)",
"The Lives of Captain Jack": "The Lives of Captain Jack (LCJ)",
"Doctor Who - The Lost Stories": "The Lost Stories (LS)",
"The Paternoster Gang": "The Paternoster Gang (PAT)",
"The Robots": "The Robots (ROB)",
"Doctor Who - The Stageplays": "The Stageplays (STG)",
"Doctor Who - The War Doctor": "The War Doctor (WD)",
"The War Master": "The War Master (WM)",
"Doctor Who - Time Lord Victorious": "Time Lord Victorious (TLV)",
"UNIT": "UNIT (UNIT)",
"UNIT - The New Series": "UNIT - The New Series (UNITNS)",
"Iris Wildthyme": "F4. Iris Wildthyme (IW)",
"Iris Wildthyme and Friends":"F5. Iris Wildthyme & Friends (IWF)",
"Graceless": "F6. Graceless",
"Doctor Who - Unbound": "Unbound (UN)",
"Vienna": "F7. Vienna",
"Charlotte Pollard": "F8. Charlotte Pollard",
# Add other series transformations as needed
}
# for json_filename in Path("JSON").rglob("*.json"):
def func_create_abs_json(json_filename, overwrite_json=False):
print(f"ABS JSON: {str(json_filename)}")
json_filename = Path(json_filename)
if os.path.exists(json_filename):
with open(json_filename, "r", encoding="utf-8") as f:
json_output = json.loads(f.read())
else:
with open(f"JSON\\{json_filename}", "r", encoding="utf-8") as f:
json_output = json.loads(f.read())
if os.path.exists(f"ABS_JSON\\{json_filename.name}") and overwrite_json is False:
print("ABS JSON exists, skipping")
return
# Extract cast members' characters and split on "/"
tags = []
for actor_info in json_output["CastMembers"]:
characters = actor_info["Character"].split("/")
tags.extend([char.strip() for char in characters]) # Strip whitespace and add to tags
chapters = []
# series_name_and_number = (
# f"{json_output['SeriesTitle']} #{json_output['ProductTitle'].split('. ')[0]}"
# )
# Extract the series number from the product title
series_number = json_output['ProductTitle'].split('. ')[0]
# Check if the series title needs to be transformed
original_series_title = json_output['SeriesTitle']
modified_series_title = original_series_title
for key in series_mapping:
if key in original_series_title:
modified_series_title = series_mapping[key]
break
modified_series_name_and_number = f"{modified_series_title} #{series_number}"
isbn = None
for i in json_output["ProductionCredits"]:
if "DigitalRetailISBN" in i:
isbn = i["DigitalRetailISBN"]
abs_metadata_json = {}
abs_metadata_json["title"] = json_output["ProductTitle"]
abs_metadata_json["subtitle"] = None
abs_metadata_json["authors"] = json_output["Writers"]
abs_metadata_json["narrators"] = [actor_info["Actor"] for actor_info in json_output["CastMembers"]]
#abs_metadata_json["tags"] = tags
#abs_metadata_json["tags"] = [actor_info["Character"] for actor_info in json_output["CastMembers"]]
# abs_metadata_json["series"] = [series_name_and_number]
abs_metadata_json["series"] = [modified_series_name_and_number]
abs_metadata_json["genres"] = ["Audio Drama"]
abs_metadata_json["publishedYear"] = json_output["ReleaseDate"].split(" ")[-1]
abs_metadata_json["publishedDate"] = None
abs_metadata_json["publisher"] = "Big Finish"
abs_metadata_json["description"] = json_output["Description"].replace("\n", "\n\n")
abs_metadata_json["isbn"] = isbn
abs_metadata_json["asin"] = None
abs_metadata_json["language"] = "Eng"
abs_metadata_json["explicit"] = False
abs_metadata_json["abridged"] = False
print("Writing ABS JSON file")
with open(f"ABS_JSON\\{json_filename.name}", "w", encoding="utf-8") as data_file:
json.dump(
{"tags": tags, "chapters": chapters, "metadata": abs_metadata_json},
data_file,
indent=4,
)
# func_create_abs_json(
# "JSON\\doctor-who-the-first-doctor-adventures-volume-01-1692.json",
# "X:\\Media\\Audiobooks - Doctor Who\\Big Finish Productions\\1. Doctor Who\\1. The Classic Series\\2. The First Doctor Adventures (1DA)\\1. Volume 1",
# )