mirror of
https://github.com/yt-dlp/yt-dlp
synced 2025-01-15 03:41:33 +01:00
[ie/niconico] Apply suggestions: info_dict, protocols and downloaders
- Use "downloader_options" to pass options used by the downloader. - Combine the two downloaders into one. - Don't inherit from "HlsFD". Co-authored-by: pukkandan <pukkandan.ytdlp@gmail.com>
This commit is contained in:
parent
7398a7cb2f
commit
972a2d51ad
3 changed files with 20 additions and 28 deletions
|
@ -30,7 +30,7 @@ from .hls import HlsFD
|
|||
from .http import HttpFD
|
||||
from .ism import IsmFD
|
||||
from .mhtml import MhtmlFD
|
||||
from .niconico import NiconicoDmcFD, NiconicoLiveFD, NiconicoLiveTimeshiftFD
|
||||
from .niconico import NiconicoDmcFD, NiconicoLiveFD
|
||||
from .rtmp import RtmpFD
|
||||
from .rtsp import RtspFD
|
||||
from .websocket import WebSocketFragmentFD
|
||||
|
@ -51,7 +51,6 @@ PROTOCOL_MAP = {
|
|||
'mhtml': MhtmlFD,
|
||||
'niconico_dmc': NiconicoDmcFD,
|
||||
'm3u8_niconico_live': NiconicoLiveFD,
|
||||
'm3u8_niconico_live_timeshift': NiconicoLiveTimeshiftFD,
|
||||
'fc2_live': FC2LiveFD,
|
||||
'websocket_frag': WebSocketFragmentFD,
|
||||
'youtube_live_chat': YoutubeLiveChatFD,
|
||||
|
|
|
@ -7,7 +7,7 @@ import time
|
|||
from . import get_suitable_downloader
|
||||
from .common import FileDownloader
|
||||
from .external import FFmpegFD
|
||||
from ..downloader.hls import HlsFD
|
||||
from ..downloader.fragment import FragmentFD
|
||||
from ..networking import Request
|
||||
from ..networking.exceptions import network_exceptions
|
||||
from ..utils import (
|
||||
|
@ -67,7 +67,10 @@ class NiconicoDmcFD(FileDownloader):
|
|||
return success
|
||||
|
||||
|
||||
class NiconicoLiveBaseFD(FileDownloader):
|
||||
class NiconicoLiveFD(FragmentFD):
|
||||
""" Downloads niconico live/timeshift VOD """
|
||||
|
||||
_PER_FRAGMENT_DOWNLOAD_RATIO = 0.1
|
||||
_WEBSOCKET_RECONNECT_DELAY = 10
|
||||
|
||||
@contextlib.contextmanager
|
||||
|
@ -75,8 +78,8 @@ class NiconicoLiveBaseFD(FileDownloader):
|
|||
""" Hold a WebSocket object and release it when leaving """
|
||||
|
||||
video_id = info_dict['id']
|
||||
live_latency = info_dict['live_latency']
|
||||
self.ws = info_dict['__ws']
|
||||
live_latency = info_dict['downloader_options']['live_latency']
|
||||
self.ws = info_dict['downloader_options']['ws']
|
||||
|
||||
self.m3u8_lock = threading.Event()
|
||||
self.m3u8_url = info_dict['manifest_url']
|
||||
|
@ -167,27 +170,15 @@ class NiconicoLiveBaseFD(FileDownloader):
|
|||
self.m3u8_lock.wait()
|
||||
return self.m3u8_url
|
||||
|
||||
|
||||
class NiconicoLiveFD(NiconicoLiveBaseFD):
|
||||
""" Downloads niconico live without being stopped """
|
||||
|
||||
def real_download(self, filename, info_dict):
|
||||
with self._ws_context(info_dict):
|
||||
new_info_dict = info_dict.copy()
|
||||
new_info_dict.update({
|
||||
'protocol': 'm3u8',
|
||||
})
|
||||
|
||||
return FFmpegFD(self.ydl, self.params or {}).download(filename, new_info_dict)
|
||||
|
||||
|
||||
class NiconicoLiveTimeshiftFD(NiconicoLiveBaseFD, HlsFD):
|
||||
""" Downloads niconico live timeshift VOD """
|
||||
|
||||
_PER_FRAGMENT_DOWNLOAD_RATIO = 0.1
|
||||
|
||||
def real_download(self, filename, info_dict):
|
||||
with self._ws_context(info_dict) as ws_context:
|
||||
# live
|
||||
if info_dict.get('is_live'):
|
||||
info_dict = info_dict.copy()
|
||||
info_dict['protocol'] = 'm3u8'
|
||||
return FFmpegFD(self.ydl, self.params or {}).download(filename, info_dict)
|
||||
|
||||
# timeshift VOD
|
||||
from ..extractor.niconico import NiconicoIE
|
||||
ie = NiconicoIE(self.ydl)
|
||||
|
||||
|
|
|
@ -1002,7 +1002,7 @@ class NiconicoLiveIE(InfoExtractor):
|
|||
for fmt, q in zip(formats, reversed(qualities[1:])):
|
||||
fmt.update({
|
||||
'format_id': q,
|
||||
'protocol': 'm3u8_niconico_live' if is_live else 'm3u8_niconico_live_timeshift',
|
||||
'protocol': 'm3u8_niconico_live',
|
||||
})
|
||||
yield fmt
|
||||
|
||||
|
@ -1075,7 +1075,9 @@ class NiconicoLiveIE(InfoExtractor):
|
|||
'live_status': live_status,
|
||||
'thumbnails': thumbnails,
|
||||
'formats': [*self._yield_formats(ws, video_id, latency, live_status == 'is_live')] if ws else None,
|
||||
'live_latency': latency,
|
||||
'http_headers': headers,
|
||||
'__ws': ws,
|
||||
'downloader_options': {
|
||||
'live_latency': latency,
|
||||
'ws': ws,
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue