]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/fivemin.py
[nowness] Add vimeo test
[youtube-dl] / youtube_dl / extractor / fivemin.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..compat import (
5     compat_str,
6     compat_urllib_parse,
7 )
8 from ..utils import (
9     ExtractorError,
10 )
11
12
13 class FiveMinIE(InfoExtractor):
14     IE_NAME = '5min'
15     _VALID_URL = r'''(?x)
16         (?:https?://[^/]*?5min\.com/Scripts/PlayerSeed\.js\?(?:.*?&)?playList=|
17             https?://(?:(?:massively|www)\.)?joystiq\.com/video/|
18             5min:)
19         (?P<id>\d+)
20         '''
21
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             },
32         },
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     ]
44
45     def _real_extract(self, url):
46         video_id = self._match_id(url)
47         embed_url = 'https://embed.5min.com/playerseed/?playList=%s' % video_id
48         embed_page = self._download_webpage(embed_url, video_id,
49                                             'Downloading embed page')
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         })
58         response = self._download_json(
59             'https://syn.5min.com/handlers/SenseHandler.ashx?' + query,
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]
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         }