Version 1.3.0-rc1 - Modification de la methode ; Error
This commit is contained in:
@@ -1,86 +0,0 @@
|
|||||||
name: Deployment Pipeline
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
deploy:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: Setup SSH
|
|
||||||
env:
|
|
||||||
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
|
||||||
run: |
|
|
||||||
mkdir -p ~/.ssh
|
|
||||||
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
|
|
||||||
chmod 600 ~/.ssh/id_rsa
|
|
||||||
eval "$(ssh-agent -s)"
|
|
||||||
ssh-add ~/.ssh/id_rsa
|
|
||||||
ssh-keyscan git.raphix.fr >> ~/.ssh/known_hosts
|
|
||||||
|
|
||||||
- name: Deploy Subsonics as gitlab-ci
|
|
||||||
run: |
|
|
||||||
ssh -A -o StrictHostKeyChecking=no raphix@alpha.raphix.fr << 'EOF'
|
|
||||||
sudo su - gitlab-ci -c '
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# Variables PM2 et npm
|
|
||||||
export PM2_HOME=/home/gitlab-ci/.pm2
|
|
||||||
export NPM_CONFIG_CACHE=/home/gitlab-ci/.npm
|
|
||||||
|
|
||||||
mkdir -p $PM2_HOME $NPM_CONFIG_CACHE
|
|
||||||
chown -R gitlab-ci:gitlab-ci $PM2_HOME $NPM_CONFIG_CACHE
|
|
||||||
|
|
||||||
echo "[Subsonics-Deploy] - Stage - Déploiement - START"
|
|
||||||
|
|
||||||
echo "[Subsonics-Deploy] - Arrêt de Subsonics : Processing"
|
|
||||||
cd /home/gitlab-ci
|
|
||||||
pm2 stop "Subsonics - Backend" || true
|
|
||||||
pm2 delete "Subsonics - Backend" || true
|
|
||||||
echo "[Subsonics-Deploy] - Arrêt de Subsonics : Success"
|
|
||||||
|
|
||||||
# Préparer tempdata
|
|
||||||
if [ ! -d "/home/gitlab-ci/backend/data" ]; then
|
|
||||||
mkdir -p /home/gitlab-ci/backend/data
|
|
||||||
fi
|
|
||||||
mv /home/gitlab-ci/backend/data/ /home/gitlab-ci/tempdata || true
|
|
||||||
|
|
||||||
echo "[Subsonics-Deploy] - Suppression de Subsonics : Processing"
|
|
||||||
rm -rf ./backend
|
|
||||||
echo "[Subsonics-Deploy] - Suppression de Subsonics : Success"
|
|
||||||
|
|
||||||
echo "[Subsonics-Deploy] - Installation de Subsonics : Processing"
|
|
||||||
git clone https://git.raphix.fr/subsonics/chopin backend
|
|
||||||
echo "[Subsonics-Deploy] - Installation de Subsonics : Success"
|
|
||||||
|
|
||||||
echo "[Subsonics-Deploy] - Installation des dépendances : Processing"
|
|
||||||
cd /home/gitlab-ci/backend
|
|
||||||
|
|
||||||
# Nettoyage node_modules et tempdata
|
|
||||||
rm -rf node_modules
|
|
||||||
if [ -d "/home/gitlab-ci/tempdata" ]; then
|
|
||||||
mv /home/gitlab-ci/tempdata/ ./data
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Assurer la propriété gitlab-ci
|
|
||||||
chown -R gitlab-ci:gitlab-ci /home/gitlab-ci/backend
|
|
||||||
mkdir -p $NPM_CONFIG_CACHE
|
|
||||||
chown -R gitlab-ci:gitlab-ci $NPM_CONFIG_CACHE
|
|
||||||
|
|
||||||
npm install --omit=dev
|
|
||||||
echo "[Subsonics-Deploy] - Installation des dépendances : Success"
|
|
||||||
|
|
||||||
echo "[Subsonics-Deploy] - Démarrage de Subsonics : Processing"
|
|
||||||
cd /home/gitlab-ci
|
|
||||||
pm2 start subsonic.config.js
|
|
||||||
echo "[Subsonics-Deploy] - Démarrage de Subsonics : Success"
|
|
||||||
|
|
||||||
echo "[Subsonics-Deploy] - Stage - Déploiement - END"
|
|
||||||
'
|
|
||||||
EOF
|
|
@@ -1,91 +1,46 @@
|
|||||||
const { LogType } = require('loguix');
|
const {createAudioResource, VoiceConnectionStatus, createAudioPlayer, StreamType} = require('@discordjs/voice');
|
||||||
const clog = new LogType("Youtube-Stream");
|
const {LogType} = require('loguix')
|
||||||
|
const clog = new LogType("Youtube-Stream")
|
||||||
|
const ytdl = require('@distube/ytdl-core')
|
||||||
const { __glob } = require('../../utils/GlobalVars');
|
const { __glob } = require('../../utils/GlobalVars');
|
||||||
const { Innertube, UniversalCache, ClientType } = require('youtubei.js');
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const { ProxyAgent } = require('undici');
|
|
||||||
|
|
||||||
async function getStream(song) {
|
async function getStream(song) {
|
||||||
try {
|
|
||||||
// Lire et formater les cookies comme chaîne
|
|
||||||
const cookiesArr = JSON.parse(fs.readFileSync(__glob.COOKIES, 'utf-8'));
|
|
||||||
const cookieStr = cookiesArr.map(cookie => `${cookie.name}=${cookie.value}`).join('; ');
|
|
||||||
|
|
||||||
// Lire et préparer le proxy
|
// FIXME: Change youtube provider
|
||||||
const proxy = JSON.parse(fs.readFileSync(__glob.PROXY, 'utf-8'));
|
|
||||||
const proxyAgent = new ProxyAgent(proxy.uri);
|
try {
|
||||||
|
|
||||||
|
const headers = {
|
||||||
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) ' +
|
||||||
|
'AppleWebKit/537.36 (KHTML, like Gecko) ' +
|
||||||
|
'Chrome/116.0.5845.97 Safari/537.36',
|
||||||
|
'Accept-Language': 'en-US,en;q=0.9'
|
||||||
|
};
|
||||||
|
|
||||||
console.log(`Tentative de récupération pour: ${song.title || song.url}`);
|
var cookies = await JSON.parse(await fs.readFileSync(__glob.COOKIES, 'utf-8'));
|
||||||
|
const proxy = await JSON.parse(await fs.readFileSync(__glob.PROXY, 'utf-8'));
|
||||||
|
const agent = ytdl.createProxyAgent(proxy, cookies)
|
||||||
|
let stream = ytdl(song.url, {
|
||||||
|
quality: 'highestaudio',
|
||||||
|
highWaterMark: 1 << 30,
|
||||||
|
liveBuffer: 20000,
|
||||||
|
dlChunkSize: 0,
|
||||||
|
bitrate: 128,
|
||||||
|
requestOptions: {
|
||||||
|
headers: headers,
|
||||||
|
},
|
||||||
|
agent: agent,
|
||||||
|
});
|
||||||
|
|
||||||
// Création de l'instance Innertube avec les bons paramètres
|
return stream
|
||||||
const youtube = await Innertube.create({
|
|
||||||
cookie: cookieStr,
|
} catch(e) {
|
||||||
player_id: '0004de42',
|
clog.error("Erreur lors de la récupération du stream : " + song.title)
|
||||||
user_agent: `Mozilla/5.0 (Macintosh; Intel Mac OS X 15_0) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Safari/605.1.15`,
|
clog.error(e)
|
||||||
client_type: ClientType.WEB,
|
|
||||||
retrieve_player: true,
|
|
||||||
device_category: 'desktop',
|
|
||||||
enable_session_cache: true,
|
|
||||||
generate_session_locally: true,
|
|
||||||
// fetch: (url, options) => fetch(url, { ...options, agent: proxyAgent })
|
|
||||||
});
|
|
||||||
|
|
||||||
// Récupérer les infos vidéo
|
|
||||||
const videoInfo = await youtube.getInfo(song.id);
|
|
||||||
|
|
||||||
|
|
||||||
if (!videoInfo) {
|
|
||||||
throw new Error('Impossible de récupérer les informations de la vidéo');
|
|
||||||
}
|
|
||||||
console.log('Informations vidéo récupérées:', videoInfo.basic_info?.title);
|
|
||||||
|
|
||||||
// Vérifier la disponibilité de la lecture
|
|
||||||
if (videoInfo.playability_status?.status !== 'OK') {
|
|
||||||
console.log('Statut de lecture:', videoInfo.playability_status?.status);
|
|
||||||
console.log('Raison:', videoInfo.playability_status?.reason);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Recherche des formats audio adaptatifs
|
|
||||||
let audioFormats = videoInfo.streaming_data?.adaptive_formats?.filter(
|
|
||||||
format => format.mime_type?.includes('audio')
|
|
||||||
) || [];
|
|
||||||
|
|
||||||
if (audioFormats.length === 0) {
|
|
||||||
// Si pas de formats adaptatifs, chercher dans les formats classiques
|
|
||||||
const basicFormats = videoInfo.streaming_data?.formats?.filter(
|
|
||||||
format => format.mime_type?.includes('audio')
|
|
||||||
) || [];
|
|
||||||
if (basicFormats.length === 0) {
|
|
||||||
throw new Error('Aucun format audio trouvé');
|
|
||||||
}
|
|
||||||
audioFormats.push(...basicFormats);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sélection du format audio de meilleure qualité
|
|
||||||
const bestAudio = audioFormats.reduce((prev, current) =>
|
|
||||||
(prev.bitrate || 0) > (current.bitrate || 0) ? prev : current
|
|
||||||
);
|
|
||||||
|
|
||||||
console.log('Format sélectionné:', bestAudio.mime_type, bestAudio.bitrate);
|
|
||||||
|
|
||||||
// Télécharger le stream audio
|
|
||||||
const stream = await videoInfo.download(bestAudio.itag, {
|
|
||||||
// fetch via ton proxy si nécessaire
|
|
||||||
headers: {
|
|
||||||
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 15_0) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Safari/605.1.15',
|
|
||||||
'Cookie': cookieStr
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(stream)
|
|
||||||
|
|
||||||
return stream; // c’est un ReadableStream prêt à être pipé
|
|
||||||
} catch (e) {
|
|
||||||
clog.error("Erreur lors de la récupération du stream : " + (song.title || song.url));
|
|
||||||
clog.error('Détails:', e.message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { getStream };
|
|
||||||
|
module.exports = {getStream}
|
||||||
|
Reference in New Issue
Block a user