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 0.0.4 to 0.0.5

12

function/index.js

@@ -24,2 +24,12 @@ function isUrl(url) {

module.exports = { isUrl, tags };
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;
}
module.exports = { isUrl, tags, convertMs };

197

index.js

@@ -1,4 +0,6 @@

const id3 = require("node-id3");
const { ytmp3 } = require("@nechlophomeriaa/ytdl");
const { isUrl, tags } = require("./function");
const { isUrl, tags, convertMs } = require("./function");
const axios = require("axios");
const cheerio = require("cheerio");
const formData = require("form-data")
const bodyForm = new formData()
const spot = require("spotify-finder");

@@ -11,7 +13,49 @@ const spotify = new spot({

});
const { getTrack } = require("spottydl");
const fetch = require("node-fetch");
async function downloads(url) {
try {
const getValue = async () => {
const data = await axios.get("https://spotifymate.com/")
const $ = cheerio.load(data.data)
const name = $("#get_video > input[type=hidden]:nth-child(4)").attr("name")
const val = $("#get_video > input[type=hidden]:nth-child(4)").val()
const cookie = data.headers['set-cookie'][0].split(";")[0]
const result = {
cookie: cookie,
name: name,
value: val
}
return result
}
const dataValue = await getValue()
bodyForm.append("url", url)
bodyForm.append(dataValue.name, dataValue.value)
const { data } = await axios("https://spotifymate.com/action", {
method: "POST",
data: bodyForm,
headers: {
"cookie": dataValue.cookie
}
})
const $ = cheerio.load(data)
const result = {
status: true,
title: $("div.row > div > div:nth-child(1) > div:nth-child(2) > div > h3 > div").text(),
artists: $("div.row > div > div:nth-child(1) > div:nth-child(2) > p").text(),
image: $("div.row > div > div:nth-child(1) > div:nth-child(1) > img").attr("src"),
url: $("div.row > div > #download-block > div:nth-child(1) > a").attr("href")
}
return result
} catch (err) {
const result = {
status: false,
message: "Unknown error occurred.\n\n" + String(err)
}
console.log(result)
return result
}
}
async function search(query, limit) {
if (isUrl(query)) throw new Error("search function not support for url");
if (isUrl(query)) throw new Error("Search function not support for url");
const limits = limit ? limit : 1;

@@ -23,84 +67,72 @@ const data = await spotify.search({ q: query, type: "track", limit: limits });

async function downloadTrack(song) {
let result = {}
if (isUrl(song)) {
try {
const tracks = await spotify.getTrack(
song.split("track/")[1].split("?")[0]
);
const tracks2 = await getTrack(song);
const bufferImage = await fetch(tracks.album.images[0].url).then((res) =>
res.buffer()
);
const audio = await ytmp3(`https://youtu.be/${tracks2.id}`);
const fetchAudio = await fetch(audio.url).then((res) => res.buffer());
let tagger = tags(
tracks2.title,
tracks2.artist,
tracks2.year,
tracks2.album,
bufferImage,
tracks2.trackNumber
);
const nodeID3 = await id3.write(tagger, fetchAudio);
const result = {
status: true,
title: tracks2.title,
artist: tracks2.artist,
uploadDate: tracks2.year,
album: tracks2.album,
size: audio.size,
duration: audio.duration,
thumbnail: tracks.album.images[0].url,
audioBuffer: nodeID3,
};
return result;
if (song.includes("spotify.link")) {
const tracks = await downloads(song)
return tracks
}
if (song.includes("open.spotify.com")) {
const tracks = await spotify.getTrack(song.split("track/")[1].split("?")[0])
const downloadData = await downloads(song)
result = {
status: true,
title: tracks.name,
artists: tracks.artists.map(art => art.name).join(", "),
duration: convertMs(tracks.duration_ms),
explicit: tracks.explicit,
popularity: tracks.popularity,
url: tracks.external_urls.spotify,
album: {
name: tracks.album.name,
type: tracks.album.album_type,
tracks: tracks.album.total_tracks,
releasedDate: tracks.album.release_date
},
imageUrl: downloadData.image,
downloadAudio: downloadData.url
}
return result
}
} catch (err) {
const result = {
result = {
status: false,
message: `Unknown error occurred\n\n${String(err)}`,
};
console.log(err);
return result;
statusCode: err.response.body.error.status,
message: err.response.body.error.message
}
console.log(result)
return result
}
} else {
try {
const searchTrack = await search(song, 1)
const downloadData = await downloads(searchTrack.items[0].external_urls.spotify)
result = {
status: true,
title: searchTrack.items[0].name,
artists: searchTrack.items[0].artists.map(art => art.name).join(", "),
duration: convertMs(searchTrack.items[0].duration_ms),
explicit: searchTrack.items[0].explicit,
popularity: searchTrack.items[0].popularity,
url: searchTrack.items[0].external_urls.spotify,
album: {
name: searchTrack.items[0].album.name,
type: searchTrack.items[0].album.album_type,
tracks: searchTrack.items[0].album.total_tracks,
releasedDate: searchTrack.items[0].album.release_date
},
imageUrl: downloadData.image,
downloadAudio: downloadData.url
}
return result
} catch (err) {
result = {
status: false,
message: "Unknown error occurred!"
}
console.log(result)
return result
}
}
} else {
try {
const findTracks = await search(song, 1);
const getTrackInfo = await getTrack(
findTracks.items[0].external_urls.spotify
);
const bufferImage = await fetch(
findTracks.items[0].album.images[0].url
).then((res) => res.buffer());
const audio = await ytmp3(`https://youtu.be/${getTrackInfo.id}`);
const fetchAudio = await fetch(audio.url).then((res) => res.buffer());
const tagger = tags(
getTrackInfo.title,
getTrackInfo.artist,
getTrackInfo.year,
getTrackInfo.album,
bufferImage,
getTrackInfo.trackNumber
);
const nodeID3 = await id3.write(tagger, fetchAudio);
const result = {
status: true,
title: getTrackInfo.title,
artist: getTrackInfo.artist,
uploadDate: getTrackInfo.year,
album: getTrackInfo.album,
size: audio.size,
duration: audio.duration,
thumbnail: findTracks.items[0].album.images[0].url,
audioBuffer: nodeID3,
};
return result;
} catch (err) {
const result = {
status: false,
message: `Unknown error occurred\n\n${String(err)}`,
};
console.log(err);
return result;
}
}
}

@@ -110,2 +142,3 @@ module.exports = {

downloadTrack,
downloads
};
{
"dependencies": {
"@nechlophomeriaa/ytdl": "^0.0.6",
"node-id3": "^0.2.6",
"spotify-finder": "^2.1.1",
"spottydl": "^0.2.2"
"axios": "^1.5.0",
"cheerio": "^1.0.0-rc.12",
"spotify-finder": "^2.1.1"
},
"name": "@nechlophomeriaa/spotifydl",
"description": "Spotify Downloader with metadata using Node-ID3",
"version": "0.0.4",
"version": "0.0.5",
"main": "index.js",
"devDependencies": {},
"scripts": {

@@ -14,0 +12,0 @@ "test": "echo \"Error: no test specified\" && exit 1"

@@ -31,15 +31,41 @@ # Usage

/*
Example Output:
Example Output: {
if url includes https://spotify.link:
{
status: true,
title: 'Be More',
artist: 'Stephen Sanchez',
uploadDate: '2023-8-3',
album: 'Be More',
size: '3.6 MB',
duration: '00:03:52',
thumbnail: 'https://i.scdn.co/image/ab67616d0000b273d8623313343c12b4b46f8235',
audioBuffer: <Buffer 49 44 33 03 00 00 00 09 08 29 54 49 54 32 00 00 00 11 00 00 01 ff fe 42 00 65 00 20 00 4d 00 6f 00 72 00 65 00 54 50 45 31 00 00 00 21 00 00 01 ff fe ... 3857031 more bytes>
title: 'So Long',
artists: 'Steady Holiday',
image: 'https://i.scdn.co/image/ab67616d0000b273d52195651e47f1b443e90429',
url: 'https://dl.spotifymate.com/mdelta.123tokyo.xyz/get.php/2/91/nyp_Tnbgfdo.
mp3?cid=MmEwMTo0Zjg6YzAxMjozOWJlOjoxfE5BfERF&h=WH8FX1im9OjJQfXr4Weckw&s=16951869
70&n=SpotifyMate.com%20-%20So%20Long%20-%20Steady%20Holiday&cid2=ODEuMTcxLjI5LjE
2fE5MfFJJQUU3QzMwMTc5MkE4Mjgw&fn=1'
}
if url includes open.spotify.com || with query:
{
status: true,
title: 'Teenage Blue',
artists: 'Dreamgirl',
duration: '00:03:54',
explicit: false,
popularity: 62,
url: 'https://open.spotify.com/track/6oWXWkwHKREYlBNuBCitFP',
album: {
name: 'Illuminaughty',
type: 'single',
tracks: 6,
releasedDate: '2015-02-14'
},
imageUrl: 'https://i.scdn.co/image/ab67616d0000b27377cbc6b59d5190717afa04aa',
downloadAudio: 'https://dl.spotifymate.com/mbeta.123tokyo.xyz/get.php/7/a1/JVD
mY_riDsc.mp3?cid=MmEwMTo0Zjg6YzAxMjozOWJlOjoxfE5BfERF&h=vcJatNsMz0NedmZOLxFnWA&s
=1695187304&n=SpotifyMate.com%20-%20Teenage%20Blue%20-%20Dreamgirl&cid2=ODEuMTcx
LjI5LjE2fE5MfFJJQUU3QzMwMTc5MkE4Mjgw&fn=1'
}
}
*/

@@ -46,0 +72,0 @@ ```

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