Youtube’dan istediğimiz kalitede video, ses ya da oynatma listesi indirebileceğimiz masaüstü bir uygulama yapmayı öğreniyoruz.

Video Serisi Boyunca Kullandığımız Siteler:

https://fonts.google.com/

https://colorhunt.co/

https://pypi.org/project/pytube3/

https://python-pytube.readthedocs.io/en/latest/

https://stackoverflow.com/questions/62661930/pytube3-playlist-returns-empty-list

https://stackoverflow.com/questions/62098925/why-my-youtube-video-downloader-only-downloads-some-videos-and-for-other-videos

Kurulum:

pip install pytube3

Kodlar:

from tkinter import *
from tkinter import ttk
import os
from tkinter import filedialog
from pytube import YouTube
from pytube import Playlist
import re


class AnaSayfa(Tk):
    def __init__(self):
        Tk.__init__(self)

        self.cerceve1 = Frame(self, bg="#769fcd")
        self.cerceve1.pack(side=TOP, fill=X)
        self.cerceve2 = Frame(self, bg="#b9d7ea")
        self.cerceve2.pack(side=TOP, fill=X)

        Label(self.cerceve1, text="YOUTUBE İNDİRME PROGRAMI", font=("Baloo 2", 17, "bold"), bg="#769fcd").pack()
        Button(self.cerceve1, text="VİDEO / SES", font=("Baloo 2", 12), bg="#769fcd", activebackground="#b9d7ea",
               width=25, command=lambda: Video(self)).pack()
        Button(self.cerceve1, text="OYNATMA LİSTESİ", font=("Baloo 2", 12), bg="#769fcd", activebackground="#b9d7ea",
               width=25, command=lambda: OynatmaListesi(self)).pack()


class Video(Frame):
    def __init__(self, master):
        Frame.__init__(self, master)

        for widget in master.cerceve2.winfo_children():
            widget.destroy()

        Label(master.cerceve2, text="VİDEO / SES", font=("Baloo 2", 13, "bold"), bg="#b9d7ea").pack()
        Label(master.cerceve2, text="URL", font=("Baloo 2", 12, "bold"), bg="#b9d7ea").pack()

        self.url = Entry(master.cerceve2, width=40, font=("Baloo 2", 11))
        self.url.pack()
        self.url.bind("<1>", self.tikla)

        Label(master.cerceve2, text="KALİTE", font=("Baloo 2", 12, "bold"), bg="#b9d7ea").pack()
        kalite = ["Max. Kalite", "Min. Kalite", "360p", "Sadece Ses"]
        self.kalite_sec = ttk.Combobox(master.cerceve2, font=("Baloo 2", 12), width=24, value=kalite)
        self.kalite_sec.pack()
        self.kalite_sec.current(0)

        Label(master.cerceve2, text="KAYIT YERİ", font=("Baloo 2", 12, "bold"), bg="#b9d7ea").pack()
        self.kayit_yeri_gosterilen = Label(master.cerceve2, text=f"{os.getcwd()}", font=("Baloo 2", 9), bg="#b9d7ea")
        self.kayit_yeri_gosterilen.pack()

        Button(master.cerceve2, text="SEÇ", font=("Baloo 2", 12), bg="#b9d7ea", activebackground="#769fcd",
               width=25, command=self.kayit_yeri_sec).pack()
        Button(master.cerceve2, text="İNDİR", font=("Baloo 2", 12), bg="#b9d7ea", activebackground="#769fcd",
               width=25, command=self.indir).pack()

        self.indiriliyor = Label(master.cerceve2, text="", bg="#b9d7ea", font=("Baloo 2", 12))
        self.indiriliyor.pack()

    def tikla(self, event):

        try:
            if "youtube" in self.clipboard_get():
                self.url.delete(0, END)
                self.url.insert(0, self.clipboard_get())
        except TclError:
            pass

    def kayit_yeri_sec(self):

        self.kayit_yeri_gosterilen.config(text=filedialog.askdirectory())

    def indir(self):

        self.yt = YouTube(self.url.get())

        if self.kalite_sec.get() == "Max. Kalite":
            self.yt.streams.get_highest_resolution().download(self.kayit_yeri_gosterilen['text'])
        elif self.kalite_sec.get() == "Min. Kalite":
            self.yt.streams.get_lowest_resolution().download(self.kayit_yeri_gosterilen['text'])
        elif self.kalite_sec.get() == "360p":
            self.yt.streams.get_by_resolution("360p").download(self.kayit_yeri_gosterilen['text'])
        elif self.kalite_sec.get() == "Sadece Ses":
            self.yt.streams.get_audio_only().download(self.kayit_yeri_gosterilen['text'])

        self.indiriliyor.config(text="İndirme Tamamlandı!!!")


class OynatmaListesi(Frame):
    def __init__(self, master):
        Frame.__init__(self, master)

        for widget in master.cerceve2.winfo_children():
            widget.destroy()

        Label(master.cerceve2, text="OYNATMA LİSTESİ", font=("Baloo 2", 13, "bold"), bg="#b9d7ea").pack()
        Label(master.cerceve2, text="URL", font=("Baloo 2", 12, "bold"), bg="#b9d7ea").pack()

        self.url = Entry(master.cerceve2, width=40, font=("Baloo 2", 11))
        self.url.pack()
        self.url.bind("<1>", self.tikla)

        Label(master.cerceve2, text="KALİTE", font=("Baloo 2", 12, "bold"), bg="#b9d7ea").pack()
        kalite = ["Max. Kalite", "Min. Kalite", "360p", "Sadece Ses"]
        self.kalite_sec = ttk.Combobox(master.cerceve2, font=("Baloo 2", 12), width=24, value=kalite)
        self.kalite_sec.pack()
        self.kalite_sec.current(0)
        Label(master.cerceve2, text="KAYIT YERİ", font=("Baloo 2", 12, "bold"), bg="#b9d7ea").pack()
        self.kayit_yeri_gosterilen = Label(master.cerceve2, text=f"{os.getcwd()}", font=("Baloo 2", 9), bg="#b9d7ea")
        self.kayit_yeri_gosterilen.pack()
        Button(master.cerceve2, text="SEÇ", font=("Baloo 2", 12), bg="#b9d7ea", activebackground="#769fcd",
               width=25, command=self.kayit_yeri_sec).pack()
        Button(master.cerceve2, text="İNDİR", font=("Baloo 2", 12), bg="#b9d7ea", activebackground="#769fcd",
               width=25, command=self.indir).pack()

        self.indiriliyor = Label(master.cerceve2, text="", bg="#b9d7ea", font=("Baloo 2", 12))
        self.indiriliyor.pack()

    def tikla(self, event):

        try:
            if "youtube" in self.clipboard_get():
                self.url.delete(0, END)
                self.url.insert(0, self.clipboard_get())
        except TclError:
            pass

    def kayit_yeri_sec(self):

        self.kayit_yeri_gosterilen.config(text=filedialog.askdirectory())

    def indir(self):

        playlist = Playlist(self.url.get())
        playlist._video_regex = re.compile(r"\"url\":\"(/watch\?v=[\w-]*)")

        if self.kalite_sec.get() == "Max. Kalite":
            for video in playlist.video_urls:
                YouTube(video).streams.get_highest_resolution().download(self.kayit_yeri_gosterilen['text'])
        elif self.kalite_sec.get() == "Min. Kalite":
            for video in playlist.video_urls:
                YouTube(video).streams.get_lowest_resolution().download(self.kayit_yeri_gosterilen['text'])
        elif self.kalite_sec.get() == "360p":
            for video in playlist.video_urls:
                YouTube(video).streams.get_by_resolution("360p").download(self.kayit_yeri_gosterilen['text'])
        elif self.kalite_sec.get() == "Sadece Ses":
            for video in playlist.video_urls:
                YouTube(video).streams.get_audio_only().download(self.kayit_yeri_gosterilen['text'])

        self.indiriliyor.config(text="İndirme Tamamlandı!!!")



if __name__ == "__main__":
    app = AnaSayfa()
    app.configure(bg="#b9d7ea")
    app.title("Youtube İndirme Programı")
    app.iconphoto(True, PhotoImage(file="sft.png"))
    app.geometry("600x475+250+75")
    app.resizable(False, False)
    app.mainloop()

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir