Input Error - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Input Error (/thread-28269.html) |
Input Error - Dream - Jul-12-2020 Hello,im trying to do a youtube video downloader script,so i did this: import pytube video_url = 'https://www.youtube.com/watch?v=4KcMdH8qiuk' youtube = pytube.YouTube(video_url) video = youtube.streams.first() video.download('/home/dream/Downloads') but i dont want to put the url in the code,I want the user to insert it when the program is started,so i did import pytube video_url = input() youtube = pytube.YouTube(video_url) video = youtube.streams.first() video.download('/home/dream/Downloads')but this return me error:
RE: Input Error - DreamingInsanity - Jul-12-2020 It maybe be a bug with the library but I've never used it so I can't say for certain. Have you thought about using other libraries? There's a very popular one called youtube-dl. It supports hundreds of sites including youtube. It has command line support as well. There is very many good python tutorials on it. https://www.bogotobogo.com/VideoStreaming/YouTube/youtube-dl-embedding.php The site provides this code: # ydl1.py from __future__ import unicode_literals import youtube_dl ydl_opts = {} with youtube_dl.YoutubeDL(ydl_opts) as ydl: ydl.download(['https://www.youtube.com/watch?v=dP15zlyra3c'])You would need to modify it to have user input but that should't be too hard. If you read up on it, there are also many options you can provide like whether you want audio, the output file type and so on. RE: Input Error - bowlofred - Jul-12-2020 Worked fine for me. I added a line to show what URL was read. import pytube video_url = input("Enter url: ") print(f"Downloading {video_url}") youtube = pytube.YouTube(video_url) video = youtube.streams.first() video.download('tube.out') And it downloads...
|