# youtube 批次下載一個清單 {%hackmd /@HIPP0/Hippotumuxthem %} ## pip 安裝 pytube > pip install pytube ## 然後把下面的程式碼打一打 ```python= 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.") ``` ## 清單 - 先找到一個清單 - 加入自己的清單 - 去個人那邊找一下你的歌單  此時進去的連結就是你要下載的清單  ## 可能會遇到的問題 > pytube.exceptions.RegexMatchError: \_\_init\_\_: could not find match for ^\w+\W 請到你的錯誤訊息裡面,按一下有寫 cipher.py 的連結 (ctrl + 左鍵 還是 右鍵) 到大約第30行,把 var_regex 從 ```python= var_regex = re.compile(r"^\w+\W") ``` 改成下面這一行 ```python= var_regex = re.compile(r"^\$*\w+\W") ``` ## 結果   祝你有個美好的一天
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up