From 15133c70ad21ac13074421bcf82a92ebc400814d Mon Sep 17 00:00:00 2001 From: greglebreton Date: Thu, 10 Nov 2022 15:57:33 +0100 Subject: [PATCH] push --- README.md | 33 +++++++++++++++++++ pyDownloadConvert.py | 60 ++++++++++++++++++++++++++++++++++ pyOnlyDownload.py | 42 ++++++++++++++++++++++++ pyPlaylistMaker.py | 77 ++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 11 +++++++ 5 files changed, 223 insertions(+) create mode 100644 README.md create mode 100644 pyDownloadConvert.py create mode 100644 pyOnlyDownload.py create mode 100644 pyPlaylistMaker.py create mode 100644 requirements.txt diff --git a/README.md b/README.md new file mode 100644 index 0000000..5612807 --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +# PYTHUBE + +## DEFINITION + +Ce projet a pour but d'automatiser le téléchargement d'une playlist Youtube à partir de l'URL de celle-ci. +Une fois le téléchargement éffectué, les fichiers sont convertis en MP3 et déplacés dans un dossier. + +## UTILISATION + +- Installation des dépendances: +```bash +python3 -m pip install -r requirements.txt +``` + +- Execution du script: +Pour télécharger une vidéo: +```bash +python3 pyDownload.py +``` +Pour convertir une vidéo en MP3: +```bash +python3 pyMp3Converter.py +``` +Pour télécharger une playlist et la convertir en MP3: +```bash +python3 pyPlaylistMaker.py +``` + +## WORKFLOW + +- Saisir l'URL de la playlist à télécharger +- Saisir le nom du dossier de destination +- Attendre l'arrivée et la conversion des vidéos \ No newline at end of file diff --git a/pyDownloadConvert.py b/pyDownloadConvert.py new file mode 100644 index 0000000..d6f9678 --- /dev/null +++ b/pyDownloadConvert.py @@ -0,0 +1,60 @@ +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)!') \ No newline at end of file diff --git a/pyOnlyDownload.py b/pyOnlyDownload.py new file mode 100644 index 0000000..9e27af7 --- /dev/null +++ b/pyOnlyDownload.py @@ -0,0 +1,42 @@ +from pytube import Playlist +import youtube_dl, os, time +from moviepy.editor import * + +### FOR DOWNLOAD 1 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:")) +destination = "" +#os.mkdir("./" + destination + "") + +# options +ydl_opts = {'format': 'best',} + +# download +download() + +# fini! +print("Téléchargement terminé!") \ No newline at end of file diff --git a/pyPlaylistMaker.py b/pyPlaylistMaker.py new file mode 100644 index 0000000..c5901f4 --- /dev/null +++ b/pyPlaylistMaker.py @@ -0,0 +1,77 @@ +from pytube import Playlist +import youtube_dl, os, time +from moviepy.editor import * + +### FOR A PLAYLIST ### + +## FUNTIONS +# downloading +def download(): + try: + for link in linkset: + print("downloading...", link) + with youtube_dl.YoutubeDL(ydl_opts) as ydl: + ydl.download([link]) + except: + print("un probleme est survenu... on réessaye!") + retry(2) + +# 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")) + +# retry fonction en cas d'erreurs +def retry(download, max_tries=10): + for i in range(max_tries): + try: + time.sleep(0.5) + download() + break + except Exception: + continue + + +## MAIN PROGRAM +# recup des liens de la playlist via lien playlist input +playlist = Playlist(str(input("Entrer les liens de la playlist youtube: "))) +linkset = list(playlist.video_urls) +print(linkset) + +# creation du repertoire destination +destination = str(input("Entrer le repertoire de destination:")) +os.mkdir("./" + destination + "") + +# download options +ydl_opts = {'format': 'best',} + +# download +download() + +# convert and rename +try: + videos = os.listdir("./") +except: + print("vidéos à convertir introuvables dans le dossier courant") + +for video in videos: + if video.endswith('.mp4'): + print("convertion en mp3...") + convert(video) +# move to folder + +# cleaning +for video in videos: + try: + if video.endswith('.mp4'): + print(video) + os.remove(video) + except: + print("rien à nettoyer!") + break + +# done! +print('Done!') \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..5b571ea --- /dev/null +++ b/requirements.txt @@ -0,0 +1,11 @@ +# PYTHUBE 1 +bs4 +PyQt5 +urllib3 +pytube==12.0.0 +PyQtWebEngine + +# PYTHUBE 2 +youtube_dl +moviepy +#os