mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-01 09:13:20 +01:00
[twitcasting] Websocket support (#399)
Closes #392 Authored by: nao20010128nao
This commit is contained in:
parent
e36d50c5dd
commit
e6779b9400
@ -5,12 +5,14 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
|
from ..downloader.websocket import has_websockets
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
clean_html,
|
clean_html,
|
||||||
float_or_none,
|
float_or_none,
|
||||||
get_element_by_class,
|
get_element_by_class,
|
||||||
get_element_by_id,
|
get_element_by_id,
|
||||||
parse_duration,
|
parse_duration,
|
||||||
|
qualities,
|
||||||
str_to_int,
|
str_to_int,
|
||||||
try_get,
|
try_get,
|
||||||
unified_timestamp,
|
unified_timestamp,
|
||||||
@ -89,9 +91,24 @@ def _real_extract(self, url):
|
|||||||
video_js_data = video_js_data[0]
|
video_js_data = video_js_data[0]
|
||||||
m3u8_url = try_get(video_js_data, lambda x: x['source']['url'])
|
m3u8_url = try_get(video_js_data, lambda x: x['source']['url'])
|
||||||
|
|
||||||
|
stream_server_data = self._download_json(
|
||||||
|
'https://twitcasting.tv/streamserver.php?target=%s&mode=client' % uploader_id, video_id,
|
||||||
|
'Downloading live info', fatal=False)
|
||||||
|
|
||||||
is_live = 'data-status="online"' in webpage
|
is_live = 'data-status="online"' in webpage
|
||||||
|
formats = []
|
||||||
if is_live and not m3u8_url:
|
if is_live and not m3u8_url:
|
||||||
m3u8_url = 'https://twitcasting.tv/%s/metastream.m3u8' % uploader_id
|
m3u8_url = 'https://twitcasting.tv/%s/metastream.m3u8' % uploader_id
|
||||||
|
if is_live and has_websockets and stream_server_data:
|
||||||
|
qq = qualities(['base', 'mobilesource', 'main'])
|
||||||
|
for mode, ws_url in stream_server_data['llfmp4']['streams'].items():
|
||||||
|
formats.append({
|
||||||
|
'url': ws_url,
|
||||||
|
'format_id': 'ws-%s' % mode,
|
||||||
|
'ext': 'mp4',
|
||||||
|
'quality': qq(mode),
|
||||||
|
'protocol': 'websocket_frag', # TwitCasting simply sends moof atom directly over WS
|
||||||
|
})
|
||||||
|
|
||||||
thumbnail = video_js_data.get('thumbnailUrl') or self._og_search_thumbnail(webpage)
|
thumbnail = video_js_data.get('thumbnailUrl') or self._og_search_thumbnail(webpage)
|
||||||
description = clean_html(get_element_by_id(
|
description = clean_html(get_element_by_id(
|
||||||
@ -106,10 +123,9 @@ def _real_extract(self, url):
|
|||||||
r'data-toggle="true"[^>]+datetime="([^"]+)"',
|
r'data-toggle="true"[^>]+datetime="([^"]+)"',
|
||||||
webpage, 'datetime', None))
|
webpage, 'datetime', None))
|
||||||
|
|
||||||
formats = None
|
|
||||||
if m3u8_url:
|
if m3u8_url:
|
||||||
formats = self._extract_m3u8_formats(
|
formats.extend(self._extract_m3u8_formats(
|
||||||
m3u8_url, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', live=is_live)
|
m3u8_url, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', live=is_live))
|
||||||
self._sort_formats(formats)
|
self._sort_formats(formats)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
Loading…
Reference in New Issue
Block a user