]>
Commit | Line | Data |
---|---|---|
3550821f S |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | from .common import InfoExtractor | |
1e83741c | 5 | from ..utils import parse_iso8601 |
3550821f S |
6 | |
7 | ||
8 | class PeriscopeIE(InfoExtractor): | |
1e83741c | 9 | IE_DESC = 'Periscope' |
0c59d02b | 10 | _VALID_URL = r'https?://(?:www\.)?periscope\.tv/[^/]+/(?P<id>[^/?#]+)' |
53472df8 | 11 | # Alive example URLs can be found here http://onperiscope.com/ |
2549e113 | 12 | _TESTS = [{ |
3550821f S |
13 | 'url': 'https://www.periscope.tv/w/aJUQnjY3MjA3ODF8NTYxMDIyMDl2zCg2pECBgwTqRpQuQD352EMPTKQjT4uqlM3cgWFA-g==', |
14 | 'md5': '65b57957972e503fcbbaeed8f4fa04ca', | |
15 | 'info_dict': { | |
16 | 'id': '56102209', | |
17 | 'ext': 'mp4', | |
18 | 'title': 'Bec Boop - 🚠✈️🇬🇧 Fly above #London in Emirates Air Line cable car at night 🇬🇧✈️🚠 #BoopScope 🎀💗', | |
19 | 'timestamp': 1438978559, | |
20 | 'upload_date': '20150807', | |
21 | 'uploader': 'Bec Boop', | |
22 | 'uploader_id': '1465763', | |
23 | }, | |
24 | 'skip': 'Expires in 24 hours', | |
2549e113 S |
25 | }, { |
26 | 'url': 'https://www.periscope.tv/w/1ZkKzPbMVggJv', | |
27 | 'only_matching': True, | |
0c59d02b S |
28 | }, { |
29 | 'url': 'https://www.periscope.tv/bastaakanoggano/1OdKrlkZZjOJX', | |
30 | 'only_matching': True, | |
2549e113 | 31 | }] |
3550821f | 32 | |
b15c44cd | 33 | def _call_api(self, method, value): |
621d6a95 | 34 | return self._download_json( |
89abf7bf | 35 | 'https://api.periscope.tv/api/v2/%s?broadcast_id=%s' % (method, value), value) |
3550821f | 36 | |
621d6a95 S |
37 | def _real_extract(self, url): |
38 | token = self._match_id(url) | |
3550821f | 39 | |
621d6a95 | 40 | broadcast_data = self._call_api('getBroadcastPublic', token) |
3550821f S |
41 | broadcast = broadcast_data['broadcast'] |
42 | status = broadcast['status'] | |
43 | ||
44 | uploader = broadcast.get('user_display_name') or broadcast_data.get('user', {}).get('display_name') | |
45 | uploader_id = broadcast.get('user_id') or broadcast_data.get('user', {}).get('id') | |
46 | ||
47 | title = '%s - %s' % (uploader, status) if uploader else status | |
1e83741c S |
48 | state = broadcast.get('state').lower() |
49 | if state == 'running': | |
50 | title = self._live_title(title) | |
3550821f S |
51 | timestamp = parse_iso8601(broadcast.get('created_at')) |
52 | ||
53 | thumbnails = [{ | |
54 | 'url': broadcast[image], | |
55 | } for image in ('image_url', 'image_url_small') if broadcast.get(image)] | |
56 | ||
1e83741c S |
57 | stream = self._call_api('getAccessPublic', token) |
58 | ||
59 | formats = [] | |
60 | for format_id in ('replay', 'rtmp', 'hls', 'https_hls'): | |
61 | video_url = stream.get(format_id + '_url') | |
62 | if not video_url: | |
63 | continue | |
64 | f = { | |
65 | 'url': video_url, | |
66 | 'ext': 'flv' if format_id == 'rtmp' else 'mp4', | |
67 | } | |
68 | if format_id != 'rtmp': | |
69 | f['protocol'] = 'm3u8_native' if state == 'ended' else 'm3u8' | |
70 | formats.append(f) | |
71 | self._sort_formats(formats) | |
72 | ||
3550821f | 73 | return { |
621d6a95 | 74 | 'id': broadcast.get('id') or token, |
3550821f S |
75 | 'title': title, |
76 | 'timestamp': timestamp, | |
77 | 'uploader': uploader, | |
78 | 'uploader_id': uploader_id, | |
79 | 'thumbnails': thumbnails, | |
1e83741c | 80 | 'formats': formats, |
3550821f | 81 | } |