【发布时间】:2023-02-22 13:29:40
【问题描述】:
我正在尝试下载我的视频播放列表并使用 pytube、moviepy、re 将其转换为 mp3 扩展名。一切正常,但当它达到一个数字时,它就会停止工作。
我怎样才能解决这个问题?
from pytube import YouTube
from pytube import Playlist
import os
import moviepy.editor as mp #to convert the mp4 to wav then mp3
import re
playlist = Playlist("https://www.youtube.com/playlist?list=PLb2p41g_hNVOeBy3OjGTdXKgscedya9f_")
for url in playlist:
print(url)
for vid in playlist.videos:
print(vid)
for url in playlist:
YouTube(url).streams.filter(only_audio=True).first().download("./Downloads/Music_2")
folder = "./Downloads/Music_2"
for file in os.listdir(folder):
if re.search('mp4', file):
print("Converting: " + file)
mp4_path = os.path.join(folder,file)
mp3_path = os.path.join(folder,os.path.splitext(file)[0]+'.mp3')
new_file = mp.AudioFileClip(mp4_path)
new_file.write_audiofile(mp3_path)
os.removed(mp4_path)
错误代码;
Traceback (most recent call last):
File "C:\Users\user\Downloads\Projects\Python\main.py", line 14, in <module>
YouTube(url).streams.filter(only_audio=True).first().download("./Downloads/Music_3")
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\Downloads\Projects\Python\venv\Lib\site-packages\pytube\__main__.py", line 296, in streams
return StreamQuery(self.fmt_streams)
^^^^^^^^^^^^^^^^
File "C:\Users\user\Downloads\Projects\Python\venv\Lib\site-packages\pytube\__main__.py", line 176, in fmt_streams
stream_manifest = extract.apply_descrambler(self.streaming_data)
^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\Downloads\Projects\Python\venv\Lib\site-packages\pytube\__main__.py", line 161, in streaming_data
return self.vid_info['streamingData']
~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
KeyError: 'streamingData'
Process finished with exit code 1
【问题讨论】:
-
来自your original code image的I wasn't able to copy correctly the playlist id
PL...,你能用正确的问题编辑你的问题吗? -
你能提供输出日志吗?或者只是错误。
-
我还建议查看 yt-dlp 而不是 Pytube,因为它具有更多功能,例如下载 mp,这样您就不必转换任何东西。
-
@Cheesebellies 我分享了错误信息
-
也许尝试检查 Pytube 是否更新?
标签: python youtube python-re moviepy pytube