]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/rds.py
[generic] Fix dbtv test (Closes #10364)
[youtube-dl] / youtube_dl / extractor / rds.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6     parse_duration,
7     parse_iso8601,
8     js_to_json,
9 )
10 from ..compat import compat_str
11
12
13 class RDSIE(InfoExtractor):
14     IE_DESC = 'RDS.ca'
15     _VALID_URL = r'https?://(?:www\.)?rds\.ca/vid(?:[eé]|%C3%A9)os/(?:[^/]+/)*(?P<id>[^/]+)-\d+\.\d+'
16
17     _TESTS = [{
18         'url': 'http://www.rds.ca/videos/football/nfl/fowler-jr-prend-la-direction-de-jacksonville-3.1132799',
19         'info_dict': {
20             'id': '604333',
21             'display_id': 'fowler-jr-prend-la-direction-de-jacksonville',
22             'ext': 'mp4',
23             'title': 'Fowler Jr. prend la direction de Jacksonville',
24             'description': 'Dante Fowler Jr. est le troisième choix du repêchage 2015 de la NFL. ',
25             'timestamp': 1430397346,
26             'upload_date': '20150430',
27             'duration': 154.354,
28             'age_limit': 0,
29         }
30     }, {
31         'url': 'http://www.rds.ca/vid%C3%A9os/un-voyage-positif-3.877934',
32         'only_matching': True,
33     }]
34
35     def _real_extract(self, url):
36         display_id = self._match_id(url)
37
38         webpage = self._download_webpage(url, display_id)
39
40         item = self._parse_json(self._search_regex(r'(?s)itemToPush\s*=\s*({.+?});', webpage, 'item'), display_id, js_to_json)
41         video_id = compat_str(item['id'])
42         title = item.get('title') or self._og_search_title(webpage) or self._html_search_meta(
43             'title', webpage, 'title', fatal=True)
44         description = self._og_search_description(webpage) or self._html_search_meta(
45             'description', webpage, 'description')
46         thumbnail = item.get('urlImageBig') or self._og_search_thumbnail(webpage) or self._search_regex(
47             [r'<link[^>]+itemprop="thumbnailUrl"[^>]+href="([^"]+)"',
48              r'<span[^>]+itemprop="thumbnailUrl"[^>]+content="([^"]+)"'],
49             webpage, 'thumbnail', fatal=False)
50         timestamp = parse_iso8601(self._search_regex(
51             r'<span[^>]+itemprop="uploadDate"[^>]+content="([^"]+)"',
52             webpage, 'upload date', fatal=False))
53         duration = parse_duration(self._search_regex(
54             r'<span[^>]+itemprop="duration"[^>]+content="([^"]+)"',
55             webpage, 'duration', fatal=False))
56         age_limit = self._family_friendly_search(webpage)
57
58         return {
59             '_type': 'url_transparent',
60             'id': video_id,
61             'display_id': display_id,
62             'url': '9c9media:rds_web:%s' % video_id,
63             'title': title,
64             'description': description,
65             'thumbnail': thumbnail,
66             'timestamp': timestamp,
67             'duration': duration,
68             'age_limit': age_limit,
69             'ie_key': 'NineCNineMedia',
70         }