Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Input Error
#1
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:
Error:
Traceback (most recent call last): File "/home/dream/.local/lib/python3.8/site-packages/pytube/extract.py", line 288, in apply_descrambler stream_data[key] = [ File "/home/dream/.local/lib/python3.8/site-packages/pytube/extract.py", line 290, in <listcomp> "url": format_item["url"], KeyError: 'url' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "youtube2.py", line 3, in <module> youtube = pytube.YouTube(video_url) File "/home/dream/.local/lib/python3.8/site-packages/pytube/__main__.py", line 92, in __init__ self.descramble() File "/home/dream/.local/lib/python3.8/site-packages/pytube/__main__.py", line 132, in descramble apply_descrambler(self.player_config_args, fmt) File "/home/dream/.local/lib/python3.8/site-packages/pytube/extract.py", line 300, in apply_descrambler cipher_url = [ File "/home/dream/.local/lib/python3.8/site-packages/pytube/extract.py", line 301, in <listcomp> parse_qs(formats[i]["cipher"]) for i, data in enumerate(formats) KeyError: 'cipher'
Reply
#2
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/VideoStreamin...edding.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.
Reply
#3
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')
Output:
Enter url: https://www.youtube.com/watch?v=4KcMdH8qiuk Downloading https://www.youtube.com/watch?v=4KcMdH8qiuk
And it downloads...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pyspark SQL Error - mismatched input 'FROM' expecting <EOF> Ariean 3 10,299 Nov-20-2020, 03:49 PM
Last Post: Ariean
  EOF error while taking input ShishirModi 1 701 Sep-27-2020, 11:28 AM
Last Post: jefsummers
  Getting an error while using input function dcsethia 5 988 May-11-2020, 04:59 PM
Last Post: buran
  catch input type error mcmxl22 5 1,320 Aug-11-2019, 07:33 AM
Last Post: wavic
  inserting input gives me error message RubberNuggets 3 1,185 Jan-15-2019, 06:17 PM
Last Post: buran
  an input error or elif error , how can i fix this the_fire_pharaoh 1 1,255 Dec-15-2018, 09:47 PM
Last Post: Gribouillis
  Getting Error : User Input aankrose 1 2,018 Sep-06-2018, 04:55 PM
Last Post: buran
  Input error vijays3 1 1,336 May-30-2018, 08:50 AM
Last Post: snippsat
  input error help Cremno 2 1,792 Oct-21-2017, 05:26 PM
Last Post: Cremno

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020