]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/rmcdecouverte.py
Fix extraction from youtube.
[youtubedl] / youtube_dl / extractor / rmcdecouverte.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from .brightcove import BrightcoveLegacyIE
8 from ..compat import (
9 compat_parse_qs,
10 compat_urlparse,
11 )
12 from ..utils import smuggle_url
13
14
15 class RMCDecouverteIE(InfoExtractor):
16 _VALID_URL = r'https?://rmcdecouverte\.bfmtv\.com/(?:(?:[^/]+/)*program_(?P<id>\d+)|(?P<live_id>mediaplayer-direct))'
17
18 _TESTS = [{
19 'url': 'https://rmcdecouverte.bfmtv.com/wheeler-dealers-occasions-a-saisir/program_2566/',
20 'info_dict': {
21 'id': '5983675500001',
22 'ext': 'mp4',
23 'title': 'CORVETTE',
24 'description': 'md5:c1e8295521e45ffebf635d6a7658f506',
25 'uploader_id': '1969646226001',
26 'upload_date': '20181226',
27 'timestamp': 1545861635,
28 },
29 'params': {
30 'skip_download': True,
31 },
32 'skip': 'only available for a week',
33 }, {
34 # live, geo restricted, bypassable
35 'url': 'https://rmcdecouverte.bfmtv.com/mediaplayer-direct/',
36 'only_matching': True,
37 }]
38 BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/1969646226001/default_default/index.html?videoId=%s'
39
40 def _real_extract(self, url):
41 mobj = re.match(self._VALID_URL, url)
42 display_id = mobj.group('id') or mobj.group('live_id')
43 webpage = self._download_webpage(url, display_id)
44 brightcove_legacy_url = BrightcoveLegacyIE._extract_brightcove_url(webpage)
45 if brightcove_legacy_url:
46 brightcove_id = compat_parse_qs(compat_urlparse.urlparse(
47 brightcove_legacy_url).query)['@videoPlayer'][0]
48 else:
49 brightcove_id = self._search_regex(
50 r'data-video-id=["\'](\d+)', webpage, 'brightcove id')
51 return self.url_result(
52 smuggle_url(
53 self.BRIGHTCOVE_URL_TEMPLATE % brightcove_id,
54 {'geo_countries': ['FR']}),
55 'BrightcoveNew', brightcove_id)