]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/vrak.py
Prepare to release.
[youtubedl] / youtube_dl / extractor / vrak.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 BrightcoveNewIE
8 from ..utils import (
9 int_or_none,
10 parse_age_limit,
11 smuggle_url,
12 unescapeHTML,
13 )
14
15
16 class VrakIE(InfoExtractor):
17 _VALID_URL = r'https?://(?:www\.)?vrak\.tv/videos\?.*?\btarget=(?P<id>[\d.]+)'
18 _TEST = {
19 'url': 'http://www.vrak.tv/videos?target=1.2306782&filtre=emission&id=1.1806721',
20 'info_dict': {
21 'id': '5345661243001',
22 'ext': 'mp4',
23 'title': 'Obésité, film de hockey et Roseline Filion',
24 'timestamp': 1488492126,
25 'upload_date': '20170302',
26 'uploader_id': '2890187628001',
27 'creator': 'VRAK.TV',
28 'age_limit': 8,
29 'series': 'ALT (Actualité Légèrement Tordue)',
30 'episode': 'Obésité, film de hockey et Roseline Filion',
31 'tags': list,
32 },
33 'params': {
34 'skip_download': True,
35 },
36 }
37 BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/2890187628001/default_default/index.html?videoId=%s'
38
39 def _real_extract(self, url):
40 video_id = self._match_id(url)
41
42 webpage = self._download_webpage(url, video_id)
43
44 title = self._html_search_regex(
45 r'<h\d\b[^>]+\bclass=["\']videoTitle["\'][^>]*>([^<]+)',
46 webpage, 'title', default=None) or self._og_search_title(webpage)
47
48 content = self._parse_json(
49 self._search_regex(
50 r'data-player-options-content=(["\'])(?P<content>{.+?})\1',
51 webpage, 'content', default='{}', group='content'),
52 video_id, transform_source=unescapeHTML)
53
54 ref_id = content.get('refId') or self._search_regex(
55 r'refId&quot;:&quot;([^&]+)&quot;', webpage, 'ref id')
56
57 brightcove_id = self._search_regex(
58 r'''(?x)
59 java\.lang\.String\s+value\s*=\s*["']brightcove\.article\.\d+\.%s
60 [^>]*
61 java\.lang\.String\s+value\s*=\s*["'](\d+)
62 ''' % re.escape(ref_id), webpage, 'brightcove id')
63
64 return {
65 '_type': 'url_transparent',
66 'ie_key': BrightcoveNewIE.ie_key(),
67 'url': smuggle_url(
68 self.BRIGHTCOVE_URL_TEMPLATE % brightcove_id,
69 {'geo_countries': ['CA']}),
70 'id': brightcove_id,
71 'description': content.get('description'),
72 'creator': content.get('brand'),
73 'age_limit': parse_age_limit(content.get('rating')),
74 'series': content.get('showName') or content.get(
75 'episodeName'), # this is intentional
76 'season_number': int_or_none(content.get('seasonNumber')),
77 'episode': title,
78 'episode_number': int_or_none(content.get('episodeNumber')),
79 'tags': content.get('tags', []),
80 }