]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/folketinget.py
Prepare for upload.
[youtubedl] / youtube_dl / extractor / folketinget.py
1 # -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..compat import compat_parse_qs
6 from ..utils import (
7 int_or_none,
8 parse_duration,
9 parse_iso8601,
10 xpath_text,
11 )
12
13
14 class FolketingetIE(InfoExtractor):
15 IE_DESC = 'Folketinget (ft.dk; Danish parliament)'
16 _VALID_URL = r'https?://(?:www\.)?ft\.dk/webtv/video/[^?#]*?\.(?P<id>[0-9]+)\.aspx'
17 _TEST = {
18 'url': 'http://www.ft.dk/webtv/video/20141/eru/td.1165642.aspx?as=1#player',
19 'info_dict': {
20 'id': '1165642',
21 'ext': 'mp4',
22 'title': 'Åbent samråd i Erhvervsudvalget',
23 'description': 'Åbent samråd med erhvervs- og vækstministeren om regeringens politik på teleområdet',
24 'view_count': int,
25 'width': 768,
26 'height': 432,
27 'tbr': 928000,
28 'timestamp': 1416493800,
29 'upload_date': '20141120',
30 'duration': 3960,
31 },
32 'params': {
33 'skip_download': 'rtmpdump required',
34 }
35 }
36
37 def _real_extract(self, url):
38 video_id = self._match_id(url)
39 webpage = self._download_webpage(url, video_id)
40
41 title = self._og_search_title(webpage)
42 description = self._html_search_regex(
43 r'(?s)<div class="video-item-agenda"[^>]*>(.*?)<',
44 webpage, 'description', fatal=False)
45
46 player_params = compat_parse_qs(self._search_regex(
47 r'<embed src="http://ft\.arkena\.tv/flash/ftplayer\.swf\?([^"]+)"',
48 webpage, 'player params'))
49 xml_url = player_params['xml'][0]
50 doc = self._download_xml(xml_url, video_id)
51
52 timestamp = parse_iso8601(xpath_text(doc, './/date'))
53 duration = parse_duration(xpath_text(doc, './/duration'))
54 width = int_or_none(xpath_text(doc, './/width'))
55 height = int_or_none(xpath_text(doc, './/height'))
56 view_count = int_or_none(xpath_text(doc, './/views'))
57
58 formats = [{
59 'format_id': n.attrib['bitrate'],
60 'url': xpath_text(n, './url', fatal=True),
61 'tbr': int_or_none(n.attrib['bitrate']),
62 } for n in doc.findall('.//streams/stream')]
63 self._sort_formats(formats)
64
65 return {
66 'id': video_id,
67 'title': title,
68 'formats': formats,
69 'description': description,
70 'timestamp': timestamp,
71 'width': width,
72 'height': height,
73 'duration': duration,
74 'view_count': view_count,
75 }