-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgencsv.py
61 lines (51 loc) · 1.79 KB
/
gencsv.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
import json
import os
import csv
import sys
def doone(filename, nameid):
with open(filename, "r") as infile:
indata = json.load(infile)
if "DmcSeriesBundle" in indata["data"]:
videos = indata["data"]["DmcSeriesBundle"]["episodes"]["videos"]
if len(videos) == 0:
return None
video = videos[0]
textbundle = indata["data"]["DmcSeriesBundle"]["series"]["text"]
texttype = "series"
else:
video = indata["data"]["DmcVideoBundle"]["video"]
textbundle = video["text"]
texttype = "program"
media_metadata = video["mediaMetadata"]
def nameTrack(i):
if i["renditionName"]:
return i["renditionName"]
return i["language"] + "-" + i["trackType"]
tracks_text = "|".join(
sorted([nameTrack(i) for i in media_metadata["audioTracks"]]))
subtitles_text = "|".join(
sorted([
nameTrack(i) for i in media_metadata["captions"]
if i["trackType"] != "FORCED"
]))
video_title = textbundle["title"]["full"][texttype]["default"]["content"]
return [video_title, nameid, tracks_text, subtitles_text]
def doall(foldername):
rows = []
for subfolder in ["disneyplus_movies", "disneyplus_series"]:
for filename in os.listdir(foldername + "/" + subfolder):
row = doone(foldername + "/" + subfolder + "/" + filename,
filename)
if row is None:
continue
rows.append(row)
return rows
def main():
rows = doall(sys.argv[1])
rows.sort(key=lambda a: a[0])
with open(sys.argv[2], "w") as csvfile:
writer = csv.writer(csvfile)
writer.writerow(["Title", "ID", "Audio", "Subtitles"])
writer.writerows(rows)
if __name__ == "__main__":
main()