NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

import os
import tkinter as tk
from tkinter import *
from tkinter import messagebox
from tkinter import font as tk_font
from tkinter import filedialog as fd
import getpass
import re
from pytube import YouTube
from pytube import Playlist
import ffmpeg as ff


progress = 0


def show_progress_bar(stream, chunk, bytes_remaining):
global progress
total_size = stream.filesize
bytes_downloaded = total_size - bytes_remaining
percentage_of_completion = int(bytes_downloaded / total_size * 100)
if progress < percentage_of_completion:
progress = percentage_of_completion
progress_string = "Completed: "+str(progress)+"%"
# show the percentage of completed download
print("r", progress_string, end='')


def single_download(video_url, path, resolution):
print("Requested Resolution: ", resolution)
yt = YouTube(video_url)
global progress
progress = 0
yt.register_on_progress_callback(show_progress_bar)
yt_vid = yt.streams.filter(file_extension='mp4', res=resolution).desc().first()
print("Available Resolution: ", yt_vid.resolution)
print("File size: ", round(yt_vid.filesize/1000000, 2), "MB")
print("Downloading...n", yt_vid.title)
if not os.path.exists(path):
os.makedirs(path)
vid_loc = yt_vid.download(path)
aud_loc = yt.streams.filter(file_extension='mp4', type='audio').desc().first()
.download(path, filename=yt_vid.title+"_audio")
if vid_loc and aud_loc:
out_loc = path + yt_vid.title + '_video.mp4'
ip_vid = ff.input(vid_loc)
ip_aud = ff.input(aud_loc)
out = ff.output(ip_vid, ip_aud, out_loc,
vcodec='copy', acodec='aac', strict='experimental')
print("nMerging Video and Audio files...")
out.run()
if os.path.exists(out_loc):
os.remove(vid_loc)
os.rename(out_loc, vid_loc)
os.remove(aud_loc)
print("nDone!")
tk.messagebox.showinfo("Success", yt_vid.title + " downloaded")
else:
print("nNot downloaded")


def playlist_download(video_url, path):
global progress
if not os.path.exists(path):
os.makedirs(path)
pl = Playlist(video_url)
no_of_videos = pl.__len__()
print("Total videos in the playlist: ", no_of_videos)
count = 0
for video in pl.videos:
progress = 0
count = count+1
video.register_on_progress_callback(show_progress_bar)
vid = video.streams.filter(progressive=True, file_extension='mp4')
.order_by('resolution').desc().first()
print("nDownloading video %d of %d..." % (count, no_of_videos))
print("nTitle: ", vid.title)
print("Resolution: ", vid.resolution)
print("File size: ", round(vid.filesize/1000000, 2), "MB")
vid.download(path)
print(" Done!")
tk.messagebox.showinfo("Success", "Download completed")


def multiple_download(video_urls, path, resolution):
# Get URLs from video_urls
urls = re.split('[;, rn]', video_urls)
# urls = list(video_urls.split(","))
for video_url in urls:
if "http" in video_url:
print("URl: ", video_url)
yt = YouTube(video_url)
global progress
progress = 0
print("Requested Resolution: ", resolution)
yt.register_on_progress_callback(show_progress_bar)
yt_vid = yt.streams.filter(file_extension='mp4', type='video',
progressive=False, res=resolution).desc().first()
print("Available Resolution: ", yt_vid.resolution)
print("File size: ", round(yt_vid.filesize/1000000, 2), "MB")
print("Downloading...n", yt_vid.title)
if not os.path.exists(path):
os.makedirs(path)
vid_loc = yt_vid.download(path)
aud_loc = yt.streams.filter(file_extension='mp4', type='audio').desc().first()
.download(path, filename=yt_vid.title+"_audio")
if vid_loc and aud_loc:
out_loc = path + yt_vid.title + '_video.mp4'
ip_vid = ff.input(vid_loc)
ip_aud = ff.input(aud_loc)
out = ff.output(ip_vid, ip_aud, out_loc,
vcodec='copy', acodec='aac', strict='experimental')
print("nMerging Video and Audio files...")
out.run()
if os.path.exists(out_loc):
os.remove(vid_loc)
os.rename(out_loc, vid_loc)
os.remove(aud_loc)
print("nDone!")
# tk.messagebox.showinfo("Success", yt_vid.title + " downloaded")
else:
print("nNot downloaded")
tk.messagebox.showinfo("Success", "All videos downloaded")


class YTAppGUI(tk.Tk):

def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
self.title("My YouTube Downloader")
self.geometry("720x200")

self.title_font = tk_font.Font(family='Arial Rounded MT Bold', size=18)

# the container is where we'll stack a bunch of frames
# on top of each other, then the one we want visible
# will be raised above the others
container = tk.Frame(self)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)

self.frames = {}
for F in (StartPage, PageOne, PageTwo, PageThree):
page_name = F.__name__
frame = F(parent=container, controller=self)
self.frames[page_name] = frame

# put all of the pages in the same location;
# the one on the top of the stacking order
# will be the one that is visible.
frame.grid(row=0, column=0, sticky="nsew")

self.show_frame("StartPage")

def show_frame(self, page_name):
# Show a frame for the given page name
frame = self.frames[page_name]
frame.tkraise()

def quit(self):
self.destroy()


class StartPage(tk.Frame):

def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller

label = tk.Label(self, text="YouTube Video Downloader", font=controller.title_font)
label.pack(side="top", fill="x", pady=10)

single_btn = tk.Button(self, text="Single Download", width=15, height=2,
command=lambda: controller.show_frame("PageOne"))

playlist_btn = tk.Button(self, text="Playlist Download", width=15, height=2,
command=lambda: controller.show_frame("PageTwo"))
multiple_btn = tk.Button(self, text="Multiple Download", width=15, height=2,
command=lambda: controller.show_frame("PageThree"))
single_btn.pack()
playlist_btn.pack()
multiple_btn.pack()

exit_btn = tk.Button(self, text='Quit', width=10, height=2,
command=lambda: controller.quit())
exit_btn.pack()


class PageOne(tk.Frame):

def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller

url_label = tk.Label(self, text='YouTube URL')
url_entry = tk.Entry(self, width=60, font=('calibre', 10, 'normal'))

loc_label = tk.Label(self, text='Download location')
self.loc_entry = tk.Entry(self, width=60, font=('calibre', 10, 'normal'))
self.loc_entry.insert(0, "/Users/" + getpass.getuser() + "/Downloads/YouTube Downloads/")

var = StringVar()
res_label = tk.Label(self, text='Choose resolution')
res_btn1 = tk.Radiobutton(self, text='144p', variable=var, value='144p')
res_btn2 = tk.Radiobutton(self, text='240p', variable=var, value='240p')
res_btn3 = tk.Radiobutton(self, text='360p', variable=var, value='360p')
res_btn4 = tk.Radiobutton(self, text='480p', variable=var, value='480p')
res_btn5 = tk.Radiobutton(self, text='720p', variable=var, value='720p')
res_btn6 = tk.Radiobutton(self, text='1080p', variable=var, value='1080p')

sub_btn = tk.Button(self, text='Submit',
command=lambda: single_download(str(url_entry.get()), str(self.loc_entry.get()),
str(var.get())))
choose_loc_btn = tk.Button(self, text='Choose other location', command=self.dir_path)
go_back_btn = tk.Button(self, text='Go Back', command=lambda: controller.show_frame("StartPage"))

url_label.grid(row=0, column=0)
url_entry.grid(row=0, column=1)
loc_label.grid(row=1, column=0)
self.loc_entry.grid(row=1, column=1)
choose_loc_btn.grid(row=1, column=2)
res_label.grid(row=2, column=0)
res_btn1.grid(row=3, column=0)
res_btn2.grid(row=3, column=1)
res_btn3.grid(row=3, column=2)
res_btn4.grid(row=4, column=0)
res_btn5.grid(row=4, column=1)
res_btn6.grid(row=4, column=2)
sub_btn.grid(row=5, column=1)
go_back_btn.grid(row=6, column=1)

def sel(self):
# url_entry.delete(0, END)
return

def dir_path(self):
self.loc_entry.delete(0, END)
self.loc_entry.insert(0, str(fd.askdirectory(initialdir="/Users/" + getpass.getuser() + "/Downloads/")))


class PageTwo(tk.Frame):

def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller

url_label = tk.Label(self, text='YouTube Playlist URL')
url_entry = tk.Entry(self, width=60, font=('calibre', 10, 'normal'))

loc_label = tk.Label(self, text='Download location')
self.loc_entry = tk.Entry(self, width=60, font=('calibre', 10, 'normal'))
self.loc_entry.insert(0, "/Users/" + getpass.getuser() + "/Downloads/YouTube Downloads/")

sub_btn = tk.Button(self, text='Submit', font=14,
command=lambda: playlist_download(str(url_entry.get()), str(self.loc_entry.get())))
go_back_btn = tk.Button(self, text='Go Back', command=lambda: controller.show_frame("StartPage"))
choose_loc_btn = tk.Button(self, text='Choose other location', command=self.dir_path)

url_label.grid(row=0, column=0)
url_entry.grid(row=0, column=1)
loc_label.grid(row=1, column=0)
self.loc_entry.grid(row=1, column=1)
choose_loc_btn.grid(row=1, column=2)
sub_btn.grid(row=2, column=1)
go_back_btn.grid(row=3, column=1)

def dir_path(self):
self.loc_entry.delete(0, END)
self.loc_entry.insert(0, str(fd.askdirectory(initialdir="/Users/" + getpass.getuser() +
"/Downloads/")))


class PageThree(tk.Frame):

def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller

var = StringVar()
url_label = tk.Label(self, text='YouTube URLs')
urls_text = tk.Text(self, height=5, width=60, highlightbackground="navy")
res_btn1 = tk.Radiobutton(self, text='144p', variable=var, value='144p')
res_btn2 = tk.Radiobutton(self, text='240p', variable=var, value='240p')
res_btn3 = tk.Radiobutton(self, text='360p', variable=var, value='360p')
res_btn4 = tk.Radiobutton(self, text='480p', variable=var, value='480p')
res_btn5 = tk.Radiobutton(self, text='720p', variable=var, value='720p')
res_btn6 = tk.Radiobutton(self, text='1080p', variable=var, value='1080p')

loc_label = tk.Label(self, text='Download location')
self.loc_entry = tk.Entry(self, width=60, font=('calibre', 10, 'normal'))
self.loc_entry.insert(0, "/Users/" + getpass.getuser() + "/Downloads/")

sub_btn = tk.Button(self, text='Submit', font=14,
command=lambda: multiple_download(str(urls_text.get("1.0", END)),
str(self.loc_entry.get()),
str(var.get())))
go_back_btn = tk.Button(self, text='Go Back', command=lambda: controller.show_frame("StartPage"))
choose_loc_btn = tk.Button(self, text='Choose other location', command=self.dir_path)

url_label.grid(row=0, column=0)
urls_text.grid(row=0, column=1)
loc_label.grid(row=1, column=0)
self.loc_entry.grid(row=1, column=1)
choose_loc_btn.grid(row=1, column=2)
res_btn1.grid(row=2, column=0)
res_btn2.grid(row=2, column=1)
res_btn3.grid(row=2, column=2)
res_btn4.grid(row=3, column=0)
res_btn5.grid(row=3, column=1)
res_btn6.grid(row=3, column=2)
sub_btn.grid(row=4, column=1)
go_back_btn.grid(row=5, column=1)

def dir_path(self):
self.loc_entry.delete(0, END)
self.loc_entry.insert(0, str(fd.askdirectory(initialdir="/Users/" + getpass.getuser() +
"/Downloads/")))


if __name__ == "__main__":
app = YTAppGUI()
app.mainloop()
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.