+ params = requests.utils.urlparse(video['url']).query
+ print(params)
+ if 'cc1=' in params: #'cc1=name=Svenska~default=yes~forced=no~uri=http://media.svt.se/download/mcc/wp3/undertexter-wsrt/1134047/1134047-025A/C(sv)/index.m3u8~lang=sv'
+ video['subs'] = [dict([k.split('=') for k in params.split('cc1=')[1].split('~')])] #make a dict from the paramstring
+ try:
+ req = requests.get(video['url']).text
+ except:
+ print("Error reading, skipping file")
+ print(sys.exc_info()[1])
+ return False
+ if 'subs' in video:
+ try:
+ segments = [item for item in requests.get(video['subs'][0]['uri']).text.split('\n') if 'vtt' in item]
+ except:
+ print("Error reading, skipping subtitle")
+ print(sys.exc_info()[1])
+ segments = [] #ugly FIXME
+ video['subs'][0]['download'] = []
+ for segment in segments:
+ if not segment.startswith('http'):
+ segment = "{}/{}".format(os.path.dirname(video['subs'][0]['uri']), segment)
+ try:
+ video['subs'][0]['download'].append(requests.get(segment).text)
+ except:
+ print("Error reading, skipping subtitle")
+ print(sys.exc_info()[1])
+ break
+ playlist = parse_playlist(req)