@nechlophomeriaa/spotifydl
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -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 @@ ``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
9764
3
168
76
1
+ Addedaxios@^1.5.0
+ Addedcheerio@^1.0.0-rc.12
+ Addedboolbase@1.0.0(transitive)
+ Addedcheerio@1.0.0(transitive)
+ Addedcheerio-select@2.1.0(transitive)
+ Addedcss-select@5.1.0(transitive)
+ Addedcss-what@6.1.0(transitive)
+ Addeddom-serializer@2.0.0(transitive)
+ Addeddomelementtype@2.3.0(transitive)
+ Addeddomhandler@5.0.3(transitive)
+ Addeddomutils@3.1.0(transitive)
+ Addedencoding-sniffer@0.2.0(transitive)
+ Addedentities@4.5.0(transitive)
+ Addedhtmlparser2@9.1.0(transitive)
+ Addediconv-lite@0.6.3(transitive)
+ Addednth-check@2.1.1(transitive)
+ Addedparse5@7.2.1(transitive)
+ Addedparse5-htmlparser2-tree-adapter@7.1.0(transitive)
+ Addedparse5-parser-stream@7.1.2(transitive)
+ Addedundici@6.21.0(transitive)
+ Addedwhatwg-encoding@3.1.1(transitive)
+ Addedwhatwg-mimetype@4.0.0(transitive)
- Removed@nechlophomeriaa/ytdl@^0.0.6
- Removednode-id3@^0.2.6
- Removedspottydl@^0.2.2
- Removed@biomejs/biome@1.8.3(transitive)
- Removed@biomejs/cli-darwin-arm64@1.8.3(transitive)
- Removed@biomejs/cli-darwin-x64@1.8.3(transitive)
- Removed@biomejs/cli-linux-arm64@1.8.3(transitive)
- Removed@biomejs/cli-linux-arm64-musl@1.8.3(transitive)
- Removed@biomejs/cli-linux-x64@1.8.3(transitive)
- Removed@biomejs/cli-linux-x64-musl@1.8.3(transitive)
- Removed@biomejs/cli-win32-arm64@1.8.3(transitive)
- Removed@biomejs/cli-win32-x64@1.8.3(transitive)
- Removed@nechlophomeriaa/ytdl@0.0.6(transitive)
- Removedasync@0.2.10(transitive)
- Removedfluent-ffmpeg@2.1.3(transitive)
- Removediconv-lite@0.6.2(transitive)
- Removedisexe@2.0.0(transitive)
- Removedm3u8stream@0.8.6(transitive)
- Removedminiget@4.2.3(transitive)
- Removednode-fetch@2.6.6(transitive)
- Removednode-id3@0.2.6(transitive)
- Removedquerystringify@2.2.0(transitive)
- Removedrequires-port@1.0.0(transitive)
- Removedsax@1.4.1(transitive)
- Removedspottydl@0.2.6(transitive)
- Removedtough-cookie@4.1.4(transitive)
- Removedtr46@0.0.3(transitive)
- Removeduniversalify@0.2.0(transitive)
- Removedurl-parse@1.5.10(transitive)
- Removedwebidl-conversions@3.0.1(transitive)
- Removedwhatwg-url@5.0.0(transitive)
- Removedwhich@1.3.1(transitive)
- Removedytdl-core@4.11.5(transitive)
- Removedytmusic-api@5.2.2(transitive)
- Removedzod@3.24.1(transitive)