]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/noz.py
0ffb44b47eb673821f013e6696d495226711c2dd
[youtubedl] / youtube_dl / extractor / noz.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..compat import compat_urllib_parse_unquote
6 from ..utils import (
7 int_or_none,
8 xpath_text,
9 )
10
11
12 class NozIE(InfoExtractor):
13 _VALID_URL = r'https?://(?:www\.)?noz\.de/video/(?P<id>[0-9]+)/'
14 _TESTS = [{
15 'url': 'http://www.noz.de/video/25151/32-Deutschland-gewinnt-Badminton-Lnderspiel-in-Melle',
16 'info_dict': {
17 'id': '25151',
18 'ext': 'mp4',
19 'duration': 215,
20 'title': '3:2 - Deutschland gewinnt Badminton-Länderspiel in Melle',
21 'description': 'Vor rund 370 Zuschauern gewinnt die deutsche Badminton-Nationalmannschaft am Donnerstag ein EM-Vorbereitungsspiel gegen Frankreich in Melle. Video Moritz Frankenberg.',
22 'thumbnail': 're:^http://.*\.jpg',
23 },
24 }]
25
26 def _real_extract(self, url):
27 video_id = self._match_id(url)
28 webpage = self._download_webpage(url, video_id)
29 description = self._og_search_description(webpage)
30
31 edge_url = self._html_search_regex(
32 r'<script\s+(?:type="text/javascript"\s+)?src="(.*?/videojs_.*?)"',
33 webpage, 'edge URL')
34 edge_content = self._download_webpage(edge_url, 'meta configuration')
35
36 config_url_encoded = self._search_regex(
37 r'so\.addVariable\("config_url","[^,]*,(.*?)"',
38 edge_content, 'config URL'
39 )
40 config_url = compat_urllib_parse_unquote(config_url_encoded)
41
42 doc = self._download_xml(config_url, 'video configuration')
43 title = xpath_text(doc, './/title')
44 thumbnail = xpath_text(doc, './/article/thumbnail/url')
45 duration = int_or_none(xpath_text(
46 doc, './/article/movie/file/duration'))
47 formats = []
48 for qnode in doc.findall('.//article/movie/file/qualities/qual'):
49 video_node = qnode.find('./html_urls/video_url[@format="video/mp4"]')
50 if video_node is None:
51 continue # auto
52 formats.append({
53 'url': video_node.text,
54 'format_name': xpath_text(qnode, './name'),
55 'format_id': xpath_text(qnode, './id'),
56 'height': int_or_none(xpath_text(qnode, './height')),
57 'width': int_or_none(xpath_text(qnode, './width')),
58 'tbr': int_or_none(xpath_text(qnode, './bitrate'), scale=1000),
59 })
60 self._sort_formats(formats)
61
62 return {
63 'id': video_id,
64 'formats': formats,
65 'title': title,
66 'duration': duration,
67 'description': description,
68 'thumbnail': thumbnail,
69 }