]>
jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/arte.py
3 import xml
.etree
.ElementTree
5 from .common
import InfoExtractor
7 # This is used by the not implemented extractLiveStream method
14 class ArteTvIE(InfoExtractor
):
16 There are two sources of video in arte.tv: videos.arte.tv and
17 www.arte.tv/guide, the extraction process is different for each one.
18 The videos expire in 7 days, so we can't add tests.
20 _EMISSION_URL
= r
'(?:http://)?www\.arte.tv/guide/(?P<lang>fr|de)/(?:(?:sendungen|emissions)/)?(?P<id>.*?)/(?P<name>.*?)(\?.*)?'
21 _VIDEOS_URL
= r
'(?:http://)?videos.arte.tv/(?P<lang>fr|de)/.*-(?P<id>.*?).html'
22 _LIVE_URL
= r
'index-[0-9]+\.html$'
27 def suitable(cls
, url
):
28 return any(re
.match(regex
, url
) for regex
in (cls
._EMISSION
_URL
, cls
._VIDEOS
_URL
))
30 # TODO implement Live Stream
31 # def extractLiveStream(self, url):
32 # video_lang = url.split('/')[-4]
33 # info = self.grep_webpage(
35 # r'src="(.*?/videothek_js.*?\.js)',
38 # (1, 'url', u'Invalid URL: %s' % url)
41 # http_host = url.split('/')[2]
42 # next_url = 'http://%s%s' % (http_host, compat_urllib_parse.unquote(info.get('url')))
43 # info = self.grep_webpage(
45 # r'(s_artestras_scst_geoFRDE_' + video_lang + '.*?)\'.*?' +
46 # '(http://.*?\.swf).*?' +
50 # (1, 'path', u'could not extract video path: %s' % url),
51 # (2, 'player', u'could not extract video player: %s' % url),
52 # (3, 'url', u'could not extract video url: %s' % url)
55 # video_url = u'%s/%s' % (info.get('url'), info.get('path'))
57 def _real_extract(self
, url
):
58 mobj
= re
.match(self
._EMISSION
_URL
, url
)
60 name
= mobj
.group('name')
61 lang
= mobj
.group('lang')
62 # This is not a real id, it can be for example AJT for the news
63 # http://www.arte.tv/guide/fr/emissions/AJT/arte-journal
64 video_id
= mobj
.group('id')
65 return self
._extract
_emission
(url
, video_id
, lang
)
67 mobj
= re
.match(self
._VIDEOS
_URL
, url
)
70 lang
= mobj
.group('lang')
71 return self
._extract
_video
(url
, id, lang
)
73 if re
.search(self
._LIVE
_URL
, video_id
) is not None:
74 raise ExtractorError(u
'Arte live streams are not yet supported, sorry')
75 # self.extractLiveStream(url)
78 def _extract_emission(self
, url
, video_id
, lang
):
79 """Extract from www.arte.tv/guide"""
80 webpage
= self
._download
_webpage
(url
, video_id
)
81 json_url
= self
._html
_search
_regex
(r
'arte_vp_url="(.*?)"', webpage
, 'json url')
83 json_info
= self
._download
_webpage
(json_url
, video_id
, 'Downloading info json')
84 self
.report_extraction(video_id
)
85 info
= json
.loads(json_info
)
86 player_info
= info
['videoJsonPlayer']
88 info_dict
= {'id': player_info
['VID'],
89 'title': player_info
['VTI'],
90 'description': player_info
['VDE'],
91 'upload_date': unified_strdate(player_info
['VDA'].split(' ')[0]),
92 'thumbnail': player_info
['programImage'],
96 formats
= player_info
['VSR'].values()
98 # Return true if that format is in the language of the url
103 regexes
= [r
'VO?%s' % l
, r
'V%s-ST.' % l
]
104 return any(re
.match(r
, f
['versionCode']) for r
in regexes
)
105 # Some formats may not be in the same language as the url
106 formats
= filter(_match_lang
, formats
)
107 # We order the formats by quality
108 formats
= sorted(formats
, key
=lambda f
: int(f
['height']))
109 # Pick the best quality
110 format_info
= formats
[-1]
111 if format_info
['mediaType'] == u
'rtmp':
112 info_dict
['url'] = format_info
['streamer']
113 info_dict
['play_path'] = 'mp4:' + format_info
['url']
115 info_dict
['url'] = format_info
['url']
119 def _extract_video(self
, url
, video_id
, lang
):
120 """Extract from videos.arte.tv"""
121 ref_xml_url
= url
.replace('/videos/', '/do_delegate/videos/')
122 ref_xml_url
= ref_xml_url
.replace('.html', ',view,asPlayerXml.xml')
123 ref_xml
= self
._download
_webpage
(ref_xml_url
, video_id
, note
=u
'Downloading metadata')
124 ref_xml_doc
= xml
.etree
.ElementTree
.fromstring(ref_xml
)
125 config_node
= ref_xml_doc
.find('.//video[@lang="%s"]' % lang
)
126 config_xml_url
= config_node
.attrib
['ref']
127 config_xml
= self
._download
_webpage
(config_xml_url
, video_id
, note
=u
'Downloading configuration')
129 video_urls
= list(re
.finditer(r
'<url quality="(?P<quality>.*?)">(?P<url>.*?)</url>', config_xml
))
131 quality
= m
.group('quality')
136 # We pick the best quality
137 video_urls
= sorted(video_urls
, key
=_key
)
138 video_url
= list(video_urls
)[-1].group('url')
140 title
= self
._html
_search
_regex
(r
'<name>(.*?)</name>', config_xml
, 'title')
141 thumbnail
= self
._html
_search
_regex
(r
'<firstThumbnailUrl>(.*?)</firstThumbnailUrl>',
142 config_xml
, 'thumbnail')
143 return {'id': video_id
,
145 'thumbnail': thumbnail
,