]>
Commit | Line | Data |
---|---|---|
933a5b37 JMF |
1 | from __future__ import unicode_literals |
2 | ||
933a5b37 | 3 | from .common import InfoExtractor |
5e1912cf | 4 | from ..compat import ( |
933a5b37 | 5 | compat_str, |
8f5c0218 | 6 | compat_urllib_parse, |
5e1912cf PH |
7 | ) |
8 | from ..utils import ( | |
57b8d84c | 9 | ExtractorError, |
933a5b37 JMF |
10 | ) |
11 | ||
12 | ||
13 | class FiveMinIE(InfoExtractor): | |
14 | IE_NAME = '5min' | |
15 | _VALID_URL = r'''(?x) | |
5e1912cf | 16 | (?:https?://[^/]*?5min\.com/Scripts/PlayerSeed\.js\?(?:.*?&)?playList=| |
d5c69f1d | 17 | https?://(?:(?:massively|www)\.)?joystiq\.com/video/| |
933a5b37 JMF |
18 | 5min:) |
19 | (?P<id>\d+) | |
20 | ''' | |
21 | ||
8f5c0218 JMF |
22 | _TESTS = [ |
23 | { | |
24 | # From http://www.engadget.com/2013/11/15/ipad-mini-retina-display-review/ | |
25 | 'url': 'http://pshared.5min.com/Scripts/PlayerSeed.js?sid=281&width=560&height=345&playList=518013791', | |
26 | 'md5': '4f7b0b79bf1a470e5004f7112385941d', | |
27 | 'info_dict': { | |
28 | 'id': '518013791', | |
29 | 'ext': 'mp4', | |
30 | 'title': 'iPad Mini with Retina Display Review', | |
31 | }, | |
933a5b37 | 32 | }, |
8f5c0218 JMF |
33 | { |
34 | # From http://on.aol.com/video/how-to-make-a-next-level-fruit-salad-518086247 | |
35 | 'url': '5min:518086247', | |
36 | 'md5': 'e539a9dd682c288ef5a498898009f69e', | |
37 | 'info_dict': { | |
38 | 'id': '518086247', | |
39 | 'ext': 'mp4', | |
40 | 'title': 'How to Make a Next-Level Fruit Salad', | |
41 | }, | |
42 | }, | |
43 | ] | |
933a5b37 | 44 | |
933a5b37 | 45 | def _real_extract(self, url): |
5e1912cf | 46 | video_id = self._match_id(url) |
8f5c0218 JMF |
47 | embed_url = 'https://embed.5min.com/playerseed/?playList=%s' % video_id |
48 | embed_page = self._download_webpage(embed_url, video_id, | |
9e1a5b84 | 49 | 'Downloading embed page') |
8f5c0218 JMF |
50 | sid = self._search_regex(r'sid=(\d+)', embed_page, 'sid') |
51 | query = compat_urllib_parse.urlencode({ | |
52 | 'func': 'GetResults', | |
53 | 'playlist': video_id, | |
54 | 'sid': sid, | |
55 | 'isPlayerSeed': 'true', | |
56 | 'url': embed_url, | |
57 | }) | |
57b8d84c | 58 | response = self._download_json( |
8f5c0218 | 59 | 'https://syn.5min.com/handlers/SenseHandler.ashx?' + query, |
57b8d84c JMF |
60 | video_id) |
61 | if not response['success']: | |
62 | err_msg = response['errorMessage'] | |
63 | if err_msg == 'ErrorVideoUserNotGeo': | |
64 | msg = 'Video not available from your location' | |
65 | else: | |
66 | msg = 'Aol said: %s' % err_msg | |
67 | raise ExtractorError(msg, expected=True, video_id=video_id) | |
68 | info = response['binding'][0] | |
933a5b37 JMF |
69 | |
70 | second_id = compat_str(int(video_id[:-2]) + 1) | |
71 | formats = [] | |
72 | for quality, height in [(1, 320), (2, 480), (4, 720), (8, 1080)]: | |
73 | if any(r['ID'] == quality for r in info['Renditions']): | |
74 | formats.append({ | |
75 | 'format_id': compat_str(quality), | |
76 | 'url': 'http://avideos.5min.com/%s/%s/%s_%s.mp4' % (second_id[-3:], second_id, video_id, quality), | |
77 | 'height': height, | |
78 | }) | |
79 | ||
80 | return { | |
81 | 'id': video_id, | |
82 | 'title': info['Title'], | |
83 | 'formats': formats, | |
84 | } |