]>
jfr.im git - yt-dlp.git/blob - yt_dlp/downloader/niconico.py
3 from . import get_suitable_downloader
4 from .common
import FileDownloader
5 from ..utils
import sanitized_Request
8 class NiconicoDmcFD(FileDownloader
):
9 """ Downloading niconico douga from DMC with heartbeat """
11 def real_download(self
, filename
, info_dict
):
12 from ..extractor
.niconico
import NiconicoIE
14 self
.to_screen('[%s] Downloading from DMC' % self
.FD_NAME
)
15 ie
= NiconicoIE(self
.ydl
)
16 info_dict
, heartbeat_info_dict
= ie
._get
_heartbeat
_info
(info_dict
)
18 fd
= get_suitable_downloader(info_dict
, params
=self
.params
)(self
.ydl
, self
.params
)
20 success
= download_complete
= False
22 heartbeat_lock
= threading
.Lock()
23 heartbeat_url
= heartbeat_info_dict
['url']
24 heartbeat_data
= heartbeat_info_dict
['data'].encode()
25 heartbeat_interval
= heartbeat_info_dict
.get('interval', 30)
27 request
= sanitized_Request(heartbeat_url
, heartbeat_data
)
31 self
.ydl
.urlopen(request
).read()
33 self
.to_screen('[%s] Heartbeat failed' % self
.FD_NAME
)
36 if not download_complete
:
37 timer
[0] = threading
.Timer(heartbeat_interval
, heartbeat
)
40 heartbeat_info_dict
['ping']()
41 self
.to_screen('[%s] Heartbeat with %d second interval ...' % (self
.FD_NAME
, heartbeat_interval
))
44 if type(fd
).__name
__ == 'HlsFD':
45 info_dict
.update(ie
._extract
_m
3u8_formats
(info_dict
['url'], info_dict
['id'])[0])
46 success
= fd
.real_download(filename
, info_dict
)
51 download_complete
= True