fix ytdlp naming

This commit is contained in:
msramalho
2022-06-21 01:17:26 +02:00
parent ab15b35008
commit c74dc280d8
2 changed files with 9 additions and 2 deletions

View File

@@ -135,4 +135,4 @@ def test_scrape_video_only2():
with tempfile.TemporaryDirectory(dir="./") as tempdir:
vks.download_media(res, tempdir)
found_files = set(os.listdir(tempdir))
assert "video-17546758_456239898_0.mkv.webm" in found_files
assert "video-17546758_456239898_0.webm" in found_files

View File

@@ -312,7 +312,7 @@ class VkScraper:
downloaded.append(filename)
elif k == "video":
for i, url in enumerate(attachments):
filename = os.path.join(destination, f"{r['id']}_{i}.mkv")
filename = os.path.join(destination, f"{r['id']}_{i}.%(ext)s")
ydl = yt_dlp.YoutubeDL(
{
"outtmpl": filename,
@@ -323,5 +323,12 @@ class VkScraper:
)
info = ydl.extract_info(url, download=True)
filename = ydl.prepare_filename(info)
if "unknown_video" in filename:
new_filename = filename.replace("unknown_video", "mkv")
with open(filename, "rb") as vin, open(new_filename, "wb") as vout:
vout.write(vin.read())
os.remove(filename)
filename = new_filename
print(filename)
downloaded.append(filename)
return downloaded