xhlove / XstreamDL-CLI

命令行版本的HLS/DASH流下载器,支持标准AES-128-CBC解密
GNU Lesser General Public License v2.1
281 stars 68 forks source link

下载长视频容易中断 #38

Closed hecoter closed 2 years ago

hecoter commented 2 years ago

m3u8url = 'http://58.222.51.151/vipts.tc.qq.com/A53DH4JO0WA6HF-yGkWDAlJ3MZJQcasVauzM1iEIupBk/uwMROfz2r55goaQXGdGnC2de64gtX89GT746tcTJVnDpJgsD/svp_50112/GquHDAOkA7rx4Twr13V0_6Gm0UOcM1Y7NuPcpo6keTiLDvhC_0t-XR3YqFPdMQtE39dVgo3S0Ks2cuzatMW9RSA6G5md6O3_vRa-mi_xcJ-hxo0fByBUGEkrwUA8pkmeU7Aso-kDV4Dp8tXnOZI-78bm-Kktoo7qstxWToYb1ssRA6RthPusdw/gzc_1000102_0b53taaawaaaymaiekw2tbq4bggdbokaad2a.f321004.ts.m3u8?ver=4'

例如这个链接,总是下载到62%就会断,但是接着下载又能完全下载完

37_1 ██████████████████ 921.03/1007.86MB • 0.33MB/s • 153/244 • 62.70% 2022-01-10 21:22:30,044 XstreamDL stream.py 212 : ERROR 尝试合并 37_1 但是未下载完成

xhlove commented 2 years ago

未能复现你所说的情况,下载顺利正常。

建议尝试一下N_m3u8DL-CLI,如果也是有这样的问题,有可能是你那儿cdn问题。

如果需要更准确一点确定,请发送你的日志文件,在logs下

image

hecoter commented 2 years ago

日志 : https://aohua.lanzout.com/iSmwyymcang 里面有两份日志,一个是下载到60%左右突然中断的日志,另一份是继续下载 并且下载成功的日志

用nilaoda 的下载器没问题

猜测可能是因为多并发导致单个文件下载时间太长造成中断

xhlove commented 2 years ago

看日志好像就是当时连接超时了,很多视频都有这个情况吗?

实际上没有多少并发,有一个可能是你使用了--disable-force-close选项。

如果用了那么改成不使用这个选项。

hecoter commented 2 years ago

好吧,昨天那个链接已经失效了,不管他了,然后又发现了一个问题

https://1252524126.vod2.myqcloud.com/9764a7a5vodtransgzp1252524126/215eee7e5285890804441012426/drm/v.f230.m3u8

这个链接也下载不下来了,标准的AES-128-CBC加密的m3u8链接,不管是调用cli还是直接用界面都不行

日志: 2022-01-11 16:26:00,336 XstreamDL log.py 41 : INFO log file -> C:/Users/happy/Desktop/m3u8down/logs/XstreamDL-2022-01-11_162600.log 2022-01-11 16:26:00,336 XstreamDL cli.py 35 : DEBUG set --live-duration to 0.0 2022-01-11 16:26:00,346 XstreamDL cli.py 41 : DEBUG set --save-dir to C:/Users/happy/Desktop/m3u8down/Downloads 2022-01-11 16:26:00,346 XstreamDL default.py 19 : WARNING headers is not exists, put your config file to C:/Users/happy/Desktop 2022-01-11 16:26:00,346 XstreamDL cli.py 44 : DEBUG set --limit-per-host to 4 2022-01-11 16:26:00,346 XstreamDL cli.py 50 : DEBUG set --key to None 2022-01-11 16:26:00,346 XstreamDL cli.py 59 : DEBUG set --b64key to None 2022-01-11 16:26:00,346 XstreamDL cli.py 60 : DEBUG set --hexiv to None 2022-01-11 16:26:00,346 XstreamDL cli.py 70 : WARNING binaries folder is not exist > C:\Users\happy\Desktop\m3u8down\binaries 2022-01-11 16:26:00,346 XstreamDL cli.py 80 : DEBUG ffmpeg ffmpeg 2022-01-11 16:26:00,346 XstreamDL cli.py 81 : DEBUG mp4decrypt mp4decrypt 2022-01-11 16:26:00,346 XstreamDL cli.py 82 : DEBUG mp4box mp4box 2022-01-11 16:26:00,346 XstreamDL cli.py 152 : INFO set URI to ['https://1252524126.vod2.myqcloud.com/9764a7a5vodtransgzp1252524126/215eee7e5285890804441012426/drm/v.f230.m3u8'] 2022-01-11 16:26:00,475 XstreamDL base.py 35 : DEBUG start parse uri for: https://1252524126.vod2.myqcloud.com/9764a7a5vodtransgzp1252524126/215eee7e5285890804441012426/drm/v.f230.m3u8 2022-01-11 16:26:00,475 XstreamDL base.py 18 : DEBUG fix name before: v.f230 2022-01-11 16:26:00,475 XstreamDL base.py 23 : DEBUG fix name after: v.f230 2022-01-11 16:26:00,475 XstreamDL base.py 64 : DEBUG parse uri result: name v.f230 home_url https://1252524126.vod2.myqcloud.com base_url https://1252524126.vod2.myqcloud.com/9764a7a5vodtransgzp1252524126/215eee7e5285890804441012426/drm 2022-01-11 16:26:00,475 XstreamDL base.py 28 : DEBUG save content to C:/Users/happy/Desktop/m3u8down/Downloads/v.f230.m3u8, size 68266 2022-01-11 16:26:00,475 XstreamDL xkey.py 105 : INFO key uri => https://app.xiaoe-tech.com/get_video_key.php?edk=CiCgFldENmveJ%2ByzND5oLL50nTuZYMxIYCW3y2M2iSlPaxCO08TAChiaoOvUBCokYjRhNjFiNTgtMmVhNy00OWYxLTgwZGMtZTE0NTIyODc5YWIy&fileId=5285890804441012426&keySource=VodBuildInKMS

xhlove commented 2 years ago

感谢反馈,这是一个bug,最新commit修复了,请使用新版代码测试

hecoter commented 2 years ago

感谢感谢,问题已解决

hecoter commented 2 years ago

` for i in range(retries): try: response = requests.get(url=segment['uri'], headers=headers, timeout=5, stream=True, verify=False, proxies={'http': proxy}) ts = response.content downsize += ts.sizeof()

伪装成图片的视频,自动去除文件头

                if ts[:4] == b'\x89PNG' or ts[:4] == b'BM\xee\x0c':
                    ts = ts[4:]
                if response.status_code == 200:
                    break
            except:
                if showLogs:
                    print(f'\r\t{segment["title"]}.ts requests failed {i + 1} times.')
                time.sleep(1)
                if i == retries - 1:
                    ts = b''`

关于下载中断的问题我觉得可以添加下载重试机制,类似于上面这个我之前写过的代码,不过是用多线程写的,希望有帮助

hecoter commented 2 years ago

``

for i in range(retries):
    try:
        response = requests.get(url=segment['uri'], headers=headers, timeout=5, stream=True, verify=False,
                                proxies={'http': proxy})
        ts = response.content
        downsize += ts.__sizeof__()
        # 伪装成图片的视频,自动去除文件头
        if ts[:4] == b'\x89PNG' or ts[:4] == b'BM\xee\x0c':
            ts = ts[4:]
        if response.status_code == 200:
            break
    except:
        if showLogs == 'True':
            print(f'\r\t{segment["title"]}.ts requests failed {i + 1} times.')
        time.sleep(1)
        if i == retries - 1:
            ts = b''
xhlove commented 2 years ago

重试机制是有的,效果可能不好 https://github.com/xhlove/XstreamDL-CLI/blob/d6d193a519e7a3cb4638154d711199eab0c4fdc2/XstreamDL_CLI/downloader.py#L298

并发最多4个,不放心可以把--limit-per-host设置为1,超时也可能和底层库有关,以及DNS

https://github.com/xhlove/XstreamDL-CLI/blob/d6d193a519e7a3cb4638154d711199eab0c4fdc2/XstreamDL_CLI/cli.py#L116

如果还有其他疑问,可以重新打开issue