Skip to content

Commit

Permalink
[ie/twitter:broadcast] Support --wait-for-video
Browse files Browse the repository at this point in the history
Closes #8473
Authored by: bashonly
  • Loading branch information
bashonly committed Oct 30, 2023
1 parent 4a601c9 commit e636a95
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 8 additions & 4 deletions yt_dlp/extractor/periscope.py
Expand Up @@ -2,6 +2,7 @@
from ..utils import (
int_or_none,
parse_iso8601,
traverse_obj,
unescapeHTML,
)

Expand All @@ -20,22 +21,25 @@ def _parse_broadcast_data(self, broadcast, video_id):
title = broadcast.get('status') or 'Periscope Broadcast'
uploader = broadcast.get('user_display_name') or broadcast.get('username')
title = '%s - %s' % (uploader, title) if uploader else title
is_live = broadcast.get('state').lower() == 'running'

thumbnails = [{
'url': broadcast[image],
} for image in ('image_url', 'image_url_small') if broadcast.get(image)]

return {
'id': broadcast.get('id') or video_id,
'title': title,
'timestamp': parse_iso8601(broadcast.get('created_at')),
'timestamp': parse_iso8601(broadcast.get('created_at')) or int_or_none(
broadcast.get('created_at_ms'), scale=1000),
'release_timestamp': int_or_none(broadcast.get('scheduled_start_ms'), scale=1000),
'uploader': uploader,
'uploader_id': broadcast.get('user_id') or broadcast.get('username'),
'thumbnails': thumbnails,
'view_count': int_or_none(broadcast.get('total_watched')),
'tags': broadcast.get('tags'),
'is_live': is_live,
'live_status': {
'running': 'is_live',
'not_started': 'is_upcoming',
}.get(traverse_obj(broadcast, ('state', {str.lower}))) or 'was_live'
}

@staticmethod
Expand Down
2 changes: 2 additions & 0 deletions yt_dlp/extractor/twitter.py
Expand Up @@ -1585,6 +1585,8 @@ def _real_extract(self, url):
if not broadcast:
raise ExtractorError('Broadcast no longer exists', expected=True)
info = self._parse_broadcast_data(broadcast, broadcast_id)
if info['live_status'] == 'is_upcoming':
return info
media_key = broadcast['media_key']
source = self._call_api(
f'live_video_stream/status/{media_key}', media_key)['source']
Expand Down

0 comments on commit e636a95

Please sign in to comment.