Try   HackMD

youtube 批次下載一個清單

pip 安裝 pytube

pip install pytube

然後把下面的程式碼打一打

from pytube import YouTube from pytube import Playlist import os # youtube清單 playlist = Playlist('https://www.youtube.com/playlist?list=PLL7LXvkhjsoKqhM5eLDub6D8BdJUEKGF0') # 你要放的位置 target_path = "e:" totol = len(playlist) t = 0 for url in playlist.video_urls: t = t + 1 print("==============") print("總共%d首歌" % totol) print(">>>>目前第%d首歌" % (t)) yt = YouTube(url) video = yt.streams.filter(only_audio=True).first() out_file = video.download(output_path=target_path) base, ext = os.path.splitext(out_file) new_file = base +'z'+ '.mp3' os.rename(out_file, new_file) print("target path = " + (new_file)) print("mp3 has been successfully downloaded.")

清單

  • 先找到一個清單
  • 加入自己的清單
  • 去個人那邊找一下你的歌單

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

此時進去的連結就是你要下載的清單

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

可能會遇到的問題

pytube.exceptions.RegexMatchError: __init__: could not find match for ^\w+\W

請到你的錯誤訊息裡面,按一下有寫 cipher.py 的連結 (ctrl + 左鍵 還是 右鍵)

到大約第30行,把 var_regex 從

var_regex = re.compile(r"^\w+\W")

改成下面這一行

var_regex = re.compile(r"^\$*\w+\W")

結果

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

祝你有個美好的一天