feat: spotify html scrape from url
This commit is contained in:
parent
f3b80e76fa
commit
eff3f8956c
11
README.md
11
README.md
|
@ -10,12 +10,12 @@ Inspired by [DatMusic](https://github.com/alashow/datmusic-api), [MyFreeMp3](htt
|
||||||
|
|
||||||
*For now*
|
*For now*
|
||||||
|
|
||||||
* Parse a Spotify Playlist page
|
* Scrape Spotify playlist page
|
||||||
* Download a title from the playlist
|
* Download all the titles from MyFreeMp3 aka VK Music
|
||||||
|
* Generate a .m3u8 playlist file
|
||||||
|
|
||||||
*TODO*
|
*TODO*
|
||||||
|
|
||||||
* Download the html spotify page
|
|
||||||
* Dowload all songs in a folder
|
* Dowload all songs in a folder
|
||||||
* Add proper command line options
|
* Add proper command line options
|
||||||
* Document how to get a VK access token (need php and other things this
|
* 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. `git clone THIS`
|
||||||
1. `npm install`
|
1. `npm install`
|
||||||
1. Fill the `.env` with a `ACCESS_TOKEN=` for VK [HowTo](https://github.com/vodka2/vk-audio-token)
|
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. `curl https://open.spotify.com/playlist/6LgeEhc97Azxq6sinJQt6w > test.html`
|
1. `node . https://open.spotify.com/playlist/6LgeEhc97Azxq6sinJQt6w`
|
||||||
1. `node . 0` => Download the first title of the playlist
|
|
||||||
|
|
12
index.js
12
index.js
|
@ -11,8 +11,10 @@ const m3u = require('m3u');
|
||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
|
|
||||||
|
|
||||||
async function getSpotifyPlaylist(){
|
async function getSpotifyPlaylist(playListUrl){
|
||||||
const spotifyPlaylistPageContent = await fs.readFile('./test.html');
|
const spotifyPlaylistPageContent = await fetch(playListUrl)
|
||||||
|
.then(res => res.text())
|
||||||
|
|
||||||
const $ = Cheerio.load(spotifyPlaylistPageContent);
|
const $ = Cheerio.load(spotifyPlaylistPageContent);
|
||||||
|
|
||||||
let playlist;
|
let playlist;
|
||||||
|
@ -81,8 +83,8 @@ async function generateM3U8Playlist(filesWithMetas){
|
||||||
await fs.writeFile(`playlist.m3u8`, m3uWriter.toString());
|
await fs.writeFile(`playlist.m3u8`, m3uWriter.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main(){
|
async function main(playlistUrl){
|
||||||
const playlist = await getSpotifyPlaylist();
|
const playlist = await getSpotifyPlaylist(playlistUrl);
|
||||||
const vkPlaylist = await Promise.map(playlist.tracks.items, async ({track}) => {
|
const vkPlaylist = await Promise.map(playlist.tracks.items, async ({track}) => {
|
||||||
const artistNames = _.map(track.artists, 'name').join(', ');
|
const artistNames = _.map(track.artists, 'name').join(', ');
|
||||||
debug('%s - %s', track.name, artistNames);
|
debug('%s - %s', track.name, artistNames);
|
||||||
|
@ -110,7 +112,7 @@ async function main(){
|
||||||
await generateM3U8Playlist(_.compact(vkPlaylist));
|
await generateM3U8Playlist(_.compact(vkPlaylist));
|
||||||
}
|
}
|
||||||
|
|
||||||
main().catch(err => console.error(err));
|
main(process.argv[2]).catch(err => console.error(err));
|
||||||
|
|
||||||
async function test(query){
|
async function test(query){
|
||||||
const response = await searchOnMyFreeMp3(query);
|
const response = await searchOnMyFreeMp3(query);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user