]>
Commit | Line | Data |
---|---|---|
b9e8d714 PG |
1 | from __future__ import unicode_literals |
2 | ||
3 | import re | |
b9e8d714 | 4 | |
c8a80fd8 S |
5 | from .common import InfoExtractor |
6 | from ..compat import compat_str | |
b9e8d714 PG |
7 | from ..utils import ( |
8 | int_or_none, | |
c8a80fd8 | 9 | parse_age_limit, |
b9e8d714 PG |
10 | ) |
11 | ||
b9e8d714 | 12 | |
c8a80fd8 | 13 | class ScreenJunkiesIE(InfoExtractor): |
5886b38d | 14 | _VALID_URL = r'https?://www.screenjunkies.com/video/(?P<display_id>[^/]+?)(?:-(?P<id>\d+))?(?:[/?#&]|$)' |
b9e8d714 PG |
15 | _TESTS = [{ |
16 | 'url': 'http://www.screenjunkies.com/video/best-quentin-tarantino-movie-2841915', | |
c8a80fd8 | 17 | 'md5': '5c2b686bec3d43de42bde9ec047536b0', |
b9e8d714 PG |
18 | 'info_dict': { |
19 | 'id': '2841915', | |
c8a80fd8 | 20 | 'display_id': 'best-quentin-tarantino-movie', |
b9e8d714 PG |
21 | 'ext': 'mp4', |
22 | 'title': 'Best Quentin Tarantino Movie', | |
c8a80fd8 S |
23 | 'thumbnail': 're:^https?://.*\.jpg', |
24 | 'duration': 3671, | |
25 | 'age_limit': 13, | |
26 | 'tags': list, | |
b9e8d714 PG |
27 | }, |
28 | }, { | |
29 | 'url': 'http://www.screenjunkies.com/video/honest-trailers-the-dark-knight', | |
30 | 'info_dict': { | |
31 | 'id': '2348808', | |
c8a80fd8 | 32 | 'display_id': 'honest-trailers-the-dark-knight', |
b9e8d714 | 33 | 'ext': 'mp4', |
c8a80fd8 S |
34 | 'title': "Honest Trailers: 'The Dark Knight'", |
35 | 'thumbnail': 're:^https?://.*\.jpg', | |
36 | 'age_limit': 10, | |
37 | 'tags': list, | |
b9e8d714 PG |
38 | }, |
39 | }, { | |
c8a80fd8 | 40 | # requires subscription but worked around |
b9e8d714 | 41 | 'url': 'http://www.screenjunkies.com/video/knocking-dead-ep-1-the-show-so-far-3003285', |
c8a80fd8 S |
42 | 'info_dict': { |
43 | 'id': '3003285', | |
44 | 'display_id': 'knocking-dead-ep-1-the-show-so-far', | |
45 | 'ext': 'mp4', | |
46 | 'title': 'Knocking Dead Ep 1: State of The Dead Recap', | |
47 | 'thumbnail': 're:^https?://.*\.jpg', | |
48 | 'duration': 3307, | |
49 | 'age_limit': 13, | |
50 | 'tags': list, | |
51 | }, | |
b9e8d714 PG |
52 | }] |
53 | ||
c8a80fd8 S |
54 | _DEFAULT_BITRATES = (48, 150, 496, 864, 2240) |
55 | ||
b9e8d714 | 56 | def _real_extract(self, url): |
c8a80fd8 S |
57 | mobj = re.match(self._VALID_URL, url) |
58 | video_id = mobj.group('id') | |
59 | display_id = mobj.group('display_id') | |
b9e8d714 | 60 | |
c8a80fd8 S |
61 | if not video_id: |
62 | webpage = self._download_webpage(url, display_id) | |
63 | video_id = self._search_regex( | |
64 | (r'src=["\']/embed/(\d+)', r'data-video-content-id=["\'](\d+)'), | |
65 | webpage, 'video id') | |
b9e8d714 | 66 | |
c8a80fd8 S |
67 | webpage = self._download_webpage( |
68 | 'http://www.screenjunkies.com/embed/%s' % video_id, | |
69 | display_id, 'Downloading video embed page') | |
70 | embed_vars = self._parse_json( | |
71 | self._search_regex( | |
72 | r'(?s)embedVars\s*=\s*({.+?})\s*</script>', webpage, 'embed vars'), | |
73 | display_id) | |
b9e8d714 | 74 | |
c8a80fd8 | 75 | title = embed_vars['contentName'] |
b9e8d714 PG |
76 | |
77 | formats = [] | |
c8a80fd8 S |
78 | bitrates = [] |
79 | for f in embed_vars.get('media', []): | |
80 | if not f.get('uri') or f.get('mediaPurpose') != 'play': | |
b9e8d714 | 81 | continue |
c8a80fd8 S |
82 | bitrate = int_or_none(f.get('bitRate')) |
83 | if bitrate: | |
84 | bitrates.append(bitrate) | |
b9e8d714 PG |
85 | formats.append({ |
86 | 'url': f['uri'], | |
c8a80fd8 | 87 | 'format_id': 'http-%d' % bitrate if bitrate else 'http', |
b9e8d714 PG |
88 | 'width': int_or_none(f.get('width')), |
89 | 'height': int_or_none(f.get('height')), | |
c8a80fd8 | 90 | 'tbr': bitrate, |
b9e8d714 PG |
91 | 'format': 'mp4', |
92 | }) | |
c8a80fd8 S |
93 | |
94 | if not bitrates: | |
95 | # When subscriptionLevel > 0, i.e. plus subscription is required | |
f66a3c7b S |
96 | # media list will be empty. However, hds and hls uris are still |
97 | # available. We can grab them assuming bitrates to be default. | |
c8a80fd8 S |
98 | bitrates = self._DEFAULT_BITRATES |
99 | ||
100 | auth_token = embed_vars.get('AuthToken') | |
101 | ||
102 | def construct_manifest_url(base_url, ext): | |
103 | pieces = [base_url] | |
104 | pieces.extend([compat_str(b) for b in bitrates]) | |
105 | pieces.append('_kbps.mp4.%s?%s' % (ext, auth_token)) | |
106 | return ','.join(pieces) | |
107 | ||
108 | if bitrates and auth_token: | |
109 | hds_url = embed_vars.get('hdsUri') | |
110 | if hds_url: | |
111 | f4m_formats = self._extract_f4m_formats( | |
112 | construct_manifest_url(hds_url, 'f4m'), | |
113 | display_id, f4m_id='hds', fatal=False) | |
114 | if len(f4m_formats) == len(bitrates): | |
115 | for f, bitrate in zip(f4m_formats, bitrates): | |
116 | if not f.get('tbr'): | |
117 | f['format_id'] = 'hds-%d' % bitrate | |
118 | f['tbr'] = bitrate | |
119 | # TODO: fix f4m downloader to handle manifests without bitrates if possible | |
120 | # formats.extend(f4m_formats) | |
121 | ||
122 | hls_url = embed_vars.get('hlsUri') | |
123 | if hls_url: | |
124 | formats.extend(self._extract_m3u8_formats( | |
125 | construct_manifest_url(hls_url, 'm3u8'), | |
126 | display_id, 'mp4', entry_protocol='m3u8_native', m3u8_id='hls', fatal=False)) | |
b9e8d714 PG |
127 | self._sort_formats(formats) |
128 | ||
129 | return { | |
130 | 'id': video_id, | |
c8a80fd8 S |
131 | 'display_id': display_id, |
132 | 'title': title, | |
133 | 'thumbnail': embed_vars.get('thumbUri'), | |
134 | 'duration': int_or_none(embed_vars.get('videoLengthInSeconds')) or None, | |
135 | 'age_limit': parse_age_limit(embed_vars.get('audienceRating')), | |
136 | 'tags': embed_vars.get('tags', '').split(','), | |
b9e8d714 | 137 | 'formats': formats, |
b9e8d714 | 138 | } |