Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

spotify-url-info

Package Overview
Dependencies
Maintainers
2
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

spotify-url-info - npm Package Compare versions

Comparing version 3.2.5 to 3.2.6

13

package.json

@@ -5,3 +5,3 @@ {

"homepage": "https://github.com/microlinkhq/spotify-url-info",
"version": "3.2.5",
"version": "3.2.6",
"main": "src/index.js",

@@ -63,3 +63,3 @@ "author": {

"himalaya": "~1.1.0",
"spotify-uri": "~3.0.3"
"spotify-uri": "~4.0.0"
},

@@ -69,2 +69,3 @@ "devDependencies": {

"@commitlint/config-conventional": "latest",
"@ksmithut/prettier-standard": "latest",
"ava": "latest",

@@ -77,5 +78,6 @@ "c8": "latest",

"isomorphic-unfetch": "latest",
"lodash": "latest",
"map-values-deep": "latest",
"nano-staged": "latest",
"npm-check-updates": "latest",
"prettier-standard": "latest",
"simple-git-hooks": "latest",

@@ -117,4 +119,5 @@ "standard": "latest",

"nano-staged": {
"*.js": [
"prettier-standard"
"*.js,!*.min.js,": [
"prettier-standard",
"standard --fix"
],

@@ -121,0 +124,0 @@ "*.md": [

@@ -21,2 +21,4 @@ 'use strict'

const SUPPORTED_TYPES = Object.values(TYPE)
const throwError = message => {

@@ -26,14 +28,6 @@ throw new TypeError(`${message}\n${ERROR.REPORT}`)

const SUPPORTED_TYPES = Object.values(TYPE)
const parseData = html => {
const embed = parse(html)
const createGetData = fetch => async (url, opts) => {
const parsedUrl = getParsedUrl(url)
const embedURL = spotifyURI.formatEmbedURL(parsedUrl)
const response = await fetch(embedURL, opts)
const text = await response.text()
const embed = parse(text)
let scripts = embed.find(el => el.tagName === 'html')
if (scripts === undefined) return throwError(ERROR.NOT_SCRIPTS)

@@ -50,3 +44,2 @@

if (script !== undefined) {
// found data in the older embed style
return normalizeData({

@@ -62,3 +55,2 @@ data: JSON.parse(Buffer.from(script.children[0].content, 'base64'))

if (script !== undefined) {
// found data in the new embed style
const data = JSON.parse(Buffer.from(script.children[0].content, 'base64'))

@@ -69,5 +61,23 @@ .data.entity

script = scripts.find(script =>
script.attributes.some(({ value }) => value === '__NEXT_DATA__')
)
if (script !== undefined) {
const string = Buffer.from(script.children[0].content)
const data = JSON.parse(string).props.pageProps.state?.data.entity
if (data !== undefined) return normalizeData({ data })
}
return throwError(ERROR.NOT_DATA)
}
const createGetData = fetch => async (url, opts) => {
const parsedUrl = getParsedUrl(url)
const embedURL = spotifyURI.formatEmbedURL(parsedUrl)
const response = await fetch(embedURL, opts)
const text = await response.text()
return parseData(text)
}
function getParsedUrl (url) {

@@ -134,3 +144,3 @@ try {

function normalizeData ({ data }) {
const normalizeData = ({ data }) => {
if (!data || !data.type || !data.name) {

@@ -151,3 +161,3 @@ throw new Error("Data doesn't seem to be of the right shape to parse")

function spotifyUrlInfo (fetch) {
module.exports = fetch => {
const getData = createGetData(fetch)

@@ -167,2 +177,2 @@ return {

module.exports = spotifyUrlInfo
module.exports.parseData = parseData
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc