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