mirror of
https://github.com/JefferyHcool/BiliNote.git
synced 2026-06-09 09:39:43 +08:00
fix(downloaders): 修复 Youtube 下载报错问题理
- 优化了临时文件清理逻辑,删除以指定文件名开头的所有相关文件
This commit is contained in:
@@ -27,13 +27,6 @@ class DouyinDownloader(Downloader, ABC):
|
|||||||
ydl_opts = {
|
ydl_opts = {
|
||||||
'format': 'bestaudio[ext=m4a]/bestaudio/best',
|
'format': 'bestaudio[ext=m4a]/bestaudio/best',
|
||||||
'outtmpl': output_path,
|
'outtmpl': output_path,
|
||||||
'postprocessors': [
|
|
||||||
{
|
|
||||||
'key': 'FFmpegExtractAudio',
|
|
||||||
'preferredcodec': 'mp3',
|
|
||||||
'preferredquality': '64',
|
|
||||||
}
|
|
||||||
],
|
|
||||||
'noplaylist': True,
|
'noplaylist': True,
|
||||||
'quiet': False,
|
'quiet': False,
|
||||||
}
|
}
|
||||||
@@ -44,7 +37,7 @@ class DouyinDownloader(Downloader, ABC):
|
|||||||
title = info.get("title")
|
title = info.get("title")
|
||||||
duration = info.get("duration", 0)
|
duration = info.get("duration", 0)
|
||||||
cover_url = info.get("thumbnail")
|
cover_url = info.get("thumbnail")
|
||||||
audio_path = os.path.join(output_dir, f"{video_id}.mp3")
|
audio_path = os.path.join(output_dir, f"{video_id}.m4a")
|
||||||
|
|
||||||
return AudioDownloadResult(
|
return AudioDownloadResult(
|
||||||
file_path=audio_path,
|
file_path=audio_path,
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class YoutubeDownloader(Downloader, ABC):
|
|||||||
title = info.get("title")
|
title = info.get("title")
|
||||||
duration = info.get("duration", 0)
|
duration = info.get("duration", 0)
|
||||||
cover_url = info.get("thumbnail")
|
cover_url = info.get("thumbnail")
|
||||||
audio_path = os.path.join(output_dir, f"{video_id}.mp3")
|
audio_path = os.path.join(output_dir, f"{video_id}.m4a")
|
||||||
|
|
||||||
return AudioDownloadResult(
|
return AudioDownloadResult(
|
||||||
file_path=audio_path,
|
file_path=audio_path,
|
||||||
|
|||||||
@@ -4,6 +4,13 @@ logger = get_logger(__name__)
|
|||||||
|
|
||||||
def cleanup_temp_files(data):
|
def cleanup_temp_files(data):
|
||||||
logger.info(f"starting cleanup temp files :{data['file_path']}")
|
logger.info(f"starting cleanup temp files :{data['file_path']}")
|
||||||
|
# 获取名称
|
||||||
|
path=data['file_path']
|
||||||
|
name=path[:-4]
|
||||||
|
# 删除以这个文件开头的
|
||||||
|
for file in os.listdir(os.path.dirname(path)):
|
||||||
|
if file.startswith(name):
|
||||||
|
os.remove(os.path.join(os.path.dirname(path), file))
|
||||||
os.remove(data['file_path'])
|
os.remove(data['file_path'])
|
||||||
# 检查是否删除文件
|
# 检查是否删除文件
|
||||||
if os.path.exists(data['file_path']):
|
if os.path.exists(data['file_path']):
|
||||||
|
|||||||
Reference in New Issue
Block a user