Skip to content

Instantly share code, notes, and snippets.

@Julien00859
Created February 11, 2016 21:06
Show Gist options
  • Save Julien00859/400d952aa957c75f7c12 to your computer and use it in GitHub Desktop.
Save Julien00859/400d952aa957c75f7c12 to your computer and use it in GitHub Desktop.
Youtube playlist download (partialy, need the user to download the youtube video with a tool like youtube-mp3)
from urllib.request import urlopen
import re
from bs4 import BeautifulSoup as bs4
import webbrowser
from mutagen.easyid3 import EasyID3
from os.path import join
lien = "https://www.youtube.com/playlist?list=PLPZappeJ88mGglSaXJ4i6_5KPI0SI_RNG"
path = "F:/Bibliothèque/Musique/Approaching Nirvana/13. Cinematic Soundscapes Vol. 2/"
artist = "Approaching Nirvana"
album = "Cinematic Soundspaces Vol. 2"
date = "2015"
title = re.compile("^[0-9a-zA-Z\ ]{1,}")
soup = bs4(urlopen(lien).read().decode(), "html.parser")
liste = soup.find(id="pl-load-more-destination").find_all("a", class_="pl-video-title-link")
print("Musics are: \n\t- " + "\n\t- ".join([a.get_text().strip() for a in liste]))
for lien in liste:
input("Press Enter to download \"" + lien.get_text().strip() + "\"")
#webbrowser.open_new_tab("http://www.youtube.com" + lien["href"])
input("All music downloaded ! Place them in the folder then press enter")
print(("Progression: {: " + str(len(str(len(liste)))) + "d}/{}").format(0,len(liste)), end="\r")
for num, lien in enumerate(liste):
file = EasyID3(join(path,lien.get_text().strip() + ".mp3"))
file["title"] = title.match(lien.get_text().strip()).group().strip()
file["album"] = album
file["date"] = date
file["artist"] = artist
file["tracknumber"] = str(num+1)
file.pprint()
file.save()
print(("Progression: {: " + str(len(str(len(liste)))) + "d}/{}").format(num+1,len(liste)), end="\r")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment