from pytube import Playlist import youtube_dl, os, time from moviepy.editor import * ### FOR ONE VIDEO ### ## FUNTIONS ## # downloading def download(): try: print("downloading...", link) with youtube_dl.YoutubeDL(ydl_opts) as ydl: ydl.download([link]) except: print("un probleme est survenu... on réessaye!") # converting and renaming fonction def convert(video): videoO = VideoFileClip(video) # split the .mp4 filename, file_extension = os.path.splitext(str(video)) # renvoie le .mp3 dans le repertoire de destination return videoO.audio.write_audiofile(os.path.join("./" + destination + "/" + filename + ".mp3")) ## MAIN PROGRAM # recup des liens de la playlist via lien playlist input link = str(input("Entrer le lien de la video youtube a télécharger: ")) # creation du repertoire destination destination = str(input("Entrer le repertoire de destination:")) os.mkdir("./" + destination + "") # options ydl_opts = {'format': 'best',} # download download() # fini! print("Téléchargement terminé!") # convert and rename videos = os.listdir('./') for video in videos: if video.endswith('.mp4'): print("convertion en mp3...") convert(video) # cleaning try: for video in videos: if video.endswith('.mp4'): print("nettoyage des vidéos converties...") os.remove(video) except: print("rien à nettoyer!") # done! print('Vidéo(s) convertie(s)!')