I have been trying to put together a few lines of code that takes a youtube music video URL and converts it to mp3/mp4 + 720p, and then downloads it to my DropBox music folder.
When I'm trying to pass a URL through a TKinter widget (entry bar) I am hitting an error about how the the entry object has no attribute 'type', or that the URL is invalid. Is it something to do with not adding quotation marks to the youtube link or something?
If anyone has any insight I would greatly appreciate it. I assume I'm missing something very obvious, but I can't seem to figure out what exactly.
#!/usr/bin/env python
import sys
import os
import tkinter
from pytube import *
from tkinter import *
top=tkinter.Tk()
yt_variable = StringVar()
def helloCallBack():
    #Select youtube link you want to upload and print contents
    yt = YouTube(yt_entry)
    print(yt.get_videos())
    print(yt.filename)    
    #Set parameters for youtube video
    video = yt.get('mp4', '720p')
    print(yt.videos)
    print("success")
    #Select download location for youtube video
    video.download('C:/Users/coope/Dropbox/BrokenBow/Music/')
    print("Downloaded " + str(yt.filename) + " to " + str(video.download) + " successfully!")
    return
yt_label=tkinter.Label(top,text='Paste Link + Press Go')
yt_label.pack()
yt_button=tkinter.Button(top,text='Go',command= helloCallBack)
yt_button.pack()
yt_entry=tkinter.Entry(top, textvariable=yt_variable)
yt_entry.get()
yt_entry.pack()
top.mainloop()
 
                        
Briefly, you have the following:
You are expecting this to create an
Entrywidget, retrieve its contents, and send that retrieved value to theYouTube()constructor. It does not work like that. You are actually creating anEntrywidget, immediately retrieving its contents, throwing away those contents (which will be empty anyway, since by that point you haven't had a chance to put anything into that field), and then attempting to send theEntrywidget itself to theYouTube()constructor.On top of that, you give the
Entrywidget atextvariable, but then you never use it.Instead, retrieve the contents of that
Entrywidget (via itstextvariable) within the callback. You can even do it in theYouTube()constructor call.Since you're not doing anything special with that
Entrywidget, there's no need for atextvariableat all.Also, there's no need for a bare
returnat the end of a function. It will return regardless once there's nothing more to do, with a default return value ofNone(the same as what gets returned with a barereturnstatement, or withreturn None).