Last active
October 15, 2021 13:03
playmoss playlists to mp3 (✞)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# $ python3 playmoss2mp3.py {playmoss_playlist_url} | |
# ex. | |
# $ python3 playmoss2mp.py https://playmoss.com/en/wideawakening/playlist/2019-wideawakening-legacy | |
# | |
# | |
import requests | |
import youtube_dl | |
import os,sys | |
from bs4 import BeautifulSoup | |
# sysin | |
#url = 'https://playmoss.com/en/wideawakening/playlist/2019-wideawakening-legacy' | |
url = sys.argv[1] | |
album = url.split('/')[-1] | |
# album | |
current = os.getcwd() | |
print("{}/{}".format(current,album)) | |
if not os.path.exists(album): | |
os.makedirs(album) | |
os.chdir(album) | |
# playmoss req | |
page = requests.get(url) | |
soup = BeautifulSoup(page.text,'html.parser') | |
songs = soup.find_all(class_='song-info') | |
# per song download and post-process | |
ydl_options = { | |
'format':'bestaudio/best', | |
'postprocessors':[ | |
{'key': 'FFmpegExtractAudio','preferredcodec': 'mp3','preferredquality': '192'}, | |
{'key': 'FFmpegMetadata'} | |
] | |
} | |
for song in songs: | |
ysong = song.span.a.get('href') | |
print(ysong) | |
try: | |
with youtube_dl.YoutubeDL(ydl_options) as ydl: | |
ydl.download([ysong]) | |
except: | |
print('error in url {}'.format(ysong)) | |
os.chdir(current) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment