mirror of
https://github.com/l1ving/youtube-dl
synced 2025-02-09 07:37:50 +08:00
[niconico] use HeartBeat
This commit is contained in:
parent
7550ea501a
commit
5a6f5f98ad
@ -96,6 +96,7 @@ from .extractor import get_info_extractor, gen_extractor_classes, _LAZY_LOADER
|
||||
from .extractor.openload import PhantomJSwrapper
|
||||
from .downloader import get_suitable_downloader
|
||||
from .downloader.rtmp import rtmpdump_version
|
||||
from .downloader.httpfd import HttpHB
|
||||
from .postprocessor import (
|
||||
FFmpegFixupM3u8PP,
|
||||
FFmpegFixupM4aPP,
|
||||
@ -1839,7 +1840,12 @@ class YoutubeDL(object):
|
||||
if not self.params.get('skip_download', False):
|
||||
try:
|
||||
def dl(name, info):
|
||||
fd = get_suitable_downloader(info, self.params)(self, self.params)
|
||||
if 'heartbeat_url' in info:
|
||||
print("use HTTPHB")
|
||||
fd = HttpHB(self, self.params)
|
||||
else:
|
||||
fd = get_suitable_downloader(info, self.params)(self, self.params)
|
||||
|
||||
for ph in self._progress_hooks:
|
||||
fd.add_progress_hook(ph)
|
||||
if self.params.get('verbose'):
|
||||
|
27
youtube_dl/downloader/httpfd.py
Normal file
27
youtube_dl/downloader/httpfd.py
Normal file
@ -0,0 +1,27 @@
|
||||
from .http import HttpFD
|
||||
|
||||
import urllib.request as compat_urllib_request
|
||||
import threading
|
||||
|
||||
|
||||
class HttpHB(HttpFD):
|
||||
def real_download(self, filename, info_dict):
|
||||
result = False
|
||||
if 'heartbeat_url'in info_dict:
|
||||
def heart_beat():
|
||||
try:
|
||||
data = info_dict['heartbeat_data'].encode("utf-8")
|
||||
compat_urllib_request.urlopen(url=info_dict['heartbeat_url'], data=data)
|
||||
print('heart beat!')
|
||||
except Exception as ex:
|
||||
print('heart beat fail: ' + ex.message)
|
||||
pass
|
||||
|
||||
if not result:
|
||||
timer = threading.Timer(25, heart_beat)
|
||||
timer.start()
|
||||
|
||||
heart_beat()
|
||||
|
||||
result = super(HttpHB, self).real_download(filename, info_dict)
|
||||
return result
|
@ -254,6 +254,10 @@ class NiconicoIE(InfoExtractor):
|
||||
}
|
||||
}))
|
||||
|
||||
# get heart-beat data
|
||||
api_url = session_api_endpoint['url'] + '/' + session_response['data']['session']['id'] + '?_format=json&_method=PUT'
|
||||
data = json.dumps(session_response['data'])
|
||||
|
||||
resolution = video_quality.get('resolution', {})
|
||||
|
||||
return {
|
||||
@ -264,6 +268,8 @@ class NiconicoIE(InfoExtractor):
|
||||
'vbr': float_or_none(video_quality.get('bitrate'), 1000),
|
||||
'height': resolution.get('height'),
|
||||
'width': resolution.get('width'),
|
||||
'heartbeat_url': api_url, # pay attention here
|
||||
'heartbeat_data': data,
|
||||
}
|
||||
|
||||
def _real_extract(self, url):
|
||||
|
Loading…
Reference in New Issue
Block a user