push
This commit is contained in:
commit
15133c70ad
33
README.md
Normal file
33
README.md
Normal file
@ -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
|
60
pyDownloadConvert.py
Normal file
60
pyDownloadConvert.py
Normal file
@ -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)!')
|
42
pyOnlyDownload.py
Normal file
42
pyOnlyDownload.py
Normal file
@ -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é!")
|
77
pyPlaylistMaker.py
Normal file
77
pyPlaylistMaker.py
Normal file
@ -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!')
|
11
requirements.txt
Normal file
11
requirements.txt
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# PYTHUBE 1
|
||||||
|
bs4
|
||||||
|
PyQt5
|
||||||
|
urllib3
|
||||||
|
pytube==12.0.0
|
||||||
|
PyQtWebEngine
|
||||||
|
|
||||||
|
# PYTHUBE 2
|
||||||
|
youtube_dl
|
||||||
|
moviepy
|
||||||
|
#os
|
Loading…
x
Reference in New Issue
Block a user