]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/faz.py
Update upstream source from tag 'upstream/2019.06.08'
[youtubedl] / youtube_dl / extractor / faz.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..compat import compat_etree_fromstring
8 from ..utils import (
9 xpath_element,
10 xpath_text,
11 int_or_none,
12 )
13
14
15 class FazIE(InfoExtractor):
16 IE_NAME = 'faz.net'
17 _VALID_URL = r'https?://(?:www\.)?faz\.net/(?:[^/]+/)*.*?-(?P<id>\d+)\.html'
18
19 _TESTS = [{
20 'url': 'http://www.faz.net/multimedia/videos/stockholm-chemie-nobelpreis-fuer-drei-amerikanische-forscher-12610585.html',
21 'info_dict': {
22 'id': '12610585',
23 'ext': 'mp4',
24 'title': 'Stockholm: Chemie-Nobelpreis für drei amerikanische Forscher',
25 'description': 'md5:1453fbf9a0d041d985a47306192ea253',
26 },
27 }, {
28 'url': 'http://www.faz.net/aktuell/politik/berlin-gabriel-besteht-zerreissprobe-ueber-datenspeicherung-13659345.html',
29 'only_matching': True,
30 }, {
31 'url': 'http://www.faz.net/berlin-gabriel-besteht-zerreissprobe-ueber-datenspeicherung-13659345.html',
32 'only_matching': True,
33 }, {
34 'url': 'http://www.faz.net/-13659345.html',
35 'only_matching': True,
36 }, {
37 'url': 'http://www.faz.net/aktuell/politik/-13659345.html',
38 'only_matching': True,
39 }, {
40 'url': 'http://www.faz.net/foobarblafasel-13659345.html',
41 'only_matching': True,
42 }]
43
44 def _real_extract(self, url):
45 video_id = self._match_id(url)
46
47 webpage = self._download_webpage(url, video_id)
48 description = self._og_search_description(webpage)
49 media = self._html_search_regex(
50 r"data-videojs-media='([^']+)",
51 webpage, 'media')
52 if media == 'extern':
53 perform_url = self._search_regex(
54 r"<iframe[^>]+?src='((?:http:)?//player\.performgroup\.com/eplayer/eplayer\.html#/?[0-9a-f]{26}\.[0-9a-z]{26})",
55 webpage, 'perform url')
56 return self.url_result(perform_url)
57 config = compat_etree_fromstring(media)
58
59 encodings = xpath_element(config, 'ENCODINGS', 'encodings', True)
60 formats = []
61 for pref, code in enumerate(['LOW', 'HIGH', 'HQ']):
62 encoding = xpath_element(encodings, code)
63 if encoding is not None:
64 encoding_url = xpath_text(encoding, 'FILENAME')
65 if encoding_url:
66 tbr = xpath_text(encoding, 'AVERAGEBITRATE', 1000)
67 if tbr:
68 tbr = int_or_none(tbr.replace(',', '.'))
69 f = {
70 'url': encoding_url,
71 'format_id': code.lower(),
72 'quality': pref,
73 'tbr': tbr,
74 'vcodec': xpath_text(encoding, 'CODEC'),
75 }
76 mobj = re.search(r'(\d+)x(\d+)_(\d+)\.mp4', encoding_url)
77 if mobj:
78 f.update({
79 'width': int(mobj.group(1)),
80 'height': int(mobj.group(2)),
81 'tbr': tbr or int(mobj.group(3)),
82 })
83 formats.append(f)
84 self._sort_formats(formats)
85
86 return {
87 'id': video_id,
88 'title': self._og_search_title(webpage),
89 'formats': formats,
90 'description': description.strip() if description else None,
91 'thumbnail': xpath_text(config, 'STILL/STILL_BIG'),
92 'duration': int_or_none(xpath_text(config, 'DURATION')),
93 }