我曾经通过以下方式下载歌曲:
from pytube import YouTube
video = YouTube('https://www.youtube.com/watch?v=AWXvSBHB210')
video.streams.get_by_itag(251).download()
从今天开始出现此错误:
Traceback (most recent call last):
File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\__main__.py", line 170, in fmt_streams
extract.apply_signature(stream_manifest, self.vid_info, self.js)
File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\extract.py", line 409, in apply_signature
cipher = Cipher(js=js)
File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\cipher.py", line 43, in __init__
self.throttling_plan = get_throttling_plan(js)
File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\cipher.py", line 387, in get_throttling_plan
raw_code = get_throttling_function_code(js)
File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\cipher.py", line 293, in get_throttling_function_code
name = re.escape(get_throttling_function_name(js))
File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\cipher.py", line 278, in get_throttling_function_name
raise RegexMatchError(
pytube.exceptions.RegexMatchError: get_throttling_function_name: could not find match for multiple
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Me\Documents\YouTubeDownloader.py", line 3, in <module>
video.streams.get_by_itag(251).download()
File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\__main__.py", line 285, in streams
return StreamQuery(self.fmt_streams)
File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\__main__.py", line 177, in fmt_streams
extract.apply_signature(stream_manifest, self.vid_info, self.js)
File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\extract.py", line 409, in apply_signature
cipher = Cipher(js=js)
File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\cipher.py", line 43, in __init__
self.throttling_plan = get_throttling_plan(js)
File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\cipher.py", line 387, in get_throttling_plan
raw_code = get_throttling_function_code(js)
File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\cipher.py", line 293, in get_throttling_function_code
name = re.escape(get_throttling_function_name(js))
File "C:\Users\Me\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\cipher.py", line 278, in get_throttling_function_name
raise RegexMatchError(
pytube.exceptions.RegexMatchError: get_throttling_function_name: could not find match for multiple
此錯誤「pytube.exceptions.RegexMatchError: get_throttling_function_name: could not find match for multiple」表示 PyTube 無法解譯 YouTube 用來提供串流影片的程式碼。這通常發生在 YouTube 變更其程式碼,而 PyTube 還未更新以反映這些變更時。
可以嘗試以下步驟來解決此問題:
1. 更新 PyTube:
確保使用的是最新版本的 PyTube。可以使用 pip 來更新:
bash
pip install --upgrade pytube
2. 清除 PyTube 快取:
PyTube 有時會快取 YouTube 頁面的資訊。清除快取可能會解決問題:
python
from pytube import YouTube
YouTube.clear_cache()
3. 使用不同的 itag 或
streams.filter()
:
有時特定的 itag 可能會失效。請嘗試使用
streams.filter()
方法來尋找具有所需解析度和檔案類型的其他可用串流:
```python from pytube import YouTube
video = YouTube('https://www.youtube.com/watch?v=AWXvSBHB210') # 尋找音訊串流 stream = video.streams.filter(only_audio=True).first() # 或者尋找特定解析度的影片串流 # stream = video.streams.filter(progressive=True, res="720p").first()
stream.download() ```
4. 等待更新:
如果以上方法都不起作用,則 YouTube 可能進行了重大更改,而 PyTube 開發人員尚未發佈更新。可以在 PyTube GitHub 頁面 上查看是否有任何已知問題或更新。
其他建議:
- 檢查的網際網路連線。
- 嘗試重新啟動的 Python 直譯器或電腦。
如果問題仍然存在,可以提供更多上下文資訊,例如 PyTube 版本、作業系統和嘗試下載的影片,以便我可以進一步協助。
标签:python,python-3.x,pytube From: 68945080