]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/atvat.py
Update changelog
[youtubedl] / youtube_dl / extractor / atvat.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6 determine_ext,
7 int_or_none,
8 unescapeHTML,
9 )
10
11
12 class ATVAtIE(InfoExtractor):
13 _VALID_URL = r'https?://(?:www\.)?atv\.at/(?:[^/]+/){2}(?P<id>[dv]\d+)'
14 _TESTS = [{
15 'url': 'http://atv.at/aktuell/di-210317-2005-uhr/v1698449/',
16 'md5': 'c3b6b975fb3150fc628572939df205f2',
17 'info_dict': {
18 'id': '1698447',
19 'ext': 'mp4',
20 'title': 'DI, 21.03.17 | 20:05 Uhr 1/1',
21 }
22 }, {
23 'url': 'http://atv.at/aktuell/meinrad-knapp/d8416/',
24 'only_matching': True,
25 }]
26
27 def _real_extract(self, url):
28 display_id = self._match_id(url)
29 webpage = self._download_webpage(url, display_id)
30 video_data = self._parse_json(unescapeHTML(self._search_regex(
31 r'class="[^"]*jsb_video/FlashPlayer[^"]*"[^>]+data-jsb="([^"]+)"',
32 webpage, 'player data')), display_id)['config']['initial_video']
33
34 video_id = video_data['id']
35 video_title = video_data['title']
36
37 parts = []
38 for part in video_data.get('parts', []):
39 part_id = part['id']
40 part_title = part['title']
41
42 formats = []
43 for source in part.get('sources', []):
44 source_url = source.get('src')
45 if not source_url:
46 continue
47 ext = determine_ext(source_url)
48 if ext == 'm3u8':
49 formats.extend(self._extract_m3u8_formats(
50 source_url, part_id, 'mp4', 'm3u8_native',
51 m3u8_id='hls', fatal=False))
52 else:
53 formats.append({
54 'format_id': source.get('delivery'),
55 'url': source_url,
56 })
57 self._sort_formats(formats)
58
59 parts.append({
60 'id': part_id,
61 'title': part_title,
62 'thumbnail': part.get('preview_image_url'),
63 'duration': int_or_none(part.get('duration')),
64 'is_live': part.get('is_livestream'),
65 'formats': formats,
66 })
67
68 return {
69 '_type': 'multi_video',
70 'id': video_id,
71 'title': video_title,
72 'entries': parts,
73 }