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