Untitled
unknown
plain_text
2 years ago
5.6 kB
7
Indexable
import tkinter as tk
from tkinter import *
from tkinter import messagebox, filedialog
from pytube import YouTube
import os
# Creating object of tk class
root = tk.Tk()
# Creating the tkinter Variables
video_Link = StringVar()
download_Path = StringVar()
#eventually script for automatic downloads at a cadence
# Defining tk UI widgets
def Widgets():
head_label = Label(root, text=" ",
padx=5,
pady=5,
font="Helvetica 14",
bg="#efefef",
fg="#2d3142")
head_label.grid(row=1,
column=1,
pady=10,
padx=5,
columnspan=3)
link_label = Label(root,
text="YouTube link :",
bg="#f9dbbd",
pady=5,
padx=5)
link_label.grid(row=2,
column=0,
pady=5,
padx=5)
root.linkText = Entry(root,
width=35,
textvariable=video_Link,
font="Helvetica 14")
root.linkText.grid(row=2,
column=1,
pady=5,
padx=5,
columnspan=2)
destination_label = Label(root,
text="Destination :",
bg="#f9dbbd",
pady=5,
padx=9)
destination_label.grid(row=3,
column=0,
pady=5,
padx=5)
root.destinationText = Entry(root,
width=27,
textvariable=download_Path,
font="Arial 14")
root.destinationText.grid(row=3,
column=1,
pady=5,
padx=5)
# Defining functions:
# Defining Browse() to select a destination folder
def Browse():
# Presenting user with a pop-up for
# directory selection. initialdir
# argument is optional Retrieving the
# user-input destination directory and
# storing it in downloadDirectory
download_Directory = filedialog.askdirectory(
initialdir="YOUR DIRECTORY PATH", title="Save File")
# Displaying the directory in the directory
# textbox
download_Path.set(download_Directory)
#download_Path.set(download_Directory)
# Defining DownloadVideo() to download the video file
def DownloadVideo():
# getting user-input Youtube Link
Youtube_link = video_Link.get()
# select the optimal location for
# saving file's
download_Folder = download_Path.get()
# Creating object of YouTube()
getVideo = YouTube(Youtube_link)
# Getting all the available streams of the
# youtube video and selecting the first
# from the
videoStream = getVideo.streams.first()
# Downloading the video to destination
# directory
videoStream.download(download_Folder)
# Displaying the message
messagebox.showinfo("SUCCESS",
"Video file saved in \n"
+ download_Folder)
# Create video download button
Download_Video = Button(root,
text="Download Video",
command=DownloadVideo,
width=20,
bg="#7f96ff",
pady=10,
padx=15,
relief=GROOVE,
font="Helvetica, 13")
Download_Video.grid(row=4,
column=1,
pady=5,
padx=10)
# Defining DownloadAudio() to download the audio file
def DownloadAudio():
# getting user-input Youtube Link
Youtube_link = video_Link.get()
# select the optimal location for
# saving file's
download_Folder = download_Path.get()
# Creating object of YouTube()
getVideo = YouTube(Youtube_link)
# Getting all the available streams of the
# youtube video and selecting the first
# from the
videoStream = getVideo.streams.filter(only_audio=True).first()
# Downloading the video to destination
# directory
videoStream.download(download_Folder)
# Displaying the message
messagebox.showinfo("SUCCESS",
"Audio file saved in \n"
+ download_Folder)
# Create audio download button
Download_Audio = Button(root,
text="Download Audio",
command=DownloadAudio,
width=20,
bg="#7f96ff",
pady=10,
padx=15,
relief=GROOVE,
font="Helvetica, 13")
Download_Audio.grid(row=5,
column=1,
pady=5,
padx=10)
# Create browse button
browse_B = Button(root,
text="Browse",
command=Browse,
width=10,
bg="#f9dbbd",
relief=GROOVE)
browse_B.grid(row=3,
column=2,
pady=1,
padx=1)
# Setting the title, background color
# and size of the tkinter window and
# disabling the resizing property
root.geometry("520x280")
root.resizable(False, False)
root.title("YouTube Video and Audio Downloader")
root.config(background="#efefef")
# Calling the Widgets() function
Widgets()
# Defining infinite loop to run
# application
root.mainloop()Editor is loading...
Leave a Comment