Musik: YouTube-Anmeldung der Bots von der Website aus - Administratoren und Entwickler laden auf der Musik-Seite die cookies.txt eines YouTube-Kontos hoch (musik_api.php youtube/youtube_upload/youtube_test/youtube_delete, includes/music.php music_can_manage_youtube/music_youtube_login); sie geht an alle Musikbots, wird dort sofort mit einem altersbeschraenkten Video geprueft und nie auf der Website gespeichert. Stand je Bot (funktioniert / nicht altersbestaetigt / abgelaufen), erneut pruefen, entfernen, aufklappbare Schritt-fuer-Schritt-Anleitung. Bots: youtube_cookies.py, Routen .../music/cookies, verstaendliche Meldung bei Altersbeschraenkung. Patchnote
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
parent
d0c7cad6e5
commit
cb5d90a796
6 changed files with 264 additions and 1 deletions
|
|
@ -10311,6 +10311,25 @@ ol.music-list li:not(.music-empty)::before { counter-increment: music; content:
|
||||||
.music-file input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
|
.music-file input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
|
||||||
.music-file .icon { color: var(--gold); }
|
.music-file .icon { color: var(--gold); }
|
||||||
|
|
||||||
|
/* YouTube-Anmeldung der Bots (nur Administratoren und Entwickler): Stand je Bot, Upload der cookies.txt, Anleitung */
|
||||||
|
.music-yt-intro { margin: 0 0 0.75rem; color: var(--text-muted); font-size: 0.85rem; }
|
||||||
|
.music-yt-status { display: flex; flex-direction: column; gap: 0.4rem; margin: 0; padding: 0; list-style: none; }
|
||||||
|
.music-yt-status li { display: grid; grid-template-columns: 5rem minmax(0, 1fr); gap: 0.1rem 0.6rem; align-items: baseline; padding: 0.55rem 0.8rem; border-left: 3px solid rgba(255, 255, 255, 0.2); border-radius: 8px; background: rgba(255, 255, 255, 0.04); font-size: 0.88rem; }
|
||||||
|
.music-yt-status li.is-good { border-left-color: #4caf50; }
|
||||||
|
.music-yt-status li.is-warn { border-left-color: var(--gold); }
|
||||||
|
.music-yt-status li.is-bad { border-left-color: #d9534f; }
|
||||||
|
.music-yt-status li.is-off .music-yt-text { color: var(--text-muted); }
|
||||||
|
.music-yt-status li > :only-child { grid-column: 1 / -1; }
|
||||||
|
.music-yt-status small { grid-column: 2; color: var(--text-muted); font-size: 0.76rem; }
|
||||||
|
.music-yt .music-text-btn[hidden] { display: none; }
|
||||||
|
.music-yt.is-working button { opacity: 0.6; pointer-events: none; }
|
||||||
|
.music-yt-guide { margin-top: 0.9rem; padding-top: 0.9rem; border-top: 1px solid var(--border); font-size: 0.88rem; }
|
||||||
|
.music-yt-guide > summary { color: var(--gold); font-weight: 500; cursor: pointer; }
|
||||||
|
.music-yt-guide ol { display: flex; flex-direction: column; gap: 0.6rem; max-width: 62rem; margin: 0.8rem 0 0; padding-left: 1.4rem; color: var(--text-muted); line-height: 1.5; }
|
||||||
|
.music-yt-guide li strong, .music-yt-guide p strong { color: var(--text); }
|
||||||
|
.music-yt-guide p { max-width: 62rem; margin: 0.8rem 0 0; color: var(--text-muted); line-height: 1.5; }
|
||||||
|
.music-yt-guide code, .music-yt-guide kbd { padding: 0.05rem 0.35rem; border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 4px; background: rgba(0, 0, 0, 0.3); color: var(--text); font-size: 0.82em; overflow-wrap: anywhere; }
|
||||||
|
|
||||||
.is-busy .music-btn, .is-busy .music-item-btn, .is-busy .music-text-btn { opacity: 0.6; pointer-events: none; }
|
.is-busy .music-btn, .is-busy .music-item-btn, .is-busy .music-text-btn { opacity: 0.6; pointer-events: none; }
|
||||||
.music-toast {
|
.music-toast {
|
||||||
position: fixed; left: 50%; bottom: 1.5rem; z-index: 1200; max-width: min(92vw, 520px); padding: 0.6rem 1rem; border: 1px solid rgba(201, 162, 39, 0.5);
|
position: fixed; left: 50%; bottom: 1.5rem; z-index: 1200; max-width: min(92vw, 520px); padding: 0.6rem 1rem; border: 1px solid rgba(201, 162, 39, 0.5);
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
* Warteschlange (umsortieren, hinspringen), Verlauf und Playlist - die Leitung (music.manage) laedt Titel hoch
|
* Warteschlange (umsortieren, hinspringen), Verlauf und Playlist - die Leitung (music.manage) laedt Titel hoch
|
||||||
* und loescht sie. Die Zeit des laufenden Titels zaehlt zwischen zwei Abfragen weiter. Listen werden nur neu
|
* und loescht sie. Die Zeit des laufenden Titels zaehlt zwischen zwei Abfragen weiter. Listen werden nur neu
|
||||||
* aufgebaut, wenn sich ihr Inhalt geaendert hat, damit Scrollposition und Klicks nicht verloren gehen.
|
* aufgebaut, wenn sich ihr Inhalt geaendert hat, damit Scrollposition und Klicks nicht verloren gehen.
|
||||||
|
* Administratoren und Entwickler pflegen unten die YouTube-Anmeldung der Bots (cookies.txt hochladen, pruefen, entfernen).
|
||||||
*/
|
*/
|
||||||
(function () {
|
(function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
@ -421,6 +422,100 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---- YouTube-Anmeldung der Bots (Block gibt es nur fuer Administratoren und Entwickler) ----
|
||||||
|
// Die cookies.txt geht ueber musik_api.php an alle Musikbots; angezeigt wird nur der Stand je Bot, nie der Inhalt.
|
||||||
|
var yt = $('[data-music-yt]');
|
||||||
|
if (yt) {
|
||||||
|
var ytList = yt.querySelector('[data-music-yt-status]');
|
||||||
|
var ytForm = yt.querySelector('[data-music-yt-upload]');
|
||||||
|
var ytInput = ytForm.querySelector('input[type="file"]');
|
||||||
|
var ytLabel = yt.querySelector('[data-music-yt-file-label]');
|
||||||
|
var ytLabelText = ytLabel.textContent;
|
||||||
|
var ytTest = yt.querySelector('[data-music-yt-test]');
|
||||||
|
var ytDelete = yt.querySelector('[data-music-yt-delete]');
|
||||||
|
var YT_TONES = { ok: 'good', no_age: 'warn', untested: 'warn', none: 'off' }; // alles andere: rot
|
||||||
|
var when = function (seconds) {
|
||||||
|
return new Date(seconds * 1000).toLocaleString('de-DE', { day: '2-digit', month: '2-digit', year: 'numeric', hour: '2-digit', minute: '2-digit' });
|
||||||
|
};
|
||||||
|
var renderYt = function (rows) {
|
||||||
|
var present = false;
|
||||||
|
ytList.textContent = '';
|
||||||
|
(rows || []).forEach(function (row) {
|
||||||
|
var li = document.createElement('li');
|
||||||
|
li.className = 'is-' + (row.error ? 'bad' : YT_TONES[row.result] || 'bad');
|
||||||
|
var name = document.createElement('strong');
|
||||||
|
name.textContent = row.name;
|
||||||
|
var text = document.createElement('span');
|
||||||
|
text.className = 'music-yt-text';
|
||||||
|
text.textContent = row.error || row.detail;
|
||||||
|
li.appendChild(name);
|
||||||
|
li.appendChild(text);
|
||||||
|
if (row.present) {
|
||||||
|
present = true;
|
||||||
|
var facts = [row.uploaded_at
|
||||||
|
? 'hochgeladen am ' + when(row.uploaded_at) + (row.uploaded_by ? ' von ' + row.uploaded_by : '')
|
||||||
|
: 'von Hand auf dem Server hinterlegt'];
|
||||||
|
if (row.tested_at) facts.push('geprüft am ' + when(row.tested_at));
|
||||||
|
var meta = document.createElement('small');
|
||||||
|
meta.textContent = facts.join(' · ');
|
||||||
|
li.appendChild(meta);
|
||||||
|
}
|
||||||
|
ytList.appendChild(li);
|
||||||
|
});
|
||||||
|
ytTest.hidden = !present;
|
||||||
|
ytDelete.hidden = !present;
|
||||||
|
};
|
||||||
|
var ytFail = function (message) {
|
||||||
|
ytList.textContent = '';
|
||||||
|
var li = document.createElement('li');
|
||||||
|
li.className = 'is-bad';
|
||||||
|
li.textContent = message;
|
||||||
|
ytList.appendChild(li);
|
||||||
|
};
|
||||||
|
// Ein Aufruf: Knopf solange sperren (die Pruefung bei YouTube dauert ein paar Sekunden je Bot)
|
||||||
|
var ytCall = function (fields, file, button, busyText) {
|
||||||
|
var label = button.textContent;
|
||||||
|
yt.classList.add('is-working');
|
||||||
|
button.textContent = busyText;
|
||||||
|
return request(fields, file)
|
||||||
|
.then(function (result) {
|
||||||
|
if (result.csrf) csrf = result.csrf;
|
||||||
|
if (result.youtube) renderYt(result.youtube);
|
||||||
|
if (!result.ok) throw new Error(result.error || 'Hat nicht geklappt.');
|
||||||
|
toast(result.message);
|
||||||
|
return result;
|
||||||
|
})
|
||||||
|
.catch(function (error) { toast(error.message, true); throw error; })
|
||||||
|
.finally(function () { yt.classList.remove('is-working'); button.textContent = label; });
|
||||||
|
};
|
||||||
|
ytInput.addEventListener('change', function () {
|
||||||
|
ytLabel.textContent = ytInput.files[0] ? ytInput.files[0].name : ytLabelText;
|
||||||
|
});
|
||||||
|
ytForm.addEventListener('submit', function (event) {
|
||||||
|
event.preventDefault();
|
||||||
|
var file = ytInput.files[0];
|
||||||
|
if (!file) return;
|
||||||
|
if (file.size > 512 * 1024) { toast('Die Datei ist zu groß – eine cookies.txt hat nur ein paar Kilobyte.', true); return; }
|
||||||
|
ytCall({ action: 'youtube_upload' }, file, ytForm.querySelector('button[type="submit"]'), 'Lädt hoch und prüft …')
|
||||||
|
.then(function () { ytForm.reset(); ytLabel.textContent = ytLabelText; })
|
||||||
|
.catch(function () {});
|
||||||
|
});
|
||||||
|
ytTest.addEventListener('click', function () {
|
||||||
|
ytCall({ action: 'youtube_test' }, null, ytTest, 'Prüft …').catch(function () {});
|
||||||
|
});
|
||||||
|
ytDelete.addEventListener('click', function () {
|
||||||
|
if (!window.confirm('YouTube-Anmeldung bei allen Bots entfernen? Altersbeschränkte Videos gehen dann nicht mehr.')) return;
|
||||||
|
ytCall({ action: 'youtube_delete' }, null, ytDelete, 'Entfernt …').catch(function () {});
|
||||||
|
});
|
||||||
|
fetch('/musik_api.php?action=youtube&bot=' + encodeURIComponent(bot), { credentials: 'same-origin', headers: { 'Accept': 'application/json' } })
|
||||||
|
.then(parseJson)
|
||||||
|
.then(function (result) {
|
||||||
|
if (!result.ok) throw new Error(result.error || 'Stand nicht abrufbar');
|
||||||
|
renderYt(result.youtube);
|
||||||
|
})
|
||||||
|
.catch(function (error) { ytFail(error.message); });
|
||||||
|
}
|
||||||
|
|
||||||
poll();
|
poll();
|
||||||
setInterval(poll, POLL_MS);
|
setInterval(poll, POLL_MS);
|
||||||
setInterval(tick, 500);
|
setInterval(tick, 500);
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,11 @@
|
||||||
* nezekan Nezekan (raids_api in config.php), cogs/music.py + music_api.py, Pfade /api/music/...
|
* nezekan Nezekan (raids_api in config.php), cogs/music.py + music_api.py, Pfade /api/music/...
|
||||||
* siel Siel (siel_api in config.php, nur wenn eingerichtet), gleicher Code, Pfade /website-api/music/...
|
* siel Siel (siel_api in config.php, nur wenn eingerichtet), gleicher Code, Pfade /website-api/music/...
|
||||||
* Jeder Bot hat seine eigene Playlist (Dateien liegen beim jeweiligen Bot).
|
* Jeder Bot hat seine eigene Playlist (Dateien liegen beim jeweiligen Bot).
|
||||||
|
*
|
||||||
|
* YouTube-Anmeldung: Altersbeschraenkte Videos (und manchmal die Server-IP) verlangen bei YouTube ein angemeldetes
|
||||||
|
* Konto. Die Bots nehmen dafuer die Cookies einer Browser-Sitzung (cookies.txt, youtube_cookies.py im Bot).
|
||||||
|
* Administratoren und Entwickler laden die Datei auf der Musik-Seite hoch (music_can_manage_youtube()); sie geht
|
||||||
|
* an alle Musikbots, wird dort sofort geprueft und nie auf der Website gespeichert oder wieder angezeigt.
|
||||||
*/
|
*/
|
||||||
require_once __DIR__ . '/raids_api.php';
|
require_once __DIR__ . '/raids_api.php';
|
||||||
require_once __DIR__ . '/events_api.php';
|
require_once __DIR__ . '/events_api.php';
|
||||||
|
|
@ -20,6 +25,7 @@ const MUSIC_UPLOAD_EXTENSIONS = ['mp3', 'ogg', 'm4a', 'wav', 'flac', 'opus'];
|
||||||
const MUSIC_QUERY_MAX = 500;
|
const MUSIC_QUERY_MAX = 500;
|
||||||
const MUSIC_ACTIONS = ['toggle', 'pause', 'resume', 'skip', 'previous', 'stop', 'shuffle', 'loop', 'volume', 'remove', 'clear', 'move', 'jump', 'seek'];
|
const MUSIC_ACTIONS = ['toggle', 'pause', 'resume', 'skip', 'previous', 'stop', 'shuffle', 'loop', 'volume', 'remove', 'clear', 'move', 'jump', 'seek'];
|
||||||
const MUSIC_BOTS = ['nezekan' => 'Nezekan', 'siel' => 'Siel'];
|
const MUSIC_BOTS = ['nezekan' => 'Nezekan', 'siel' => 'Siel'];
|
||||||
|
const MUSIC_COOKIES_MAX = 512 * 1024; // eine cookies.txt hat nur ein paar Kilobyte
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Die Musikbots, die eingerichtet sind: Schluessel => Anzeigename. Nezekan immer, Siel nur mit siel_api in config.php.
|
* Die Musikbots, die eingerichtet sind: Schluessel => Anzeigename. Nezekan immer, Siel nur mit siel_api in config.php.
|
||||||
|
|
@ -104,6 +110,46 @@ function music_api_request(string $bot, string $method, string $path, ?array $js
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Darf das Konto die YouTube-Anmeldung der Musikbots pflegen? Nur Administratoren und Entwickler. */
|
||||||
|
function music_can_manage_youtube(?array $user = null): bool
|
||||||
|
{
|
||||||
|
$user ??= current_user();
|
||||||
|
return $user !== null && (!empty($user['is_admin']) || is_developer($user));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* YouTube-Anmeldung bei allen Musikbots abfragen oder aendern - derselbe Aufruf geht an jeden Bot.
|
||||||
|
*
|
||||||
|
* @param string $method GET = Stand, POST = hochladen ($json: cookies, user) bzw. pruefen ($path .../test), DELETE = entfernen
|
||||||
|
* @return list<array<string, mixed>> je Bot: bot, name und entweder present, uploaded_at, uploaded_by, tested_at,
|
||||||
|
* result (none|untested|ok|no_age|expired|blocked|error), detail - oder error
|
||||||
|
*/
|
||||||
|
function music_youtube_login(string $method = 'GET', string $path = '/music/cookies', ?array $json = null): array
|
||||||
|
{
|
||||||
|
$rows = [];
|
||||||
|
foreach (music_bots() as $bot => $name) {
|
||||||
|
$row = ['bot' => $bot, 'name' => $name];
|
||||||
|
try {
|
||||||
|
$state = (array) (music_api_request($bot, $method, $path, $json)['youtube'] ?? []);
|
||||||
|
$row += [
|
||||||
|
'present' => !empty($state['present']),
|
||||||
|
'uploaded_at' => isset($state['uploaded_at']) ? (int) $state['uploaded_at'] : null,
|
||||||
|
'uploaded_by' => (string) ($state['uploaded_by'] ?? ''),
|
||||||
|
'tested_at' => isset($state['tested_at']) ? (int) $state['tested_at'] : null,
|
||||||
|
'result' => (string) ($state['result'] ?? 'none'),
|
||||||
|
'detail' => (string) ($state['detail'] ?? ''),
|
||||||
|
];
|
||||||
|
} catch (RuntimeException $e) {
|
||||||
|
// Ein Bot ohne das Update haelt "cookies" fuer eine Server-ID (422) oder kennt den Pfad nicht (404/405)
|
||||||
|
$row['error'] = preg_match('/Status (404|405|422)\.$/', $e->getMessage())
|
||||||
|
? $name . ' kennt die YouTube-Anmeldung noch nicht (Bot-Update fehlt).'
|
||||||
|
: $e->getMessage();
|
||||||
|
}
|
||||||
|
$rows[] = $row;
|
||||||
|
}
|
||||||
|
return $rows;
|
||||||
|
}
|
||||||
|
|
||||||
/** Zustand der Musik eines Bots auf dem Legions-Server (Kanal, Titel, Warteschlange, Verlauf, Playlist). */
|
/** Zustand der Musik eines Bots auf dem Legions-Server (Kanal, Titel, Warteschlange, Verlauf, Playlist). */
|
||||||
function music_state(string $bot): array
|
function music_state(string $bot): array
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,16 @@ const PATCHNOTE_TYPES = [
|
||||||
];
|
];
|
||||||
|
|
||||||
const PATCHNOTES = [
|
const PATCHNOTES = [
|
||||||
|
[
|
||||||
|
'id' => '2026-11-21-a',
|
||||||
|
'date' => '2026-11-21',
|
||||||
|
'title' => 'Musik: altersbeschränkte YouTube-Videos',
|
||||||
|
'summary' => 'Der Bot sagt jetzt verständlich, wenn ein YouTube-Video wegen einer Altersbeschränkung nicht geht – und Administratoren können die Bots auf der Musik-Seite bei YouTube anmelden.',
|
||||||
|
'changes' => [
|
||||||
|
['type' => 'verbessert', 'area' => 'Musik', 'text' => 'Hat ein YouTube-Video eine Altersbeschränkung, sagt der Bot das jetzt auf Deutsch statt mit einer englischen Fehlermeldung. Nimm dann einen anderen Upload des Lieds oder such nach dem Titel.'],
|
||||||
|
['type' => 'neu', 'area' => 'Musik', 'audience' => 'leitung', 'text' => 'Musik-Seite, ganz unten (nur Administratoren und Entwickler): „YouTube-Anmeldung der Bots“. Dort lädst du die Cookies eines YouTube-Kontos als Datei hoch; beide Bots prüfen sie sofort und zeigen, ob die Anmeldung funktioniert, abgelaufen ist oder das Konto nicht altersbestätigt ist. Neu gestartet werden muss nichts, eine Schritt-für-Schritt-Anleitung steht direkt dabei. Die Website selbst speichert die Datei nicht.'],
|
||||||
|
],
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'id' => '2026-11-16-a',
|
'id' => '2026-11-16-a',
|
||||||
'date' => '2026-11-16',
|
'date' => '2026-11-16',
|
||||||
|
|
|
||||||
36
musik.php
36
musik.php
|
|
@ -9,6 +9,7 @@ require_once __DIR__ . '/includes/music.php';
|
||||||
require_permission('music.control');
|
require_permission('music.control');
|
||||||
|
|
||||||
$canManage = user_has_permission('music.manage');
|
$canManage = user_has_permission('music.manage');
|
||||||
|
$canYoutube = music_can_manage_youtube(); // YouTube-Anmeldung der Bots: nur Administratoren und Entwickler
|
||||||
$bots = music_bots(); // mehrere Bots = Umschalter im Player, jeder mit eigenem Kanal, Warteschlange und Playlist
|
$bots = music_bots(); // mehrere Bots = Umschalter im Player, jeder mit eigenem Kanal, Warteschlange und Playlist
|
||||||
$pageTitle = 'Musik';
|
$pageTitle = 'Musik';
|
||||||
include __DIR__ . '/includes/header.php';
|
include __DIR__ . '/includes/header.php';
|
||||||
|
|
@ -117,6 +118,41 @@ include __DIR__ . '/includes/header.php';
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<?php if ($canYoutube): ?>
|
||||||
|
<section class="panel music-card music-yt" data-music-yt>
|
||||||
|
<div class="music-card-head">
|
||||||
|
<h2>YouTube-Anmeldung der Bots</h2>
|
||||||
|
<button type="button" class="music-text-btn" data-music-yt-test hidden>Erneut prüfen</button>
|
||||||
|
</div>
|
||||||
|
<p class="music-yt-intro">Altersbeschränkte Videos gibt YouTube nur an angemeldete Konten heraus. Dafür bekommen die Bots die Cookies eines YouTube-Kontos – als Datei, die du hier hochlädst. Diesen Bereich sehen nur Administratoren und Entwickler.</p>
|
||||||
|
<ul class="music-yt-status" data-music-yt-status><li class="is-off"><span class="music-yt-text">Lade Stand …</span></li></ul>
|
||||||
|
<form class="music-upload" data-music-yt-upload>
|
||||||
|
<label class="music-file">
|
||||||
|
<input type="file" name="file" accept=".txt,text/plain" required data-enhanced="1">
|
||||||
|
<?= icon('upload') ?><span data-music-yt-file-label>cookies.txt wählen – exportiert auf youtube.com, Format „Netscape“</span>
|
||||||
|
</label>
|
||||||
|
<div class="music-row">
|
||||||
|
<button type="submit" class="button">Hochladen & prüfen</button>
|
||||||
|
<button type="button" class="button button-secondary" data-music-yt-delete hidden>Anmeldung entfernen</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<details class="music-yt-guide">
|
||||||
|
<summary>Schritt für Schritt: So meldest du die Bots bei YouTube an</summary>
|
||||||
|
<ol>
|
||||||
|
<li><strong>Ein eigenes Konto für die Bots nehmen.</strong> Am besten ein Google-Konto nur für diesen Zweck, nicht dein Hauptkonto – die Cookies sind ein Zugang zu diesem Konto. Für altersbeschränkte Videos muss dort das Alter bestätigt sein: einmal mit dem Konto ein Video ab 18 öffnen und der Aufforderung von YouTube folgen (Ausweis oder Kreditkarte).</li>
|
||||||
|
<li><strong>Eine Erweiterung installieren,</strong> die Cookies als <code>cookies.txt</code> speichert – zum Beispiel „Get cookies.txt LOCALLY“ (Chrome, Edge) oder „cookies.txt“ (Firefox). In den Einstellungen der Erweiterung „Im Inkognito-Modus zulassen“ bzw. „In privaten Fenstern ausführen“ einschalten.</li>
|
||||||
|
<li><strong>Ein privates Fenster öffnen</strong> (<kbd>Strg</kbd> + <kbd>Umschalt</kbd> + <kbd>N</kbd>, in Firefox <kbd>Strg</kbd> + <kbd>Umschalt</kbd> + <kbd>P</kbd>) und dort auf youtube.com mit dem Konto der Bots anmelden.</li>
|
||||||
|
<li><strong>Im selben Tab</strong> die Adresse <code>https://www.youtube.com/robots.txt</code> aufrufen. Im privaten Fenster darf sonst kein Tab mit YouTube offen sein – sonst tauscht YouTube die Cookies gleich wieder aus.</li>
|
||||||
|
<li><strong>Die Cookies exportieren:</strong> Erweiterung anklicken, Format „Netscape“ wählen und nur die aktuelle Seite exportieren. Das ergibt eine Datei wie <code>www.youtube.com_cookies.txt</code>.</li>
|
||||||
|
<li><strong>Das private Fenster schließen – nicht abmelden.</strong> Wer sich abmeldet oder das Konto danach in einem normalen Fenster weiterbenutzt, macht die Cookies ungültig.</li>
|
||||||
|
<li><strong>Hier hochladen:</strong> oben die Datei auswählen und „Hochladen & prüfen“ klicken. Nach einigen Sekunden steht bei jedem Bot, ob es geklappt hat. Neu gestartet werden muss nichts.</li>
|
||||||
|
<li><strong>Die Datei vom eigenen Rechner löschen.</strong> Die Website selbst speichert sie nicht, sie liegt nur bei den Bots auf dem Server.</li>
|
||||||
|
</ol>
|
||||||
|
<p><strong>Wann wiederholen?</strong> Wenn oben „abgelaufen“ steht oder ein Bot bei einem YouTube-Link eine Altersbeschränkung oder fehlende Anmeldung meldet: Schritte 3 bis 8 noch einmal. Eine feste Laufzeit haben die Cookies nicht.</p>
|
||||||
|
</details>
|
||||||
|
</section>
|
||||||
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
<div class="music-toast" data-music-toast hidden></div>
|
<div class="music-toast" data-music-toast hidden></div>
|
||||||
<script src="<?= e(asset_url('/assets/js/music.js')) ?>"></script>
|
<script src="<?= e(asset_url('/assets/js/music.js')) ?>"></script>
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,13 @@
|
||||||
* POST action=upload, file, title Datei in die Playlist (music.manage)
|
* POST action=upload, file, title Datei in die Playlist (music.manage)
|
||||||
* POST action=delete, track_id Titel aus der Playlist (music.manage)
|
* POST action=delete, track_id Titel aus der Playlist (music.manage)
|
||||||
* Steuern: music.control, Playlist verwalten: music.manage. POST mit CSRF-Token.
|
* Steuern: music.control, Playlist verwalten: music.manage. POST mit CSRF-Token.
|
||||||
|
*
|
||||||
|
* YouTube-Anmeldung der Bots (nur Administratoren und Entwickler, music_can_manage_youtube()) - gilt immer fuer alle
|
||||||
|
* Musikbots, Antwort zusaetzlich mit youtube = Stand je Bot (music_youtube_login()):
|
||||||
|
* GET ?action=youtube Stand
|
||||||
|
* POST action=youtube_upload, file cookies.txt an die Bots geben (wird dort abgelegt und geprueft)
|
||||||
|
* POST action=youtube_test erneut pruefen
|
||||||
|
* POST action=youtube_delete bei den Bots entfernen
|
||||||
*/
|
*/
|
||||||
require_once __DIR__ . '/includes/bootstrap.php';
|
require_once __DIR__ . '/includes/bootstrap.php';
|
||||||
require_once __DIR__ . '/includes/music.php';
|
require_once __DIR__ . '/includes/music.php';
|
||||||
|
|
@ -42,7 +49,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
$reply(false, 'Die Seite war zu lange offen – bitte noch einmal klicken.', ['stale' => true, 'csrf' => csrf_token()]);
|
$reply(false, 'Die Seite war zu lange offen – bitte noch einmal klicken.', ['stale' => true, 'csrf' => csrf_token()]);
|
||||||
}
|
}
|
||||||
verify_csrf();
|
verify_csrf();
|
||||||
} elseif ($action !== 'state') {
|
} elseif (!in_array($action, ['state', 'youtube'], true)) {
|
||||||
http_response_code(405);
|
http_response_code(405);
|
||||||
$reply(false, 'Nur per POST.');
|
$reply(false, 'Nur per POST.');
|
||||||
}
|
}
|
||||||
|
|
@ -130,6 +137,56 @@ try {
|
||||||
admin_log('🎵 Musik: Titel gelöscht', ['Titel-Nr.' => $trackId, 'Bot' => MUSIC_BOTS[$bot]], 'danger', 'discord');
|
admin_log('🎵 Musik: Titel gelöscht', ['Titel-Nr.' => $trackId, 'Bot' => MUSIC_BOTS[$bot]], 'danger', 'discord');
|
||||||
$reply(true, 'Titel gelöscht.', ['music' => music_state($bot)]);
|
$reply(true, 'Titel gelöscht.', ['music' => music_state($bot)]);
|
||||||
|
|
||||||
|
case 'youtube':
|
||||||
|
case 'youtube_upload':
|
||||||
|
case 'youtube_test':
|
||||||
|
case 'youtube_delete':
|
||||||
|
if (!music_can_manage_youtube()) {
|
||||||
|
http_response_code(403);
|
||||||
|
$reply(false, 'Die YouTube-Anmeldung pflegen nur Administratoren und Entwickler.');
|
||||||
|
}
|
||||||
|
// Kurzfassung fuers Log: "Nezekan: ok, Siel: expired"
|
||||||
|
$summary = static fn (array $rows): string => implode(', ', array_map(
|
||||||
|
static fn (array $row): string => $row['name'] . ': ' . (isset($row['error']) ? 'Fehler' : $row['result']),
|
||||||
|
$rows
|
||||||
|
));
|
||||||
|
if ($action === 'youtube') {
|
||||||
|
$reply(true, '', ['youtube' => music_youtube_login()]);
|
||||||
|
}
|
||||||
|
if ($action === 'youtube_test') {
|
||||||
|
$reply(true, 'Geprüft.', ['youtube' => music_youtube_login('POST', '/music/cookies/test', [])]);
|
||||||
|
}
|
||||||
|
if ($action === 'youtube_delete') {
|
||||||
|
$rows = music_youtube_login('DELETE');
|
||||||
|
admin_log('🎵 Musik: YouTube-Anmeldung entfernt', ['Bots' => $summary($rows)], 'danger', 'discord');
|
||||||
|
$reply(true, 'YouTube-Anmeldung entfernt.', ['youtube' => $rows]);
|
||||||
|
}
|
||||||
|
$file = $_FILES['file'] ?? null;
|
||||||
|
if (!is_array($file) || ($file['error'] ?? UPLOAD_ERR_NO_FILE) !== UPLOAD_ERR_OK || !is_uploaded_file($file['tmp_name'])) {
|
||||||
|
$reply(false, 'Bitte die exportierte cookies.txt auswählen.');
|
||||||
|
}
|
||||||
|
if ((int) $file['size'] > MUSIC_COOKIES_MAX) {
|
||||||
|
$reply(false, 'Die Datei ist zu groß – eine cookies.txt hat nur ein paar Kilobyte.');
|
||||||
|
}
|
||||||
|
// Der Inhalt geht nur an die Bots weiter - die Website speichert und loggt ihn nicht
|
||||||
|
$cookies = (string) file_get_contents($file['tmp_name']);
|
||||||
|
if (!mb_check_encoding($cookies, 'UTF-8') || stripos($cookies, 'youtube.com') === false) {
|
||||||
|
$reply(false, 'Das ist keine cookies.txt von youtube.com (Export im Format „Netscape“).');
|
||||||
|
}
|
||||||
|
$user = current_user();
|
||||||
|
$rows = music_youtube_login('POST', '/music/cookies', [
|
||||||
|
'cookies' => $cookies,
|
||||||
|
'user' => (string) ($user['display_name'] !== '' ? $user['display_name'] : $user['username']),
|
||||||
|
]);
|
||||||
|
$failed = array_filter($rows, static fn (array $row): bool => isset($row['error']));
|
||||||
|
if (count($failed) === count($rows)) {
|
||||||
|
// Kein Bot hat die Datei genommen (z. B. keine Anmeldung in den Cookies) - Meldung des ersten reicht
|
||||||
|
$reply(false, (string) reset($failed)['error'], ['youtube' => music_youtube_login()]);
|
||||||
|
}
|
||||||
|
admin_log('🎵 Musik: YouTube-Anmeldung hinterlegt', ['Bots' => $summary($rows)], 'info', 'discord');
|
||||||
|
$allOk = !$failed && !array_filter($rows, static fn (array $row): bool => $row['result'] !== 'ok');
|
||||||
|
$reply(true, $allOk ? 'YouTube-Anmeldung hinterlegt – sie funktioniert.' : 'Hochgeladen – das Ergebnis steht bei jedem Bot.', ['youtube' => $rows]);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
http_response_code(400);
|
http_response_code(400);
|
||||||
$reply(false, 'Unbekannte Aktion.');
|
$reply(false, 'Unbekannte Aktion.');
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue