]>
jfr.im git - yt-dlp.git/blob - yt_dlp/downloader/niconico.py
2 from __future__
import unicode_literals
6 from .common
import FileDownloader
7 from ..downloader
import get_suitable_downloader
8 from ..extractor
.niconico
import NiconicoIE
9 from ..utils
import sanitized_Request
12 class NiconicoDmcFD(FileDownloader
):
13 """ Downloading niconico douga from DMC with heartbeat """
15 FD_NAME
= 'niconico_dmc'
17 def real_download(self
, filename
, info_dict
):
18 self
.to_screen('[%s] Downloading from DMC' % self
.FD_NAME
)
20 ie
= NiconicoIE(self
.ydl
)
21 info_dict
, heartbeat_info_dict
= ie
._get
_heartbeat
_info
(info_dict
)
23 fd
= get_suitable_downloader(info_dict
, params
=self
.params
)(self
.ydl
, self
.params
)
25 success
= download_complete
= False
27 heartbeat_lock
= threading
.Lock()
28 heartbeat_url
= heartbeat_info_dict
['url']
29 heartbeat_data
= heartbeat_info_dict
['data'].encode()
30 heartbeat_interval
= heartbeat_info_dict
.get('interval', 30)
32 request
= sanitized_Request(heartbeat_url
, heartbeat_data
)
36 self
.ydl
.urlopen(request
).read()
38 self
.to_screen('[%s] Heartbeat failed' % self
.FD_NAME
)
41 if not download_complete
:
42 timer
[0] = threading
.Timer(heartbeat_interval
, heartbeat
)
45 heartbeat_info_dict
['ping']()
46 self
.to_screen('[%s] Heartbeat with %d second interval ...' % (self
.FD_NAME
, heartbeat_interval
))
49 if type(fd
).__name
__ == 'HlsFD':
50 info_dict
.update(ie
._extract
_m
3u8_formats
(info_dict
['url'], info_dict
['id'])[0])
51 success
= fd
.real_download(filename
, info_dict
)
56 download_complete
= True