]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/fivemin.py
debian/changelog: Highlight the fix of youtube videos.
[youtubedl] / 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 5min:)
18 (?P<id>\d+)
19 '''
20
21 _TESTS = [
22 {
23 # From http://www.engadget.com/2013/11/15/ipad-mini-retina-display-review/
24 'url': 'http://pshared.5min.com/Scripts/PlayerSeed.js?sid=281&width=560&height=345&playList=518013791',
25 'md5': '4f7b0b79bf1a470e5004f7112385941d',
26 'info_dict': {
27 'id': '518013791',
28 'ext': 'mp4',
29 'title': 'iPad Mini with Retina Display Review',
30 },
31 },
32 {
33 # From http://on.aol.com/video/how-to-make-a-next-level-fruit-salad-518086247
34 'url': '5min:518086247',
35 'md5': 'e539a9dd682c288ef5a498898009f69e',
36 'info_dict': {
37 'id': '518086247',
38 'ext': 'mp4',
39 'title': 'How to Make a Next-Level Fruit Salad',
40 },
41 },
42 ]
43
44 def _real_extract(self, url):
45 video_id = self._match_id(url)
46 embed_url = 'https://embed.5min.com/playerseed/?playList=%s' % video_id
47 embed_page = self._download_webpage(embed_url, video_id,
48 'Downloading embed page')
49 sid = self._search_regex(r'sid=(\d+)', embed_page, 'sid')
50 query = compat_urllib_parse.urlencode({
51 'func': 'GetResults',
52 'playlist': video_id,
53 'sid': sid,
54 'isPlayerSeed': 'true',
55 'url': embed_url,
56 })
57 response = self._download_json(
58 'https://syn.5min.com/handlers/SenseHandler.ashx?' + query,
59 video_id)
60 if not response['success']:
61 err_msg = response['errorMessage']
62 if err_msg == 'ErrorVideoUserNotGeo':
63 msg = 'Video not available from your location'
64 else:
65 msg = 'Aol said: %s' % err_msg
66 raise ExtractorError(msg, expected=True, video_id=video_id)
67 info = response['binding'][0]
68
69 second_id = compat_str(int(video_id[:-2]) + 1)
70 formats = []
71 for quality, height in [(1, 320), (2, 480), (4, 720), (8, 1080)]:
72 if any(r['ID'] == quality for r in info['Renditions']):
73 formats.append({
74 'format_id': compat_str(quality),
75 'url': 'http://avideos.5min.com/%s/%s/%s_%s.mp4' % (second_id[-3:], second_id, video_id, quality),
76 'height': height,
77 })
78
79 return {
80 'id': video_id,
81 'title': info['Title'],
82 'formats': formats,
83 }