]>
RaphaΓ«l G. Git Repositories - youtubedl/blob - youtube_dl/extractor/periscope.py
2 from __future__
import unicode_literals
4 from .common
import InfoExtractor
11 class PeriscopeIE(InfoExtractor
):
14 _VALID_URL
= r
'https?://(?:www\.)?periscope\.tv/[^/]+/(?P<id>[^/?#]+)'
15 # Alive example URLs can be found here http://onperiscope.com/
17 'url': 'https://www.periscope.tv/w/aJUQnjY3MjA3ODF8NTYxMDIyMDl2zCg2pECBgwTqRpQuQD352EMPTKQjT4uqlM3cgWFA-g==',
18 'md5': '65b57957972e503fcbbaeed8f4fa04ca',
22 'title': 'Bec Boop - π βοΈπ¬π§ Fly above #London in Emirates Air Line cable car at night π¬π§βοΈπ #BoopScope ππ',
23 'timestamp': 1438978559,
24 'upload_date': '20150807',
25 'uploader': 'Bec Boop',
26 'uploader_id': '1465763',
28 'skip': 'Expires in 24 hours',
30 'url': 'https://www.periscope.tv/w/1ZkKzPbMVggJv',
31 'only_matching': True,
33 'url': 'https://www.periscope.tv/bastaakanoggano/1OdKrlkZZjOJX',
34 'only_matching': True,
37 def _call_api(self
, method
, value
):
38 return self
._download
_json
(
39 'https://api.periscope.tv/api/v2/%s?broadcast_id=%s' % (method
, value
), value
)
41 def _real_extract(self
, url
):
42 token
= self
._match
_id
(url
)
44 broadcast_data
= self
._call
_api
('getBroadcastPublic', token
)
45 broadcast
= broadcast_data
['broadcast']
46 status
= broadcast
['status']
48 user
= broadcast_data
.get('user', {})
50 uploader
= broadcast
.get('user_display_name') or user
.get('display_name')
51 uploader_id
= (broadcast
.get('username') or user
.get('username') or
52 broadcast
.get('user_id') or user
.get('id'))
54 title
= '%s - %s' % (uploader
, status
) if uploader
else status
55 state
= broadcast
.get('state').lower()
56 if state
== 'running':
57 title
= self
._live
_title
(title
)
58 timestamp
= parse_iso8601(broadcast
.get('created_at'))
61 'url': broadcast
[image
],
62 } for image
in ('image_url', 'image_url_small') if broadcast
.get(image
)]
64 stream
= self
._call
_api
('getAccessPublic', token
)
67 for format_id
in ('replay', 'rtmp', 'hls', 'https_hls'):
68 video_url
= stream
.get(format_id
+ '_url')
73 'ext': 'flv' if format_id
== 'rtmp' else 'mp4',
75 if format_id
!= 'rtmp':
76 f
['protocol'] = 'm3u8_native' if state
== 'ended' else 'm3u8'
78 self
._sort
_formats
(formats
)
81 'id': broadcast
.get('id') or token
,
83 'timestamp': timestamp
,
85 'uploader_id': uploader_id
,
86 'thumbnails': thumbnails
,
91 class PeriscopeUserIE(InfoExtractor
):
92 _VALID_URL
= r
'https?://www\.periscope\.tv/(?P<id>[^/]+)/?$'
93 IE_DESC
= 'Periscope user videos'
94 IE_NAME
= 'periscope:user'
97 'url': 'https://www.periscope.tv/LularoeHusbandMike/',
99 'id': 'LularoeHusbandMike',
100 'title': 'LULAROE HUSBAND MIKE',
101 'description': 'md5:6cf4ec8047768098da58e446e82c82f0',
103 # Periscope only shows videos in the last 24 hours, so it's possible to
105 'playlist_mincount': 0,
108 def _real_extract(self
, url
):
109 user_id
= self
._match
_id
(url
)
111 webpage
= self
._download
_webpage
(url
, user_id
)
113 data_store
= self
._parse
_json
(
114 unescapeHTML(self
._search
_regex
(
115 r
'data-store=(["\'])(?P
<data
>.+?
)\
1',
116 webpage, 'data store
', default='{}', group='data
')),
119 user = data_store.get('User
', {}).get('user
', {})
120 title = user.get('display_name
') or user.get('username
')
121 description = user.get('description
')
125 'https
://www
.periscope
.tv
/%s/%s' % (user_id, broadcast['id']))
126 for broadcast in data_store.get('UserBroadcastHistory
', {}).get('broadcasts
', [])]
128 return self.playlist_result(entries, user_id, title, description)