]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/faz.py
[utils] Correct octal/hexadecimal number detection in js_to_json
[youtube-dl] / youtube_dl / extractor / faz.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6     xpath_element,
7     xpath_text,
8     int_or_none,
9 )
10
11
12 class FazIE(InfoExtractor):
13     IE_NAME = 'faz.net'
14     _VALID_URL = r'https?://(?:www\.)?faz\.net/(?:[^/]+/)*.*?-(?P<id>\d+)\.html'
15
16     _TESTS = [{
17         'url': 'http://www.faz.net/multimedia/videos/stockholm-chemie-nobelpreis-fuer-drei-amerikanische-forscher-12610585.html',
18         'info_dict': {
19             'id': '12610585',
20             'ext': 'mp4',
21             'title': 'Stockholm: Chemie-Nobelpreis für drei amerikanische Forscher',
22             'description': 'md5:1453fbf9a0d041d985a47306192ea253',
23         },
24     }, {
25         'url': 'http://www.faz.net/aktuell/politik/berlin-gabriel-besteht-zerreissprobe-ueber-datenspeicherung-13659345.html',
26         'only_matching': True,
27     }, {
28         'url': 'http://www.faz.net/berlin-gabriel-besteht-zerreissprobe-ueber-datenspeicherung-13659345.html',
29         'only_matching': True,
30     }, {
31         'url': 'http://www.faz.net/-13659345.html',
32         'only_matching': True,
33     }, {
34         'url': 'http://www.faz.net/aktuell/politik/-13659345.html',
35         'only_matching': True,
36     }, {
37         'url': 'http://www.faz.net/foobarblafasel-13659345.html',
38         'only_matching': True,
39     }]
40
41     def _real_extract(self, url):
42         video_id = self._match_id(url)
43
44         webpage = self._download_webpage(url, video_id)
45         description = self._og_search_description(webpage)
46         config_xml_url = self._search_regex(
47             r'videoXMLURL\s*=\s*"([^"]+)', webpage, 'config xml url')
48         config = self._download_xml(
49             config_xml_url, video_id, 'Downloading config xml')
50
51         encodings = xpath_element(config, 'ENCODINGS', 'encodings', True)
52         formats = []
53         for pref, code in enumerate(['LOW', 'HIGH', 'HQ']):
54             encoding = xpath_element(encodings, code)
55             if encoding is not None:
56                 encoding_url = xpath_text(encoding, 'FILENAME')
57                 if encoding_url:
58                     formats.append({
59                         'url': encoding_url,
60                         'format_id': code.lower(),
61                         'quality': pref,
62                         'tbr': int_or_none(xpath_text(encoding, 'AVERAGEBITRATE')),
63                     })
64         self._sort_formats(formats)
65
66         return {
67             'id': video_id,
68             'title': self._og_search_title(webpage),
69             'formats': formats,
70             'description': description.strip() if description else None,
71             'thumbnail': xpath_text(config, 'STILL/STILL_BIG'),
72             'duration': int_or_none(xpath_text(config, 'DURATION')),
73         }