Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

tkinter yt downloader with resolution

from tkinter import *
import pafy

class YouTubeDownloader:
    def __init__(self,master):
        self.master = master
        master.title("Youtube Downloader")
        self.media_option = StringVar()
        self.audio_quality_lsit = []
        self.audio_quality_drop_menu = StringVar()
        self.video_quality_lsit = []
        self.video_quality_drop_menu = StringVar()
        Label(master, text="YouTube URL:").grid(row=0)
        self.url_field = Entry(master)
        self.url_field.grid(row=0, column=1)
        Button(master, text='Paste URL', command=self.url).grid(row=0, column=4, sticky=W, pady=10)
        Button(master, text='Download', command=self.download).grid(row=12, column=4, sticky=W, pady=10)
        Label(master, text="Media Type: ").grid(row=3)
        media_drop_menu = OptionMenu(master, self.media_option, "Audio", "Video", command=self.media_select)
        media_drop_menu.grid(row=5, column=0)


    def url(self):
        global data
        url = self.url_field.get()
        data = pafy.new(url)


    def media_select(self):
        global  A_V
        A_V = self.media_option.get()
        if A_V == "Audio":
            audio()
        elif A_V == "Video":
            video()


    def audio():
        global selected_audio
        audio_streams = self.data.audiostreams
        for audio_quality in audio_streams:
            audio_quality_lsit.append(audio_quality.bitrate)
        selected_audio = audio_quality_drop_menu.get()
        print("selected_audio") #Debug Statement
        Label(master, text="Audio Bitrate: ").grid(row=7, column=1)
        show_drop_menu = OptionMenu(master, audio_quality_drop_menu, *audio_quality_lsit)
        show_drop_menu.grid(row=9, column=1)


    def video(self):
        global selected_video
        video_streams = self.data.streams
        for video_quality in video_streams:
            video_quality_lsit.append(video_quality.resolution)
        selected_video = video_quality_drop_menu.get()
        print("selected_video")  #Debug Statement
        Label(master, text="Video Quality: ").grid(row=7, column=1)
        show_drop_menu = OptionMenu(master, video_quality_drop_menu, *video_quality_lsit)
        show_drop_menu.grid(row=9, column=1)


    def download(self):
        if selected_audio:
            print("Audio")  #Debug Statement
            self.selected_audio.download(quiet=False)
        elif selected_video:
            print("Video")  #Debug Statement
            self.selected_video.download(quiet=False)



root = Tk()
my_youtube = YouTubeDownloader(root)
root.mainloop()
Comment

PREVIOUS NEXT
Code Example
Python :: from wireframe GUI design to python tkinter 
Python :: Highlighting the shortest path in a Networkx graph 
Python :: gnome-terminal stopped executing after python 3.6 is installed 
Python :: gcp functions save BQ 
Python :: windows python pip upgrade 
Shell :: bash watch cpu frequency, linux cpu frequency, linux live cpu frequency 
Shell :: FirewallD is not running 
Shell :: ubuntu audio restart 
Shell :: how to install cv2 
Shell :: how to upgrade pip 
Shell :: linux how to see ports in use 
Shell :: [ERROR] Error while getting Capacitor CLI version. Is Capacitor installed? 
Shell :: gyp ERR! stack Error: not found: make 
Shell :: linker `cc` not found 
Shell :: notepad++ ubuntu 
Shell :: create react app typescript 
Shell :: install snap on kalicannot communicate with server: Post "http://localhost/v2/snaps/core": dial unix /run/snapd.socket: connect: no such file or directory 
Shell :: ubuntu remove temp files 
Shell :: Failed to start gunicorn daemon ubuntu 
Shell :: write a bash program to print a given number in reverse order 
Shell :: flask restful install 
Shell :: uninstall qt creator ubuntu 
Shell :: conda instal uvicorn windows 
Shell :: recent branches 
Shell :: check my ubuntu version 
Shell :: .ps1 is not digitally signed. You cannot run this script on the current system. 
Shell :: ubuntu du sort by dir size 
Shell :: uninstall foxit reader ubuntu 18.04 
Shell :: cmake must be installed to build dlib 
Shell :: dotnet build release 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =