1.0.1 • Published 1 year ago
@durka/down v1.0.1
@durka/download
文件下载,主要专注视频下载
参考 aria2 项目,以及在 aria2 基础上封装的一个 electron 项目 Motrix
aria2: https://github.com/aria2/aria2 Motrix: https://github.com/agalwood/Motrix youtube-dl: https://github.com/ytdl-org/youtube-dl/ curl: https://reqbin.com/req/c-egazzayq/curl-download-file curl --limit-rate 100k -O URL
protocol = info_dict['protocol']
if protocol.startswith('m3u8') and info_dict.get('is_live'):
return FFmpegFD
if protocol == 'm3u8' and params.get('hls_prefer_native') is True:
return HlsFD
if protocol == 'm3u8_native' and params.get('hls_prefer_native') is False:
return FFmpegFD
return PROTOCOL_MAP.get(protocol, HttpFD)
def slow_down(self, start_time, now, byte_counter):
"""Sleep if the download speed is over the rate limit."""
rate_limit = self.params.get('ratelimit')
if rate_limit is None or byte_counter == 0:
return
if now is None:
now = time.time()
elapsed = now - start_time
if elapsed <= 0.0:
return
speed = float(byte_counter) / elapsed
if speed > rate_limit:
sleep_time = float(byte_counter) / rate_limit - elapsed
if sleep_time > 0:
time.sleep(sleep_time)
- 指定 proxy 的 http header
- 断点续传进度显示不准确
- 断点续传应该检查下已经下载的文件和要下载的文件是不是同一个(尺寸大小,链接是否一致等等)
- 下载过程记录耗时
- 单任务失败后需要支持重试(分片下载时有可能出现错误“”导致整个任务结束)
- m3u8 中的 ts 文件如果加密了要支持解密 https://juejin.cn/post/6887575078293372942#heading-0 https://github.com/Momo707577045/m3u8-downloader
需要指定 referer 才能生效的 m3u8 文件(内部已经默认注入) https://v9.xszav.net/hls/xszavavs/media/videos/h264/118886_SD.mp4/index.m3u8
重定向且加密的 m3u8 文件 http://video.yjf138.com/20180812/6yl0Q2YZ/index.m3u8 http://video.yjf138.com/20180812/6yl0Q2YZ/1500kb/hls/index.m3u8
Installation
Usage
Changelog
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.