]>
Commit | Line | Data |
---|---|---|
5ab69ab4 MF |
1 | #!/usr/bin/env python3 |
2 | import requests | |
3 | import svtplaydump | |
4 | import os.path | |
5 | def get_hls_playlist(url): | |
6 | ret = requests.get(url).json() | |
7 | #import pdb;pdb.set_trace() | |
8 | videourl = None | |
9 | if isinstance(ret['playback']['items']['item'], list): | |
10 | videourl = sorted(ret['playback']['items']['item'], key=lambda k: int(k['bitrate']))[-1]['url'] | |
11 | else: | |
12 | videourl = ret['playback']['items']['item']['url'] | |
13 | return videourl | |
14 | ||
15 | res = requests.get("http://webapi.tv4play.se/video/programs/search.json?categoryids=pokemon&start=0&rows=1000").json() | |
16 | videos = [] | |
17 | #import pdb;pdb.set_trace() | |
18 | for vid in res['results']: | |
19 | video = {} | |
20 | video['title'] = vid['name'] | |
21 | video['description'] = vid['lead'] | |
22 | video['url'] = get_hls_playlist("http://premium.tv4play.se/api/web/asset/{}/play.json?protocol=hls&videoFormat=MP4+WVM+SMI".format(vid['href'])) | |
23 | video['filename'] = "{} {}.ts".format(vid['ontime'],vid['name']) | |
24 | videos.append(video) | |
25 | basename = video['filename'].split('.ts')[0] | |
26 | if os.path.exists(basename+'.mkv'): | |
27 | print("Skipping {}".format(basename)) | |
28 | continue | |
29 | svtplaydump.download_from_playlist(video) | |
30 | svtplaydump.remux(video) |