feat: spotify html scrape from url

This commit is contained in:
HugoPoi 2020-07-04 17:40:20 +02:00
parent f3b80e76fa
commit eff3f8956c
2 changed files with 12 additions and 11 deletions

View File

@ -10,12 +10,12 @@ Inspired by [DatMusic](https://github.com/alashow/datmusic-api), [MyFreeMp3](htt
*For now*
* Parse a Spotify Playlist page
* Download a title from the playlist
* Scrape Spotify playlist page
* Download all the titles from MyFreeMp3 aka VK Music
* Generate a .m3u8 playlist file
*TODO*
* Download the html spotify page
* Dowload all songs in a folder
* Add proper command line options
* Document how to get a VK access token (need php and other things this
@ -38,6 +38,5 @@ BEWARE WIP
1. `git clone THIS`
1. `npm install`
1. Fill the `.env` with a `ACCESS_TOKEN=` for VK [HowTo](https://github.com/vodka2/vk-audio-token)
1. `curl https://open.spotify.com/playlist/6LgeEhc97Azxq6sinJQt6w > test.html`
1. `node . 0` => Download the first title of the playlist
1. (Optional) Only for direct VK search, fill the `.env` with a `ACCESS_TOKEN=` for VK [HowTo](https://github.com/vodka2/vk-audio-token)
1. `node . https://open.spotify.com/playlist/6LgeEhc97Azxq6sinJQt6w`

View File

@ -11,8 +11,10 @@ const m3u = require('m3u');
require('dotenv').config();
async function getSpotifyPlaylist(){
const spotifyPlaylistPageContent = await fs.readFile('./test.html');
async function getSpotifyPlaylist(playListUrl){
const spotifyPlaylistPageContent = await fetch(playListUrl)
.then(res => res.text())
const $ = Cheerio.load(spotifyPlaylistPageContent);
let playlist;
@ -81,8 +83,8 @@ async function generateM3U8Playlist(filesWithMetas){
await fs.writeFile(`playlist.m3u8`, m3uWriter.toString());
}
async function main(){
const playlist = await getSpotifyPlaylist();
async function main(playlistUrl){
const playlist = await getSpotifyPlaylist(playlistUrl);
const vkPlaylist = await Promise.map(playlist.tracks.items, async ({track}) => {
const artistNames = _.map(track.artists, 'name').join(', ');
debug('%s - %s', track.name, artistNames);
@ -110,7 +112,7 @@ async function main(){
await generateM3U8Playlist(_.compact(vkPlaylist));
}
main().catch(err => console.error(err));
main(process.argv[2]).catch(err => console.error(err));
async function test(query){
const response = await searchOnMyFreeMp3(query);