Mar-05-2020, 07:52 PM
hi every one,
i use Embedding Youtube-dl on windows
i try to bring the total video from playlist of youtube
for exemple here have 13 vidéos
Link playlist
but i receive this error message
for video in playlist_dict['entries']:
TypeError: 'NoneType' object is not subscriptable
some one have idea
thank you in advance for your time
i use Embedding Youtube-dl on windows
i try to bring the total video from playlist of youtube
for exemple here have 13 vidéos
Link playlist
# ===================== Embedding Youtube-dl =================================
# les options de la version Python se trouvent dans le fichier "YoutubeDL.py".
# ============================================================================
#!usrbinpython3
# -- coding utf-8 --
import youtube_dl
from tkinter import *
from tkinter import ttk
from tkinter import filedialog
import time
class Root(Tk):
def __init__(self):
super(Root, self).__init__()
self.title("[Embedding yt-dl GUI]")
self.geometry("600x120+10+10")
self.resizable(width=False, height=False)
# Cadre - Titre et Bouton de téléchargement encapsulé
self.buttonFrame = ttk.LabelFrame(self, text="")
self.buttonFrame.place(x=5, y=72, width=270, height=43)
self.progressBar()
def progressBar(self):
# Widget - Bouton - sélection du chemin de stockage via OpenFolder
self.button0 = Button(text='Chemin de stockage', command=self.Folder_Destination)
self.button0.place(x=5, y=5, width=140, height=22)
# Widget - Label0 - Affiche le chemin de stockage
self.label0 = Label(text='')
self.label0.place(x=150, y=5)
# Widget - Combobox - Création de la Liste déroulante
self.combo = ttk.Combobox(font=('Verdana', 8))
self.combo.place(x=5, y=30, width=140, height=22)
# -- Liste des valeurs
self.var = StringVar()
self.combo['values'] = ("Youtube", "Youtube playlist", "Youtube chaîne", "Tweeter", "Facebook", "ARTE", "TSR", "6play", "Dailymotion", "Vimeo", "PublicSenat")
# -- Valeur sélectionée
self.combo.bind("<<ComboboxSelected>>", self.callback)
# Widget - Bouton - Lance le téléchargement
self.button2 = ttk.Button(self.buttonFrame, text="Télécharger", command=self.run_progressbar)
self.button2.place(x=5, y=0, width=80, height=22)
# Widget - Label0 - Progression du téléchargement
self.label1 = ttk.Label(self.buttonFrame, text="")
self.label1.place(x=85, y=0, width=80, height=22)
# Widget - Barre de progression - ttk.Progressbar
self.progress_bar = ttk.Progressbar(self.buttonFrame, orient='horizontal', length=140, mod='determinate')
self.progress_bar.place(x=140, y=0, width=120, height=22)
# Retourne la valeur sélectionnée - Combobox
def callback(self, event=None):
print('--- callback ---')
print('var.get():', self.var.get())
if event:
print('event.widget.get():', event.widget.get())
self.var.set(event.widget.get())
print('var.get():', self.var.get())
def Folder_Destination(self):
# Dossier = StringVar()
self.Dossier = filedialog.askdirectory(title='Sélectionner un chemin de stockage ...')
print("Folder_Destination Dossier " + str(self.Dossier))
# Widget - label0 - Affiche la valeur du chemin de stockage
self.label0["text"] = str(" ") + str(self.Dossier)
self.label0.update()
def run_progressbar(self):
def my_hook(d):
# (d) - Dictionnaire - Recensement des paramètres de téléchargement Youtube-dl
if d['status'] == 'downloading':
print(d['_percent_str'], d['_eta_str'])
# "[:-1]" permet de retenir de la chaine que les n-1 premiers caractères
# (n étant ici la longueur totale de la chaine). Autrement dit, on neutralise le "%" final
percent_download = float(d['_percent_str'][:-1])
# Envoie la valeur 'percent_download' à la barre de progression
self.progress_bar["value"] = percent_download
self.progress_bar.update()
# Envoie la valeur 'percent_download' au Label1
self.label1["text"] = str(" ") + str(percent_download) + str("%")
self.label1.update()
if d['status'] == 'finished':
print('Téléchargement effectué ...')
if self.var.get() == "Youtube":
print('var.get() - in Progressbar :', self.var.get())
print('-+-+-+-+-+-+-+-+-')
ydl_opts = {
'ignoreerrors': True,
'quiet': True
}
# input_file = open(var_URL.get())
for playlist in var_URL.get():
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
print('var.get() - in Progressbar :', self.var.get())
print(var_URL.get())
playlist_dict = ydl.extract_info(playlist, download=False)
for video in playlist_dict['entries']:
print([0])
if not video:
print('ERROR: Unable to get info. Continuing...')
continue
for property in ['thumbnail', 'id', 'title', 'description', 'duration']:
print(property, '--', video.get(property))
if self.var.get() == "Youtube1":
print('var.get() - in Progressbar :', self.var.get())
ydl_opts = {
# -- Console Infos --
'verbose': True,
# -- Extraction Video --
'format': 'best',
# -- Titre et Extension --
'outtmpl': str(self.Dossier) + chr(47) + '%(title)s.%(ext)s',
# données "json"
"writeinfojson": True,
# -- --
'logger': MyLogger(),
'progress_hooks': [my_hook],
}
if self.var.get() == "Youtube playlist":
print('var.get() - in Progressbar :', self.var.get())
ydl_opts = {
# -- Console Infos --
'verbose': True,
# -- Extraction Video --
'format': 'best',
# -- Titre et Extension --
'outtmpl': str(self.Dossier) + chr(47) + '%(title)s.%(ext)s',
# données "json"
"writeinfojson": True,
# -- --
'logger': MyLogger(),
'progress_hooks': [my_hook],
}
##############################################################################
if self.var.get() == "Youtube":
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
print(var_URL.get())
ydl.download([var_URL.get()])
if self.var.get() == "Youtube playlist":
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
print(var_URL.get())
ydl.download([var_URL.get()])
# self.progress_bar["value"] = 0
##############################################################################
##############################################################################
# Remonte les messages de mise au point (log). C'est nécessaire au moins pour les "vraies" erreurs.
# Rien n'empêche de créer un fichier log avec l'écriture de tous les messages pour garder une trace de ce qui s'est passé.
class MyLogger(object):
def debug(self, msg):
pass
def warning(self, msg):
pass
def error(self, msg):
print(msg)
def info(self, msg):
print(msg)
root = Root()
# Widget - Entry URL
var_URL = StringVar()
Input1 = Entry(bd=2, justify=CENTER, textvariable=var_URL)
Input1.place(x=5, y=55, width=590, height=22)
root.mainloop()i just add the line 99 to 125but i receive this error message
for video in playlist_dict['entries']:
TypeError: 'NoneType' object is not subscriptable
some one have idea
thank you in advance for your time
