mirror of
https://github.com/eRgo35/spotify-parser.git
synced 2025-12-16 21:06:11 +01:00
inital commit
This commit is contained in:
29
index.js
Normal file
29
index.js
Normal file
@@ -0,0 +1,29 @@
|
||||
const fetch = require('isomorphic-unfetch')
|
||||
const Spotify = require("spotify-url-info")
|
||||
const {getData, getPreview} = Spotify(fetch)
|
||||
|
||||
let spotufy_regex = /https?:\/\/(?:embed\.|open\.)(?:spotify\.com\/)(?:track\/|\?uri=spotify:track:)((\w|-)+)(?:(?=\?)(?:[?&]foo=(\d*)(?=[&#]|$)|(?![?&]foo=)[^#])+)?(?=#|$)/
|
||||
let isUrl = false
|
||||
let url = ""
|
||||
|
||||
process.argv.forEach(val => {
|
||||
if (isUrl) {
|
||||
url = val
|
||||
}
|
||||
if (val == "--url") {
|
||||
isUrl = true
|
||||
}
|
||||
})
|
||||
|
||||
let spotifyLink = spotufy_regex.test(url)
|
||||
if (!spotifyLink) {
|
||||
console.error("invalid url")
|
||||
return
|
||||
}
|
||||
|
||||
const parser = async () => {
|
||||
let spotifyResult = await getPreview(url)
|
||||
console.log(spotifyResult.artist, " - ", spotifyResult.title)
|
||||
}
|
||||
|
||||
parser()
|
||||
Reference in New Issue
Block a user