jingfelix/BiliFM

下载出错就停止了,然后也无法重新下载,除非删掉所有,但是还是会在不同位置出错

liuchuancong opened this issue · 11 comments

下载出错就停止了,然后也无法重新下载,除非删掉所有,但是还是会在不同位置出错

Hi,

可以提供一下使用的下载命令,视频链接或报错截图吗?这样能帮助我更快地定位问题!

typer.echo("Download failed")
typer.echo("Error: " + str(e)) 这块,这个exception也没有打印任何东西 在下载就是已存在,应该是对比文件夹名称有问题,我试下代码能不能修复

请输入bvBV1iC4y1m75S
[##################################################] 2788314/2788314 精选抖音热歌飙升榜Top100首,前三首肯定都是你最喜欢的!Download failed
Error: 'data'
4.5 seconds download finish

Error: 'data'
Traceback (most recent call last):
  File "e:\project\BiliFM-main\src\bilifm\audio.py", line 46, in download
    baseUrl = requests.get(
              ^^^^^^^^^^^^^
KeyError: 'data'
 2.81 seconds download finish

好,我来看一下

for cid, part in zip(self.cid_list, self.part_list):
                check_response = requests.get(
                        self.playUrl,
                        params={
                            "fnval": 16,
                            "bvid": self.bvid,
                            "cid": cid,
                        },
                    )
                if check_response.status_code == 200 and check_response.text != 'jsonpgz()':
                    baseUrl = check_response.json()["data"]["dash"]["audio"][0]["baseUrl"]

添加检查就可以了,但是还是存在部分歌曲无法下载的情况,但不会直接退出

file_path = f"{self.title}-{part}.mp3" 建议把self.title删掉,歌曲太长了,下载下来看不到名字

https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/misc/sign/wbi.md

查了一下文档,部分歌曲依然无法下载可能是受到这个影响。测试后发现请求几次就会报 412,我想想怎么修。

from src.bilifm.audio import Audio
file_path = "bv.txt"
import fileinput
import asyncio
import time
tasks = []
def createTasks():
    with open(file_path, 'r') as f:
      lines = f.readlines()
      for line in lines:
        if not len(line.strip()) == 0:
          tasks.append(line.strip())
        


async def main():
    # loop over async iterator with async for loop
    async for item in AsyncIterator():
        print(item)
        
        
        
class AsyncIterator():
    # constructor, define some state
    def __init__(self):
        createTasks()
        self.counter = 0
 
    # create an instance of the iterator
    def __aiter__(self):
        return self
 
    # return the next awaitable
    async def __anext__(self):
        # check for no further items
        if self.counter >= len(tasks):
            raise StopAsyncIteration
        # increment the counter
        # simulate work
        print(self.counter)
        audio = Audio(tasks[self.counter])
        await audio.download()
        self.counter += 1
        # return the counter value
        return self.counter
      
      
asyncio.run(main())

可以加个txt 以及指定下载目录,类似的方法,这样下载不会很累

以及文件判断是否存在可以提前到请求之前,这样节约时间以及流量

412 报错和检查文件位置都在 v0.2.0 里修好了

pip install bilifm==0.2.0