]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/nowness.py
Prepare for release.
[youtubedl] / youtube_dl / extractor / nowness.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .brightcove import BrightcoveIE
7 from .common import InfoExtractor
8 from ..utils import ExtractorError
9
10
11 class NownessIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:(?:www|cn)\.)?nowness\.com/[^?#]*?/(?P<id>[0-9]+)/(?P<slug>[^/]+?)(?:$|[?#])'
13
14 _TESTS = [
15 {
16 'url': 'http://www.nowness.com/day/2013/6/27/3131/candor--the-art-of-gesticulation',
17 'md5': '068bc0202558c2e391924cb8cc470676',
18 'info_dict': {
19 'id': '2520295746001',
20 'ext': 'mp4',
21 'title': 'Candor: The Art of Gesticulation',
22 'description': 'Candor: The Art of Gesticulation',
23 'thumbnail': 're:^https?://.*\.jpg',
24 'uploader': 'Nowness',
25 }
26 },
27 {
28 'url': 'http://cn.nowness.com/day/2014/8/7/4069/kasper-bj-rke-ft-jaakko-eino-kalevi--tnr',
29 'md5': 'e79cf125e387216f86b2e0a5b5c63aa3',
30 'info_dict': {
31 'id': '3716354522001',
32 'ext': 'mp4',
33 'title': 'Kasper Bjørke ft. Jaakko Eino Kalevi: TNR',
34 'description': 'Kasper Bjørke ft. Jaakko Eino Kalevi: TNR',
35 'thumbnail': 're:^https?://.*\.jpg',
36 'uploader': 'Nowness',
37 }
38 },
39 ]
40
41 def _real_extract(self, url):
42 mobj = re.match(self._VALID_URL, url)
43 video_id = mobj.group('slug')
44
45 webpage = self._download_webpage(url, video_id)
46 player_url = self._search_regex(
47 r'"([^"]+/content/issue-[0-9.]+.js)"', webpage, 'player URL')
48 real_id = self._search_regex(
49 r'\sdata-videoId="([0-9]+)"', webpage, 'internal video ID')
50
51 player_code = self._download_webpage(
52 player_url, video_id,
53 note='Downloading player JavaScript',
54 errnote='Player download failed')
55 player_code = player_code.replace("'+d+'", real_id)
56
57 bc_url = BrightcoveIE._extract_brightcove_url(player_code)
58 if bc_url is None:
59 raise ExtractorError('Could not find player definition')
60 return {
61 '_type': 'url',
62 'url': bc_url,
63 'ie_key': 'Brightcove',
64 }