From eff3f8956cdb6b54dcd16085d4c9f8fdbc64f197 Mon Sep 17 00:00:00 2001 From: HugoPoi Date: Sat, 4 Jul 2020 17:40:20 +0200 Subject: [PATCH] feat: spotify html scrape from url --- README.md | 11 +++++------ index.js | 12 +++++++----- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index b34ef62..7e23b98 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/index.js b/index.js index 648295f..6d3a550 100644 --- a/index.js +++ b/index.js @@ -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);