-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix(Track): avoid fetching thumbnail on initialisation, thumbnail rate limit - bump deps. * fix(Track): correct the this context * add test file * feat(Track): cache thumbnail if it exist * feat(Track): avoid fetching thumbnail each call, cache it * refactor: 🎨 Enforce NAME/Version Format For Client-Name Header * refactor: collections/maps This commit refactors the discord.js collections used in Riffy, replacing it with Node.js/V8 Map. * fix: 🐛 Fixes the cacheThumbnail property that was not working * Corrects The format issue in author property package.json, Replaced it with contributors field. * Sets the correct condition for player#destroy * Fixed clearFilters() and added API to fetch songs for autoplay * fix(Track): clubs non-track result/response in tracks and throws Error in v4 Lavalink * Updated some test commands * Update Types * fix: node regions support feat: exception object in resolve method and types fix: leastUsedNodes sorting * fix(Riffy): missing 'tracks' in resolve track method's response This commit adds the 'tracks' that was accidentally removed and updates types * feat(riffy): add 'node' property in resolve method, for accurate selection of the node * fix: Riffy resolve 'node' property error, fix: headers not getting show in debug, update: 'nodes' types. * Fix: [Better Handle No-Audio] Set Player#connected to `true` after Voice state & Server event is Received * refactor: Connection & Player Debug Messages * Fix(Rest): return promises with await * feat(Node): Version Checks & Bump pkgs(deps) * feat(Node) Adds Version checks * bump deps * feat `includeHeaders` in rest makeRequest --------- Co-authored-by: ThePedroo <[email protected]> Co-authored-by: FlameFace <[email protected]>
- Loading branch information
1 parent
56f40cf
commit f53fbf0
Showing
15 changed files
with
1,228 additions
and
1,033 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,49 @@ | ||
const undici = require('undici'); | ||
const { JSDOM } = require('jsdom'); | ||
|
||
async function scAutoPlay(url) { | ||
const res = await undici.fetch(`${url}/recommended`); | ||
|
||
if (res.status !== 200) { | ||
throw new Error(`Failed to fetch URL. Status code: ${res.status}`); | ||
} | ||
|
||
const html = await res.text(); | ||
|
||
const dom = new JSDOM(html); | ||
const document = dom.window.document; | ||
|
||
const secondNoscript = document.querySelectorAll('noscript')[1]; | ||
const sectionElement = secondNoscript.querySelector('section'); | ||
const articleElements = sectionElement.querySelectorAll('article'); | ||
/** | ||
* | ||
* @param {string} url soundcloud song url without parameters | ||
* @returns | ||
*/ | ||
|
||
async function soundcloud(url) { | ||
const res = await undici.fetch(`https://riffy.unburn.tech/api/soundcloud`, { | ||
method: "POST", | ||
body: JSON.stringify({ | ||
"url": url | ||
}) | ||
}); | ||
|
||
articleElements.forEach(articleElement => { | ||
const h2Element = articleElement.querySelector('h2[itemprop="name"]'); | ||
const output = await res.json(); | ||
|
||
const aElement = h2Element.querySelector('a[itemprop="url"]'); | ||
const href = `https://soundcloud.com${aElement.getAttribute('href')}` | ||
if (output.status !== 200) { | ||
throw new Error(`Failed to fetch URL. Status code: ${output.status}`); | ||
} | ||
|
||
return href; | ||
}); | ||
return output; | ||
} | ||
|
||
async function spAutoPlay(track_id) { | ||
const data = await undici.fetch("https://open.spotify.com/get_access_token?reason=transport&productType=embed"); | ||
|
||
const body = await data.json(); | ||
/** | ||
* | ||
* @param {string} track_id spotify song track id | ||
* @returns | ||
*/ | ||
|
||
async function spotify(track_id) { | ||
const res = await undici.fetch(`https://riffy.unburn.tech/api/spotify`, { | ||
method: "POST", | ||
body: JSON.stringify({ | ||
"track_id": track_id | ||
}) | ||
}); | ||
|
||
const res = await undici.fetch(`https://api.spotify.com/v1/recommendations?limit=10&seed_tracks=${track_id}`, { | ||
headers: { | ||
Authorization: `Bearer ${body.accessToken}`, | ||
'Content-Type': 'application/json', | ||
}, | ||
}) | ||
const output = await res.json(); | ||
|
||
const json = await res.json(); | ||
if (output.status !== 200) { | ||
throw new Error(`Failed to fetch URL. Status code: ${output.status}`); | ||
} | ||
|
||
return json.tracks[Math.floor(Math.random() * json.tracks.length)].id | ||
return output; | ||
} | ||
|
||
module.exports = { scAutoPlay, spAutoPlay }; | ||
module.exports = { soundcloud, spotify }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.