]>
RaphaΓ«l G. Git Repositories - youtubedl/blob - youtube_dl/extractor/periscope.py
63cc764bb8eceed80893606e640466b355279a0d
2 from __future__
import unicode_literals
4 from .common
import InfoExtractor
5 from ..utils
import parse_iso8601
8 class PeriscopeIE(InfoExtractor
):
10 _VALID_URL
= r
'https?://(?:www\.)?periscope\.tv/[^/]+/(?P<id>[^/?#]+)'
11 # Alive example URLs can be found here http://onperiscope.com/
13 'url': 'https://www.periscope.tv/w/aJUQnjY3MjA3ODF8NTYxMDIyMDl2zCg2pECBgwTqRpQuQD352EMPTKQjT4uqlM3cgWFA-g==',
14 'md5': '65b57957972e503fcbbaeed8f4fa04ca',
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',
24 'skip': 'Expires in 24 hours',
26 'url': 'https://www.periscope.tv/w/1ZkKzPbMVggJv',
27 'only_matching': True,
29 'url': 'https://www.periscope.tv/bastaakanoggano/1OdKrlkZZjOJX',
30 'only_matching': True,
33 def _call_api(self
, method
, value
):
34 attribute
= 'token' if len(value
) > 13 else 'broadcast_id'
35 return self
._download
_json
(
36 'https://api.periscope.tv/api/v2/%s?%s=%s' % (method
, attribute
, value
), value
)
38 def _real_extract(self
, url
):
39 token
= self
._match
_id
(url
)
41 broadcast_data
= self
._call
_api
('getBroadcastPublic', token
)
42 broadcast
= broadcast_data
['broadcast']
43 status
= broadcast
['status']
45 uploader
= broadcast
.get('user_display_name') or broadcast_data
.get('user', {}).get('display_name')
46 uploader_id
= broadcast
.get('user_id') or broadcast_data
.get('user', {}).get('id')
48 title
= '%s - %s' % (uploader
, status
) if uploader
else status
49 state
= broadcast
.get('state').lower()
50 if state
== 'running':
51 title
= self
._live
_title
(title
)
52 timestamp
= parse_iso8601(broadcast
.get('created_at'))
55 'url': broadcast
[image
],
56 } for image
in ('image_url', 'image_url_small') if broadcast
.get(image
)]
58 stream
= self
._call
_api
('getAccessPublic', token
)
61 for format_id
in ('replay', 'rtmp', 'hls', 'https_hls'):
62 video_url
= stream
.get(format_id
+ '_url')
67 'ext': 'flv' if format_id
== 'rtmp' else 'mp4',
69 if format_id
!= 'rtmp':
70 f
['protocol'] = 'm3u8_native' if state
== 'ended' else 'm3u8'
72 self
._sort
_formats
(formats
)
75 'id': broadcast
.get('id') or token
,
77 'timestamp': timestamp
,
79 'uploader_id': uploader_id
,
80 'thumbnails': thumbnails
,