]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/streamcz.py
Merge branch '_stream' of https://github.com/pulpe/youtube-dl into pulpe-_stream
[yt-dlp.git] / youtube_dl / extractor / streamcz.py
CommitLineData
0793a7b3 1# -*- coding: utf-8 -*-
2from __future__ import unicode_literals
3
4import re
5import json
6
7from .common import InfoExtractor
8
9
10class StreamCZIE(InfoExtractor):
11 _VALID_URL = r'https?://www\.stream\.cz/((?P<category>.+)/)?(?P<videogroup>.+)/(?P<videoid>.+)'
12
13 _TESTS = [{
14 'url': 'http://www.stream.cz/peklonataliri/765767-ecka-pro-deti',
15 'md5': '6d3ca61a8d0633c9c542b92fcb936b0c',
16 'info_dict': {
17 'id': '765767',
18 'ext': 'mp4',
19 'title': 'Peklo na talíři: Éčka pro děti',
20 'description': 'md5:49ace0df986e95e331d0fe239d421519',
21 'thumbnail': 'http://im.stream.cz/episode/52961d7e19d423f8f06f0100',
22 },
23 },
24 ]
25
26 def _real_extract(self, url):
27 mobj = re.match(self._VALID_URL, url)
28 video_id = mobj.group('videoid')
29
30 webpage = self._download_webpage(url, video_id)
31
32 data = self._html_search_regex(r'Stream\.Data\.Episode\((.+?)\);', webpage, 'stream data')
33
34 jsonData = json.loads(data)
35
36 formats = []
37 for video in jsonData['instances']:
38 format_id = video['instances'][0]['quality']
39
40 if format_id == '240p':
41 quality = 0
42 elif format_id == '360p':
43 quality = 1
44 elif format_id == '480p':
45 quality = 2
46 elif format_id == '720p':
47 quality = 3
48
49 formats.append({
50 'format_id': format_id,
51 'url': video['instances'][0]['source'],
52 'quality': quality,
53 'ext': 'mp4',
54 })
55
56 self._sort_formats(formats)
57
58 return {
59 'id': str(jsonData['id']),
60 'title': self._og_search_title(webpage),
61 'thumbnail': jsonData['episode_image_original_url'].replace('//', 'http://'),
62 'formats': formats,
63 'description': self._og_search_description(webpage),
64 }