]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/folketinget.py
0fb29de75228f0133c0b8d54a015fbd5d90954c1
[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 'md5': '6269e8626fa1a891bf5369b386ae996a',
20 'info_dict': {
21 'id': '1165642',
22 'ext': 'mp4',
23 'title': 'Åbent samråd i Erhvervsudvalget',
24 'description': 'Åbent samråd med erhvervs- og vækstministeren om regeringens politik på teleområdet',
25 'view_count': int,
26 'width': 768,
27 'height': 432,
28 'tbr': 928000,
29 'timestamp': 1416493800,
30 'upload_date': '20141120',
31 'duration': 3960,
32 },
33 }
34
35 def _real_extract(self, url):
36 video_id = self._match_id(url)
37 webpage = self._download_webpage(url, video_id)
38
39 title = self._og_search_title(webpage)
40 description = self._html_search_regex(
41 r'(?s)<div class="video-item-agenda"[^>]*>(.*?)<',
42 webpage, 'description', fatal=False)
43
44 player_params = compat_parse_qs(self._search_regex(
45 r'<embed src="http://ft\.arkena\.tv/flash/ftplayer\.swf\?([^"]+)"',
46 webpage, 'player params'))
47 xml_url = player_params['xml'][0]
48 doc = self._download_xml(xml_url, video_id)
49
50 timestamp = parse_iso8601(xpath_text(doc, './/date'))
51 duration = parse_duration(xpath_text(doc, './/duration'))
52 width = int_or_none(xpath_text(doc, './/width'))
53 height = int_or_none(xpath_text(doc, './/height'))
54 view_count = int_or_none(xpath_text(doc, './/views'))
55
56 formats = [{
57 'format_id': n.attrib['bitrate'],
58 'url': xpath_text(n, './url', fatal=True),
59 'tbr': int_or_none(n.attrib['bitrate']),
60 } for n in doc.findall('.//streams/stream')]
61 self._sort_formats(formats)
62
63 return {
64 'id': video_id,
65 'title': title,
66 'formats': formats,
67 'description': description,
68 'timestamp': timestamp,
69 'width': width,
70 'height': height,
71 'duration': duration,
72 'view_count': view_count,
73 }