Version 2.0.0 - update of everything
This commit is contained in:
85 files changed
+13065
-2107
No files matched your search
@@ -1,25 +1,43 @@
|
||||
const {createAudioResource, VoiceConnectionStatus, createAudioPlayer, StreamType} = require('@discordjs/voice');
|
||||
const {LogType} = require('loguix')
|
||||
const clog = new LogType("Soundcloud-Stream")
|
||||
const {Soundcloud} = require('soundcloud.ts')
|
||||
const ffmpeg = require('fluent-ffmpeg')
|
||||
const { isAllowedUrl } = require('../SongCheck')
|
||||
|
||||
const soundcloud = new Soundcloud();
|
||||
|
||||
async function getStream(song) {
|
||||
try {
|
||||
|
||||
var stream = await soundcloud.util.streamTrack(song.url)
|
||||
return stream
|
||||
|
||||
|
||||
|
||||
} catch(e) {
|
||||
clog.error("Erreur lors de la récupération du stream : " + song.title)
|
||||
clog.error(e)
|
||||
}
|
||||
|
||||
// Le flux SoundCloud est lu depuis le début : le seek n'est pas supporté (le player le refuse)
|
||||
const seekable = false
|
||||
|
||||
/**
|
||||
* @param {Object} song
|
||||
* @param {number} seekSec - ignoré (seek non supporté)
|
||||
* @param {{signal?: AbortSignal}} options
|
||||
* @returns {Promise<import('stream').Readable|null>} le flux, ou null en cas d'échec / d'annulation
|
||||
*/
|
||||
async function getStream(song, seekSec = 0, { signal } = {}) {
|
||||
if(signal?.aborted) return null
|
||||
if(!song || !isAllowedUrl("soundcloud", song.url)) {
|
||||
clog.error("URL SoundCloud refusée : " + JSON.stringify(song?.url))
|
||||
return null
|
||||
}
|
||||
try {
|
||||
const stream = await soundcloud.util.streamTrack(song.url)
|
||||
if(!stream) {
|
||||
clog.error("Aucun flux renvoyé par SoundCloud pour : " + song.title)
|
||||
return null
|
||||
}
|
||||
// Chargement remplacé entre-temps (skip, leave...) : on libère le flux
|
||||
if(signal?.aborted) {
|
||||
stream.destroy?.()
|
||||
return null
|
||||
}
|
||||
signal?.addEventListener('abort', () => stream.destroy?.(), { once: true })
|
||||
return stream
|
||||
} catch(e) {
|
||||
clog.error("Erreur lors de la récupération du stream : " + song.title)
|
||||
clog.error(e)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {getStream}
|
||||
module.exports = {getStream, seekable}
|
||||
Reference in new issue
Block a user