]>
git.frykholm.com Git - svtplaydump.git/blob - mirror-svtplay.py
a08e14cc6581cbdf43a5d9ff2812777929d7b99c
2 from pathlib
import Path
9 totpages
= requests
.get("https://www.svtplay.se/api/latest").json()['totalPages']
10 for page
in range(1,totpages
):
11 resp
= requests
.get(f
"https://www.svtplay.se/api/latest?page={page}").json()
12 for video
in resp
['data']:
15 def find_genre(video
):
16 for cluster
in video
['clusters']:
17 if cluster
['clusterType'] == 'main':
18 return cluster
['name']
21 def svtplay_meta2xml(meta
):
28 <String>{meta['programTitle']} - {meta['title']}</String>
31 <Name>DESCRIPTION</Name>
32 <String>{meta['shortDescription']}</String>
35 <Name>DATE_RELEASED</Name>
36 <String>{meta['year']}</String>
40 <String>{meta['description']}</String>
50 genre
= find_genre(video
)
54 if not video
['movie']: #We have a Series, make a folder
55 path
= Path(genre
) / Path(video
['programTitle'].replace('/','_'))
59 # import pdb;pdb.set_trace()
60 if video
['season'] == 0 and not video
['movie']: #not a series, something like Rapport
61 validf
= datetime
.datetime
.strptime(video
['validFrom'],'%Y-%m-%dT%H:%M:%S%z')
62 valids
= validf
.strftime("%Y-%m-%dT%H")
63 title
= f
"{video['programTitle']} {valids}"
64 if not video
['movie'] and video
['season'] != 0:
65 title
= f
"{video['programTitle']} S{video['season']}E{video['episodeNumber']} {video['title']}"
66 with
open(f
"{path}/{video['id']}.xml","w") as xmlfile
:
67 xmlfile
.write(svtplay_meta2xml(video
))
69 if video
['closedCaptioned']:
70 add_subs
= f
"'{path}/'*{apa}*.vtt"
71 ydl_opts
= { 'download_archive': 'svtplay.archive',
72 'writesubtitles': True,
74 'writethumbnail': True,
75 'outtmpl' : f
'{path}/%(title)s-%(id)s.%(ext)s',
78 'key': 'ExecAfterDownload',
79 'exec_cmd': f
"echo {{}} && mkvmerge --global-tags '{path}'/{apa}.xml --attach-file '{path}/'*{apa}*jpg '{path}'/*{apa}*.mp4 {add_subs} -o '{path}/{title}.mkv' && rm '{path}'/*{apa}*",
82 extra_info
= { 'id': apa
,
84 'thumbnail':video
.get('thumbnail','').replace('{format}','large')}
85 xml
= svtplay_meta2xml(video
)
86 with youtube_dl
.YoutubeDL(ydl_opts
) as ydl
:
87 ydl
.extract_info("http://svtplay.se/"+video
['contentUrl'], extra_info
=extra_info
)
89 if __name__
== "__main__":
90 for video
in videos():
91 print(video
['programTitle'])