2024-11-15 14:07:58 +01:00
|
|
|
import yt_dlp
|
|
|
|
from PIL import Image
|
|
|
|
import requests
|
|
|
|
from io import BytesIO
|
|
|
|
from tkinter import *
|
|
|
|
from PIL import Image, ImageTk
|
|
|
|
|
|
|
|
def add_url():
|
|
|
|
|
|
|
|
url = EntryURL.get()
|
|
|
|
|
|
|
|
ydl_opts = {}
|
|
|
|
|
|
|
|
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
|
|
|
info = ydl.extract_info(url, download=False)
|
|
|
|
|
|
|
|
title = info.get('title', 'Titre indisponible')
|
2024-11-15 19:08:15 +01:00
|
|
|
subtitlte = (
|
|
|
|
info.get('artist', info.get('uploader', 'Artiste indisponible'))
|
|
|
|
+ ' · '
|
|
|
|
+ '{:,}'.format(info.get('view_count', 'Nombre de vue indisponible')).replace(',', ' ')
|
|
|
|
+ ' vues'
|
|
|
|
)
|
2024-11-15 14:07:58 +01:00
|
|
|
thumbnail_url = info.get('thumbnail')
|
2024-11-15 19:08:15 +01:00
|
|
|
|
2024-11-15 14:07:58 +01:00
|
|
|
response = requests.get(thumbnail_url)
|
|
|
|
image = Image.open(BytesIO(response.content))
|
|
|
|
width, height = image.size
|
|
|
|
|
2024-11-15 19:08:15 +01:00
|
|
|
# Découper l'image en un carré centré
|
|
|
|
square_size = min(width, height)
|
2024-11-15 14:07:58 +01:00
|
|
|
left = (width - square_size) // 2
|
|
|
|
top = (height - square_size) // 2
|
|
|
|
|
|
|
|
# Calculer les coordonnées du coin inférieur droit du carré
|
|
|
|
right = left + square_size
|
|
|
|
bottom = top + square_size
|
|
|
|
|
|
|
|
# Découper l'image carrée
|
|
|
|
image = image.crop((left, top, right, bottom))
|
|
|
|
image.thumbnail((50, 50))
|
|
|
|
|
2024-11-15 19:08:15 +01:00
|
|
|
# Création d'un cadre pour chaque vidéo
|
|
|
|
cadre = Frame(scrollable_frame)
|
2024-11-15 14:07:58 +01:00
|
|
|
cadre.pack(fill=X, padx=10, pady=5)
|
|
|
|
|
2024-11-15 19:08:15 +01:00
|
|
|
# Charger l'image et l'afficher
|
2024-11-15 14:07:58 +01:00
|
|
|
image = ImageTk.PhotoImage(image)
|
|
|
|
image_label = Label(cadre, image=image)
|
2024-11-15 19:08:15 +01:00
|
|
|
image_label.image = image # Préserver la référence pour éviter le garbage collection
|
2024-11-15 14:07:58 +01:00
|
|
|
image_label.pack(side=LEFT, padx=5)
|
|
|
|
|
2024-11-15 19:08:15 +01:00
|
|
|
# Ajouter les titres
|
2024-11-15 14:07:58 +01:00
|
|
|
texte_frame = Frame(cadre)
|
|
|
|
texte_frame.pack(side=LEFT, padx=10, fill=BOTH, expand=True)
|
|
|
|
|
|
|
|
label_texte1 = Label(texte_frame, text=title, font=("Arial", 12, "bold"))
|
|
|
|
label_texte1.pack(anchor="w")
|
|
|
|
|
|
|
|
label_texte2 = Label(texte_frame, text=subtitlte, font=("Arial", 10))
|
|
|
|
label_texte2.pack(anchor="w")
|
|
|
|
|
2024-11-15 19:08:15 +01:00
|
|
|
# Ajouter un bouton "Supprimer"
|
|
|
|
menu_button = Button(cadre, text="Supprimer", relief=FLAT, command=cadre.destroy)
|
2024-11-15 14:07:58 +01:00
|
|
|
menu_button.pack(side=RIGHT)
|
|
|
|
|
2024-11-15 19:08:15 +01:00
|
|
|
# Effacer l'entrée URL
|
|
|
|
EntryURL.delete(0, END)
|
2024-11-15 14:07:58 +01:00
|
|
|
|
|
|
|
# Fenêtre principale
|
|
|
|
root = Tk()
|
2024-11-15 19:08:15 +01:00
|
|
|
root.title("Téléchargeur YouTube")
|
|
|
|
root.geometry("1000x500")
|
2024-11-15 14:07:58 +01:00
|
|
|
|
2024-11-15 19:08:15 +01:00
|
|
|
# Cadre pour la barre d'URL
|
2024-11-15 14:07:58 +01:00
|
|
|
EntryFrame = Frame(root)
|
2024-11-15 19:08:15 +01:00
|
|
|
EntryFrame.pack(fill="x", padx=5, pady=2.5)
|
2024-11-15 14:07:58 +01:00
|
|
|
|
|
|
|
EntryURL = Entry(EntryFrame)
|
|
|
|
EntryURL.pack(side=LEFT, fill="x", expand=True, padx=2.5)
|
|
|
|
|
|
|
|
EntryButton = Button(EntryFrame, text="Ajouter", command=add_url)
|
|
|
|
EntryButton.pack(side=RIGHT, padx=3.5)
|
|
|
|
|
2024-11-15 19:08:15 +01:00
|
|
|
# LabelFrame pour lister les vidéos
|
|
|
|
MoviesList = LabelFrame(root, text="Vidéos à télécharger", relief=GROOVE)
|
2024-11-15 14:07:58 +01:00
|
|
|
MoviesList.pack(fill="both", expand=True, padx=5, pady=2.5)
|
|
|
|
|
2024-11-15 19:08:15 +01:00
|
|
|
# Canvas pour le défilement
|
|
|
|
MoviesCanva = Canvas(MoviesList, highlightthickness=0)
|
|
|
|
MoviesCanva.pack(side="left", fill="both", expand=True)
|
|
|
|
|
|
|
|
# Barre de défilement verticale
|
|
|
|
scrollbar = Scrollbar(MoviesList, orient="vertical", command=MoviesCanva.yview)
|
|
|
|
scrollbar.pack(side="right", fill="y")
|
|
|
|
MoviesCanva.configure(yscrollcommand=scrollbar.set)
|
|
|
|
|
|
|
|
# Frame pour les vidéos à l'intérieur du Canvas
|
|
|
|
scrollable_frame = Frame(MoviesCanva)
|
|
|
|
canvas_frame = MoviesCanva.create_window((0, 0), window=scrollable_frame, anchor="nw")
|
|
|
|
|
|
|
|
# Ajuster la taille du Canvas en fonction du contenu
|
|
|
|
def on_frame_configure(event):
|
|
|
|
MoviesCanva.configure(scrollregion=MoviesCanva.bbox("all"))
|
|
|
|
|
|
|
|
scrollable_frame.bind("<Configure>", on_frame_configure)
|
2024-11-15 14:07:58 +01:00
|
|
|
|
2024-11-15 19:08:15 +01:00
|
|
|
# Ajuster la largeur du Canvas au redimensionnement
|
|
|
|
MoviesCanva.bind("<Configure>", lambda e: MoviesCanva.itemconfig(canvas_frame, width=e.width))
|
2024-11-15 14:07:58 +01:00
|
|
|
|
|
|
|
root.mainloop()
|