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

@nechlophomeriaa/spotifydl

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nechlophomeriaa/spotifydl - npm Package Compare versions

Comparing version 1.0.7 to 1.0.8

.prettierignore

30

function/index.js
function isUrl(url) {
return url.match(
new RegExp(
/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&/=]*)/gi
)
);
return url.match(new RegExp(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&/=]*)/gi))
}

@@ -17,19 +13,19 @@

description: "Front cover",
imageBuffer: image,
imageBuffer: image
},
track: track,
};
return result;
track: track
}
return result
}
function convertMs(duration) {
seconds = parseInt((duration/1000)%60)
minutes = parseInt((duration/(1000*60))%60)
hours = parseInt((duration/(1000*60*60))%24);
hours = (hours < 10) ? "0" + hours : hours;
minutes = (minutes < 10) ? "0" + minutes : minutes;
seconds = (seconds < 10) ? "0" + seconds : seconds;
return hours + ":" + minutes + ":" + seconds;
seconds = parseInt((duration / 1000) % 60)
minutes = parseInt((duration / (1000 * 60)) % 60)
hours = parseInt((duration / (1000 * 60 * 60)) % 24)
hours = hours < 10 ? "0" + hours : hours
minutes = minutes < 10 ? "0" + minutes : minutes
seconds = seconds < 10 ? "0" + seconds : seconds
return hours + ":" + minutes + ":" + seconds
}
module.exports = { isUrl, tags, convertMs };
module.exports = { isUrl, tags, convertMs }

@@ -1,54 +0,41 @@

const { isUrl, tags, convertMs } = require("./function");
const axios = require("axios");
const cheerio = require("cheerio");
const fetch = require("node-fetch");
const spot = require("spotify-finder");
const { isUrl, tags, convertMs } = require("./function")
const axios = require("axios")
const cheerio = require("cheerio")
const fetch = require("node-fetch")
const spot = require("spotify-finder")
const spotify = new spot({
consumer: {
key: "9e1c5e192a8141c59b7e91f2848e6a9c",
secret: "78e2ece45fa446c98517d2cbb3271486",
},
});
secret: "78e2ece45fa446c98517d2cbb3271486"
}
})
const options = {
headers: {
Origin: "https://spotifydown.com",
Referer: "https://spotifydown.com/",
},
};
Referer: "https://spotifydown.com/"
}
}
async function getOriginalUrl(url) {
const data = await fetch(url);
return data.url;
const data = await fetch(url)
return data.url
}
async function downloads(url) {
if (!isUrl(url)) throw new Error("Please input Url");
if (!isUrl(url)) throw new Error("Please input Url")
if (url.includes("spotify.link")) {
const originalUrl = await getOriginalUrl(url);
const track = await axios.get(
`https://api.spotifydown.com/metadata/track/${
originalUrl.split("track/")[1].split("?")[0]
}`,
options
);
const { data } = await axios.get(
`https://api.spotifydown.com/download/${track.data.id}`,
options
);
return data;
const originalUrl = await getOriginalUrl(url)
const track = await axios.get(`https://api.spotifydown.com/metadata/track/${originalUrl.split("track/")[1].split("?")[0]}`, options)
const { data } = await axios.get(`https://api.spotifydown.com/download/${track.data.id}`, options)
return data
} else if (url.includes("open.spotify.com")) {
const { data } = await axios.get(
`https://api.spotifydown.com/download/${
url.split("track/")[1].split("?")[0]
}`,
options
);
return data;
const { data } = await axios.get(`https://api.spotifydown.com/download/${url.split("track/")[1].split("?")[0]}`, options)
return data
} else {
const result = {
status: false,
message: "Please input valid spotify url",
};
console.log(result);
return result;
message: "Please input valid spotify url"
}
console.log(result)
return result
}

@@ -58,85 +45,55 @@ }

async function search(query, limit) {
if (isUrl(query)) throw new Error("Search function not support for url");
const limits = limit ? limit : 1;
const data = await spotify.search({ q: query, type: "track", limit: limits });
return data.tracks;
if (isUrl(query)) throw new Error("Search function not support for url")
const limits = limit ? limit : 1
const data = await spotify.search({ q: query, type: "track", limit: limits })
return data.tracks
}
async function downloadAlbum(url) {
let result = { type: null, metadata: {}, trackList: [] };
if (!isUrl(url)) throw new Error("Input Url");
let result = { type: null, metadata: {}, trackList: [] }
if (!isUrl(url)) throw new Error("Input Url")
try {
if (url.includes("spotify.link")) {
const getOrigin = await getOriginalUrl(url);
if (!getOrigin.includes("album/") && !getOrigin.includes("playlist/"))
throw new Error("Invalid album/playlist url");
const getOrigin = await getOriginalUrl(url)
if (!getOrigin.includes("album/") && !getOrigin.includes("playlist/")) throw new Error("Invalid album/playlist url")
if (getOrigin.includes("album/")) {
var inputData = "album/";
var inputData = "album/"
} else {
var inputData = "playlist/";
var inputData = "playlist/"
}
const metaData = await axios.get(
`https://api.spotifydown.com/metadata/${inputData}${
getOrigin.split(inputData)[1].split("?")[0]
}`,
options
);
result.type = inputData.split("/")[0];
result.metadata = metaData.data;
const { data } = await axios.get(
`https://api.spotifydown.com/trackList/${inputData}${
getOrigin.split(inputData)[1].split("?")[0]
}`,
options
);
console.log(`Downloading audio...`);
console.log(
"Please wait for a moment, this process will take for a couple minutes"
);
const metaData = await axios.get(`https://api.spotifydown.com/metadata/${inputData}${getOrigin.split(inputData)[1].split("?")[0]}`, options)
result.type = inputData.split("/")[0]
result.metadata = metaData.data
const { data } = await axios.get(`https://api.spotifydown.com/trackList/${inputData}${getOrigin.split(inputData)[1].split("?")[0]}`, options)
console.log(`Downloading audio...`)
console.log("Please wait for a moment, this process will take for a couple minutes")
for (let i = 0; i < data.trackList.length; i++) {
const downloading = await downloads(
`https://open.spotify.com/track/${data.trackList[i].id}`
);
result.trackList.push(downloading);
const downloading = await downloads(`https://open.spotify.com/track/${data.trackList[i].id}`)
result.trackList.push(downloading)
}
return result;
return result
} else if (url.includes("open.spotify.com")) {
if (!url.includes("album/") && !url.includes("playlist/"))
throw new Error("Invalid album/playlist url");
if (!url.includes("album/") && !url.includes("playlist/")) throw new Error("Invalid album/playlist url")
if (url.includes("album/")) {
var inputData = "album/";
var inputData = "album/"
} else {
var inputData = "playlist/";
var inputData = "playlist/"
}
const metaData = await axios.get(
`https://api.spotifydown.com/metadata/${inputData}${
url.split(inputData)[1].split("?")[0]
}`,
options
);
result.type = inputData.split("/")[0];
result.metadata = metaData.data;
const { data } = await axios.get(
`https://api.spotifydown.com/trackList/${inputData}${
url.split(inputData)[1].split("?")[0]
}`,
options
);
console.log("Downloading audio...");
console.log(
"Please wait for a moment, this process will take for a couple minutes"
);
const metaData = await axios.get(`https://api.spotifydown.com/metadata/${inputData}${url.split(inputData)[1].split("?")[0]}`, options)
result.type = inputData.split("/")[0]
result.metadata = metaData.data
const { data } = await axios.get(`https://api.spotifydown.com/trackList/${inputData}${url.split(inputData)[1].split("?")[0]}`, options)
console.log("Downloading audio...")
console.log("Please wait for a moment, this process will take for a couple minutes")
for (let i = 0; i < data.trackList.length; i++) {
const downloading = await downloads(
`https://open.spotify.com/track/${data.trackList[i].id}`
);
result.trackList.push(downloading);
const downloading = await downloads(`https://open.spotify.com/track/${data.trackList[i].id}`)
result.trackList.push(downloading)
}
return result;
return result
} else {
throw new Error("Invalid Url!");
throw new Error("Invalid Url!")
}
} catch (err) {
console.log(err);
return String(err);
console.log(err)
return String(err)
}

@@ -146,16 +103,12 @@ }

async function downloadTrack(song) {
let result = {};
let result = {}
if (isUrl(song)) {
try {
if (song.includes("spotify.link")) {
const getOrigin = await getOriginalUrl(song);
var tracks = await spotify.getTrack(
getOrigin.split("track/")[1].split("?")[0]
);
const getOrigin = await getOriginalUrl(song)
var tracks = await spotify.getTrack(getOrigin.split("track/")[1].split("?")[0])
} else {
var tracks = await spotify.getTrack(
song.split("track/")[1].split("?")[0]
);
var tracks = await spotify.getTrack(song.split("track/")[1].split("?")[0])
}
const downloadData = await downloads(song);
const downloadData = await downloads(song)
result = {

@@ -173,22 +126,20 @@ status: true,

tracks: tracks.album.total_tracks,
releasedDate: tracks.album.release_date,
releasedDate: tracks.album.release_date
},
imageUrl: tracks.album.images[0].url,
audioUrl: downloadData.link,
};
return result;
audioUrl: downloadData.link
}
return result
} catch (err) {
result = {
status: false,
message: "Unknown error occurred!\n\n" + String(err),
};
console.log(result);
return result;
message: "Unknown error occurred!\n\n" + String(err)
}
console.log(result)
return result
}
} else {
try {
const searchTrack = await search(song, 1);
const downloadData = await downloads(
searchTrack.items[0].external_urls.spotify
);
const searchTrack = await search(song, 1)
const downloadData = await downloads(searchTrack.items[0].external_urls.spotify)
result = {

@@ -206,15 +157,15 @@ status: true,

tracks: searchTrack.items[0].album.total_tracks,
releasedDate: searchTrack.items[0].album.release_date,
releasedDate: searchTrack.items[0].album.release_date
},
imageUrl: downloadData.metadata.cover,
audioUrl: downloadData.link,
};
return result;
audioUrl: downloadData.link
}
return result
} catch (err) {
result = {
status: false,
message: "Unknown error occurred!\n\n" + String(err),
};
console.log(result);
return result;
message: "Unknown error occurred!\n\n" + String(err)
}
console.log(result)
return result
}

@@ -229,3 +180,3 @@ }

downloadTrack,
downloads,
};
downloads
}

@@ -9,7 +9,9 @@ {

"name": "@nechlophomeriaa/spotifydl",
"description": "Spotify Downloader with metadata using Node-ID3",
"version": "1.0.7",
"description": "Simple Scraper Spotify Track/Album/Playlist Downloader with Metadata",
"version": "1.0.8",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js",
"format": "prettier --write '**/*.{md,js,json}'"
},

@@ -16,0 +18,0 @@ "repository": {

@@ -1,2 +0,11 @@

# Usage
<p>Simple Scraper Spotify Downloader from <a href ="https://spotifydown.com/id">SpotifyDown</a></p>
## Installation
```sh
> npm i @nechlophomeriaa/spotifydl
```
## Usage
```js

@@ -7,8 +16,9 @@ const { search, downloadTrack, downloadAlbum, downloads, getOriginalUrl } = require("@nechlophomeriaa/spotifydl")

## Search Function
```js
(async () => {
const searchTrack = await search(query, limit) //
console.log(searchTrack)
// Promise will be return an Array
})
;async () => {
const searchTrack = await search(query, limit) //
console.log(searchTrack)
// Promise will be return an Array
}

@@ -28,8 +38,9 @@ /*

## Download Single Track Function
```js
// Input Metadata: ✅
(async () => {
const downTrack = await downloadTrack(song) // query || url
console.log(downTrack)
})
;async () => {
const downTrack = await downloadTrack(song) // query || url
console.log(downTrack)
}
/*

@@ -61,9 +72,10 @@ Example Output: {

## Download Albums Function
```js
// Supports: Album/Playlist
// Input Metadata: ✅
(async () => {
const downAlbums = await downloadAlbum(url)
console.log(downAlbums)
})
;async () => {
const downAlbums = await downloadAlbum(url)
console.log(downAlbums)
}
/*

@@ -115,4 +127,2 @@ Example Output: {

If there is bug/error please make an issue!
<p align="center">If there is bug/error please make an issue!</p>
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