I'm trying to download the whole Youtube playlist as MP3, this code below is giving me a TypeError: 'DeferredGeneratorList' object is not callable
, I tried googling it, I found no similar errors at all, is there something I'm doing wrong? and / or, is there any other way I can use to achieve that?
Code:
import os
import subprocess
from pytube import Playlist, YouTube
def run(pl):
# get parent directory; VERY IMPORTANT!!
# INCLUDE LAST SLASH AFTER FOLDER NAME
# e.g. /home/username/Folder/ or C:\Users\Username\Folder\
filepath = input("Please enter the filepath of the directory where this script is located:\n")
# get linked list of links in the playlist
links = pl.video_urls()
# download each item in the list
for l in links:
# converts the link to a YouTube object
yt = YouTube(l)
# takes first stream; since ffmpeg will convert to mp3 anyway
music = yt.streams.first()
# gets the filename of the first audio stream
default_filename = music.default_filename
print("Downloading " default_filename "...")
# downloads first audio stream
music.download()
# creates mp3 filename for downloaded file
new_filename = default_filename[0:-3] "mp3"
print("Converting to mp3....")
# converts mp4 audio to mp3 audio
subprocess.run(['ffmpeg', '-i',
os.path.join(filepath, default_filename),
os.path.join(filepath, new_filename)
])
print("Download finished.")
if __name__ == "__main__":
url = input("Please enter the url of the playlist you wish to download: ")
pl = Playlist(url)
run(pl)
The error:
Traceback (most recent call last):
File "C:/Users/Totenkopf/Downloads/test/main.py", line 40, in <module>
run(pl)
File "C:/Users/Totenkopf/Downloads/test/main.py", line 13, in run
links = pl.video_urls()
TypeError: 'DeferredGeneratorList' object is not callable
CodePudding user response:
video_urls is a list not a method. Call video_urls without ().