Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3831

How do I get the download button to register the link provided as a url?

$
0
0

Beginner coder, first time using TKinter.when I click the Download button, the code doesn't execute as I'd expect (I expect it to download the video). Of the errors that are raised, one is a RegexMatchError and I think the problem is in this line "yt = YouTube(f"{url}")">any assistance will be appreciated.

import tkinter as tkfrom tkinter import ttkfrom tkinter.messagebox import showinfofrom pytube import YouTuberoot = tk.Tk()root.geometry("400x200")root.resizable(False, False)root.title("Youtube Downloader")tk.Label(root, text="Hello :)\nWelcome to Youtube Downloader.\n").pack()url = tk.StringVar()# Link framelink = ttk.Frame(root)link.pack(padx=10, pady=10, fill='x', expand=True)# Linklink_label = ttk.Label(link, text="Enter the Youtube link:\n")link_label.pack(fill='x', expand=True)link_entry = ttk.Entry(link, textvariable=url)link_entry.pack(fill='x', expand=True)link_entry.focus()# download buttondef download_clicked():    print("Welcome to Youtube Downloader.")    showinfo(        title='Information',        message='Download has began!'    )    yt = YouTube(f"{url}")    stream = yt.streams.get_by_itag(22)    size = round(stream.filesize / 10 ** 6, 2)    print(f"Downloading {yt.title}, \n Length: {yt.length} seconds, \n Size: {size} MBs")download_button = ttk.Button(    root,    text='Download',    compound=tk.LEFT,    command=download_clicked)download_button.pack(ipadx=5, ipady=5, expand=True)# Exit buttonexit_button = ttk.Button(    root,    text='Exit',    command=lambda: root.quit())exit_button.pack(    ipadx=5,    ipady=5,    expand=True,    side="left")try:    from ctypes import windll    windll.shcore.SetProcessDpiAwareness(1)finally:    root.mainloop()

the error

Exception in Tkinter callbackTraceback (most recent call last):  File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1921, in __call__    return self.func(*args)  File "c:\Users\hp\Desktop\git\YoutubeDownloader\tkinter yt dowloader.py", line 36, in download_clicked    yt = YouTube(f"{url}")  File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube\__main__.py", line 71, in __init__    self.video_id = extract.video_id(url)  File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube\extract.py", line 133, in video_id    return regex_search(r"(?:v=|\/)([0-9A-Za-z_-]{11}).*", url, group=1)  File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube\helpers.py", line 129, in regex_search    raise RegexMatchError(caller="regex_search", pattern=pattern)        pytube.exceptions.RegexMatchError: regex_search: could not find match for (?:v=|\/)([0-9A-Za-z_-]{11}).*

Viewing all articles
Browse latest Browse all 3831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>