Merge remote-tracking branch 'dstftw/generic-webpage-unescape'
[youtube-dl] / youtube_dl / extractor / parliamentliveuk.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7     ExtractorError,
8     unified_strdate,
9 )
10
11
12 class ParliamentLiveUKIE(InfoExtractor):
13     IE_NAME = 'parliamentlive.tv'
14     IE_DESC = 'UK parliament videos'
15     _VALID_URL = r'https?://www\.parliamentlive\.tv/Main/Player\.aspx\?(?:[^&]+&)*?meetingId=(?P<id>[0-9]+)'
16
17     _TEST = {
18         'url': 'http://www.parliamentlive.tv/Main/Player.aspx?meetingId=15121&player=windowsmedia',
19         'info_dict': {
20             'id': '15121',
21             'ext': 'asf',
22             'title': 'hoc home affairs committee, 18 mar 2014.pm',
23             'description': 'md5:033b3acdf83304cd43946b2d5e5798d1',
24         },
25         'params': {
26             'skip_download': True,  # Requires mplayer (mms)
27         }
28     }
29
30     def _real_extract(self, url):
31         mobj = re.match(self._VALID_URL, url)
32         video_id = mobj.group('id')
33         webpage = self._download_webpage(url, video_id)
34
35         asx_url = self._html_search_regex(
36             r'embed.*?src="([^"]+)" name="MediaPlayer"', webpage,
37             'metadata URL')
38         asx = self._download_xml(asx_url, video_id, 'Downloading ASX metadata')
39         video_url = asx.find('.//REF').attrib['HREF']
40
41         title = self._search_regex(
42             r'''(?x)player\.setClipDetails\(
43                 (?:(?:[0-9]+|"[^"]+"),\s*){2}
44                 "([^"]+",\s*"[^"]+)"
45                 ''',
46             webpage, 'title').replace('", "', ', ')
47         description = self._html_search_regex(
48             r'(?s)<span id="MainContentPlaceHolder_CaptionsBlock_WitnessInfo">(.*?)</span>',
49             webpage, 'description')
50
51         return {
52             'id': video_id,
53             'ext': 'asf',
54             'url': video_url,
55             'title': title,
56             'description': description,
57         }