]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/orf.py
Prepare for upload.
[youtubedl] / youtube_dl / extractor / orf.py
1 # coding: utf-8
2
3 import re
4 import xml.etree.ElementTree
5 import json
6
7 from .common import InfoExtractor
8 from ..utils import (
9 compat_urlparse,
10 ExtractorError,
11 find_xpath_attr,
12 )
13
14 class ORFIE(InfoExtractor):
15 _VALID_URL = r'https?://tvthek.orf.at/(programs/.+?/episodes|topics/.+?)/(?P<id>\d+)'
16
17 _TEST = {
18 u'url': u'http://tvthek.orf.at/programs/1171769-Wetter-ZIB/episodes/6557323-Wetter',
19 u'file': u'6566957.flv',
20 u'info_dict': {
21 u'title': u'Wetter',
22 u'description': u'Christa Kummer, Marcus Wadsak und Kollegen präsentieren abwechselnd ihre täglichen Wetterprognosen für Österreich.\r \r Mehr Wetter unter wetter.ORF.at',
23 },
24 u'params': {
25 # It uses rtmp
26 u'skip_download': True,
27 }
28 }
29
30 def _real_extract(self, url):
31 mobj = re.match(self._VALID_URL, url)
32 playlist_id = mobj.group('id')
33 webpage = self._download_webpage(url, playlist_id)
34
35 flash_xml = self._search_regex('ORF.flashXML = \'(.+?)\'', webpage, u'flash xml')
36 flash_xml = compat_urlparse.parse_qs('xml='+flash_xml)['xml'][0]
37 flash_config = xml.etree.ElementTree.fromstring(flash_xml.encode('utf-8'))
38 playlist_json = self._search_regex(r'playlist\': \'(\[.*?\])\'', webpage, u'playlist').replace(r'\"','"')
39 playlist = json.loads(playlist_json)
40
41 videos = []
42 ns = '{http://tempuri.org/XMLSchema.xsd}'
43 xpath = '%(ns)sPlaylist/%(ns)sItems/%(ns)sItem' % {'ns': ns}
44 webpage_description = self._og_search_description(webpage)
45 for (i, (item, info)) in enumerate(zip(flash_config.findall(xpath), playlist), 1):
46 # Get best quality url
47 rtmp_url = None
48 for q in ['Q6A', 'Q4A', 'Q1A']:
49 video_url = find_xpath_attr(item, '%sVideoUrl' % ns, 'quality', q)
50 if video_url is not None:
51 rtmp_url = video_url.text
52 break
53 if rtmp_url is None:
54 raise ExtractorError(u'Couldn\'t get video url: %s' % info['id'])
55 description = self._html_search_regex(
56 r'id="playlist_entry_%s".*?<p>(.*?)</p>' % i, webpage,
57 u'description', default=webpage_description, flags=re.DOTALL)
58 videos.append({
59 '_type': 'video',
60 'id': info['id'],
61 'title': info['title'],
62 'url': rtmp_url,
63 'ext': 'flv',
64 'description': description,
65 })
66
67 return videos