系列文章:
1.只要點兩下,就能離開位子。讓電腦依照規劃自動下載YT影片https://skjhcreator.blogspot.com/2022/11/youtube.html
2.只要點兩下,就能離開位子。讓電腦依照公開的PlayList自動下載YT多媒體https://skjhcreator.blogspot.com/2022/11/playlistyoutube.html
3.只要點兩下,就能離開位子。讓電腦依照規劃自動下載臉書的影片https://skjhcreator.blogspot.com/2022/11/facebook.html
4.只要點兩下,就能離開位子。讓電腦依照規劃自動下載YT多媒體https://skjhcreator.blogspot.com/2023/02/yt.html
5.變更套件,重寫程式。只要點兩下,就能離開位子。讓電腦依照規劃自動下載YT影片https://skjhcreator.blogspot.com/2025/10/yt.html
沒想到再次寫程式來下載YT影片,理由是先前的程式在2023年後已無法正常下載YT影片。所以重新再寫程式。但關鍵是原先套件pytube無法正常執行,一直發生錯誤。更改套件便是目前解決問題的關鍵。
下載檔案。解壓密碼:demo1234
使用步驟:
安裝套件yt-dlp:
pip install yt-dlp
檔案名稱:pyyt_dlp.py
檔案內容:
import yt_dlp
import os
# 取得目前的工作目錄
current_directory = os.getcwd()
# 檢查 YTDownloadList.txt 是否存在
if os.path.exists(current_directory + "\\YTDownloadList.txt"):
# 如果存在,則讀取檔案內容
with open("YTDownloadList.txt", "r", encoding="utf-8") as file:
content = file.readlines()
else:
# 如果不存在,則創建YTDownloadList.txt 並寫入內容
with open("YTDownloadList.txt", "w", encoding="utf-8") as file:
file.write('https://www.youtube.com/watch?v=uSqVw9rO7lg')
print("YTDownloadList.txt 內有預設音樂影片,請再按一次")
os.system("pause")
os.system("exit")
ydl_opts = {
'format': 'best',
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
for i in content:
ydl.download([i])
資料來源:
沒有留言:
張貼留言