GET /yandex.html — получение токена в один клик: кнопка ведёт на oauth.yandex.ru с клиентом Яндекс Музыки, токен ловится из адреса, сохраняется через POST /yandex/save в /root/.yandex-token (600) и сразу проверяется. GET /yandex/status — состояние и наличие Плюса. Установлены: beets 2.14.1 (venv), yt-dlp, mutagen, musicbrainzngs, ffmpeg 7.1.5, fpcalc. Системный pip не подошёл из-за externally-managed — пакеты в /opt/music-tools/venv, обёртка /usr/local/bin/beet.
132 lines
6.1 KiB
HTML
132 lines
6.1 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="ru">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>Токен Яндекс Музыки — Buryans Hub</title>
|
||
<style>
|
||
:root { --bg:#0d1117; --fg:#c9d1d9; --dim:#8b949e; --line:#30363d; --acc:#58a6ff; --ok:#3fb950; --warn:#d29922; }
|
||
* { box-sizing:border-box; }
|
||
body { margin:0; background:var(--bg); color:var(--fg);
|
||
font:15px/1.65 -apple-system,"Segoe UI",Roboto,sans-serif; }
|
||
.wrap { max-width:760px; margin:0 auto; padding:32px 20px 80px; }
|
||
h1 { font-size:21px; margin:0 0 6px; }
|
||
.sub { color:var(--dim); font-size:13px; margin-bottom:24px; }
|
||
.card { background:#161b22; border:1px solid var(--line); border-radius:10px;
|
||
padding:18px 20px; margin-bottom:16px; }
|
||
.card h2 { font-size:15px; margin:0 0 10px; }
|
||
ol { margin:8px 0 0; padding-left:20px; }
|
||
li { margin:6px 0; }
|
||
code { background:#0d1117; border:1px solid var(--line); border-radius:4px;
|
||
padding:1px 6px; font-size:13px; }
|
||
.btn { display:inline-block; background:var(--acc); color:#0d1117; text-decoration:none;
|
||
border:0; border-radius:8px; padding:11px 18px; font-weight:600; cursor:pointer;
|
||
font-size:15px; }
|
||
.btn.secondary { background:#21262d; color:var(--fg); border:1px solid var(--line); }
|
||
input { width:100%; background:#0d1117; border:1px solid var(--line); color:var(--fg);
|
||
border-radius:8px; padding:11px 12px; font-size:14px; outline:none; margin:10px 0; }
|
||
input:focus { border-color:var(--acc); }
|
||
.state { padding:12px 14px; border-radius:8px; background:#0d1117;
|
||
border:1px solid var(--line); font-size:14px; }
|
||
.ok { color:var(--ok); } .warn { color:var(--warn); }
|
||
.muted { color:var(--dim); font-size:13px; }
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div class="wrap">
|
||
<h1>Токен Яндекс Музыки</h1>
|
||
<div class="sub">Нужен для синхронизации «Мне нравится» с медиасервером. Пароль мне передавать не нужно — только токен.</div>
|
||
|
||
<div class="card">
|
||
<h2>Состояние</h2>
|
||
<div class="state" id="state">проверяю…</div>
|
||
</div>
|
||
|
||
<div class="card">
|
||
<h2>Как получить токен</h2>
|
||
<ol>
|
||
<li>Откройте ссылку ниже и войдите в свой аккаунт Яндекса.</li>
|
||
<li>После входа браузер перейдёт на страницу, в адресе которой будет
|
||
<code>#access_token=...</code> — это и есть токен.</li>
|
||
<li>Скопируйте значение после <code>access_token=</code> до <code>&</code>
|
||
и вставьте ниже.</li>
|
||
</ol>
|
||
<p><a class="btn" id="oauth" href="#" target="_blank" rel="noopener">Открыть вход Яндекса</a></p>
|
||
<p class="muted">Ссылка ведёт на официальный <code>oauth.yandex.ru</code> с клиентом
|
||
Яндекс Музыки. Токен даёт доступ к вашему аккаунту музыки, поэтому хранится
|
||
только на сервере с правами 600.</p>
|
||
</div>
|
||
|
||
<div class="card">
|
||
<h2>Вставить токен</h2>
|
||
<input id="tok" type="password" placeholder="вставьте токен сюда" autocomplete="off">
|
||
<button class="btn" id="save">Сохранить и проверить</button>
|
||
<p class="muted" id="msg"></p>
|
||
</div>
|
||
|
||
<p class="muted">
|
||
<a style="color:var(--acc)" href="graph.html">граф</a> ·
|
||
<a style="color:var(--acc)" href="ask.html">агент</a> ·
|
||
<a style="color:var(--acc)" href="./">панель</a>
|
||
</p>
|
||
</div>
|
||
<script>
|
||
const CLIENT = "23cabbbdc6cd418abb4b39c32c41195d"; // клиент Яндекс Музыки
|
||
const REDIRECT = location.origin + location.pathname;
|
||
document.getElementById("oauth").href =
|
||
"https://oauth.yandex.ru/authorize?response_type=token&client_id=" + CLIENT;
|
||
|
||
async function refresh(){
|
||
const s = document.getElementById("state");
|
||
try {
|
||
const r = await fetch("yandex/status");
|
||
const d = await r.json();
|
||
if (!d.has_token) {
|
||
s.innerHTML = '<span class="warn">токена нет</span> — синхронизация выключена';
|
||
} else if (d.error) {
|
||
s.innerHTML = '<span class="warn">токен есть, но не работает:</span> ' + d.error;
|
||
} else {
|
||
s.innerHTML = '<span class="ok">подключено</span> · ' + (d.login || d.uid) +
|
||
' · Плюс: ' + (d.plus ? "да" : "нет");
|
||
}
|
||
} catch (e) {
|
||
s.textContent = "не смог проверить: " + e;
|
||
}
|
||
}
|
||
|
||
document.getElementById("save").addEventListener("click", async () => {
|
||
const tok = document.getElementById("tok").value.trim();
|
||
const msg = document.getElementById("msg");
|
||
if (!tok) { msg.textContent = "вставьте токен"; return; }
|
||
msg.textContent = "проверяю…";
|
||
try {
|
||
const r = await fetch("yandex/save", {
|
||
method: "POST", headers: {"Content-Type": "application/json"},
|
||
body: JSON.stringify({token: tok})
|
||
});
|
||
const d = await r.json();
|
||
if (d.error && !d.has_token) {
|
||
msg.innerHTML = '<span class="warn">' + d.error + '</span>';
|
||
} else if (d.error) {
|
||
msg.innerHTML = '<span class="warn">сохранён, но не проверен:</span> ' + d.error;
|
||
} else {
|
||
msg.innerHTML = '<span class="ok">готово</span> · ' + (d.login || d.uid) +
|
||
' · Плюс: ' + (d.plus ? "да" : "нет");
|
||
document.getElementById("tok").value = "";
|
||
refresh();
|
||
}
|
||
} catch (e) { msg.textContent = "ошибка: " + e; }
|
||
});
|
||
|
||
// если токен пришёл в адресе (после OAuth) — подставим автоматически
|
||
const m = location.hash.match(/access_token=([^&]+)/);
|
||
if (m) {
|
||
document.getElementById("tok").value = decodeURIComponent(m[1]);
|
||
history.replaceState(null, "", location.pathname);
|
||
document.getElementById("msg").textContent = "токен получен из ссылки — нажмите «Сохранить»";
|
||
}
|
||
refresh();
|
||
</script>
|
||
</body>
|
||
</html>
|