Python scripts for download music video from youtube and convert it into mp3
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
pythube/pyDownloadConvert.py

60 lines
1.4 KiB

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)!')