]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/uplynk.py
d/p/skip-style-checks-for-flake8: Add metadata to please lintian.
[youtubedl] / youtube_dl / extractor / uplynk.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8 float_or_none,
9 ExtractorError,
10 )
11
12
13 class UplynkIE(InfoExtractor):
14 IE_NAME = 'uplynk'
15 _VALID_URL = r'https?://.*?\.uplynk\.com/(?P<path>ext/[0-9a-f]{32}/(?P<external_id>[^/?&]+)|(?P<id>[0-9a-f]{32}))\.(?:m3u8|json)(?:.*?\bpbs=(?P<session_id>[^&]+))?'
16 _TEST = {
17 'url': 'http://content.uplynk.com/e89eaf2ce9054aa89d92ddb2d817a52e.m3u8',
18 'info_dict': {
19 'id': 'e89eaf2ce9054aa89d92ddb2d817a52e',
20 'ext': 'mp4',
21 'title': '030816-kgo-530pm-solar-eclipse-vid_web.mp4',
22 'uploader_id': '4413701bf5a1488db55b767f8ae9d4fa',
23 },
24 'params': {
25 # m3u8 download
26 'skip_download': True,
27 },
28 }
29
30 def _extract_uplynk_info(self, uplynk_content_url):
31 path, external_id, video_id, session_id = re.match(UplynkIE._VALID_URL, uplynk_content_url).groups()
32 display_id = video_id or external_id
33 formats = self._extract_m3u8_formats(
34 'http://content.uplynk.com/%s.m3u8' % path,
35 display_id, 'mp4', 'm3u8_native')
36 if session_id:
37 for f in formats:
38 f['extra_param_to_segment_url'] = 'pbs=' + session_id
39 self._sort_formats(formats)
40 asset = self._download_json('http://content.uplynk.com/player/assetinfo/%s.json' % path, display_id)
41 if asset.get('error') == 1:
42 raise ExtractorError('% said: %s' % (self.IE_NAME, asset['msg']), expected=True)
43
44 return {
45 'id': asset['asset'],
46 'title': asset['desc'],
47 'thumbnail': asset.get('default_poster_url'),
48 'duration': float_or_none(asset.get('duration')),
49 'uploader_id': asset.get('owner'),
50 'formats': formats,
51 }
52
53 def _real_extract(self, url):
54 return self._extract_uplynk_info(url)
55
56
57 class UplynkPreplayIE(UplynkIE):
58 IE_NAME = 'uplynk:preplay'
59 _VALID_URL = r'https?://.*?\.uplynk\.com/preplay2?/(?P<path>ext/[0-9a-f]{32}/(?P<external_id>[^/?&]+)|(?P<id>[0-9a-f]{32}))\.json'
60 _TEST = None
61
62 def _real_extract(self, url):
63 path, external_id, video_id = re.match(self._VALID_URL, url).groups()
64 display_id = video_id or external_id
65 preplay = self._download_json(url, display_id)
66 content_url = 'http://content.uplynk.com/%s.m3u8' % path
67 session_id = preplay.get('sid')
68 if session_id:
69 content_url += '?pbs=' + session_id
70 return self._extract_uplynk_info(content_url)