Yandex Music metadata plugin for Jellyfin 12.4
This commit is contained in:
commit
c3dc901337
25 files changed
+3233
No files matched your search
@@ -0,0 +1,75 @@
|
||||
using MediaBrowser.Model.Plugins;
|
||||
|
||||
namespace Jellyfin.Plugin.YandexMusic.Configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Plugin configuration.
|
||||
/// </summary>
|
||||
public class PluginConfiguration : BasePluginConfiguration
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the Yandex OAuth token. Optional, required only for lyrics.
|
||||
/// </summary>
|
||||
public string Token { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the preferred language for genre names and artist descriptions.
|
||||
/// </summary>
|
||||
public string Language { get; set; } = "ru";
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether song metadata is enabled.
|
||||
/// </summary>
|
||||
public bool EnableSongMetadata { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether album metadata is enabled.
|
||||
/// </summary>
|
||||
public bool EnableAlbumMetadata { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether artist metadata is enabled.
|
||||
/// </summary>
|
||||
public bool EnableArtistMetadata { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether cover art is enabled.
|
||||
/// </summary>
|
||||
public bool EnableImages { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether lyrics are enabled.
|
||||
/// </summary>
|
||||
public bool EnableLyrics { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the real album title from Yandex is written to the track's Album field.
|
||||
/// When disabled (default), the existing album tag is kept.
|
||||
/// </summary>
|
||||
public bool UseYandexAlbumName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the original release year from Yandex may replace the year tag.
|
||||
/// </summary>
|
||||
public bool UseYandexYear { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the minimum match score (0..1) required to accept a search result.
|
||||
/// </summary>
|
||||
public double MatchThreshold { get; set; } = 0.72;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the duration tolerance in seconds used while matching tracks.
|
||||
/// </summary>
|
||||
public int DurationToleranceSeconds { get; set; } = 12;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether genres from Yandex are written to items.
|
||||
/// </summary>
|
||||
public bool EnableGenres { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether labels are written as studios.
|
||||
/// </summary>
|
||||
public bool EnableLabels { get; set; } = true;
|
||||
}
|
||||
@@ -0,0 +1,279 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Yandex Music</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="YandexMusicConfigPage" data-role="page" class="page type-interior pluginConfigurationPage" data-require="emby-input,emby-button,emby-select,emby-checkbox">
|
||||
<div data-role="content">
|
||||
<div class="content-primary">
|
||||
<form id="YandexMusicConfigForm">
|
||||
<div class="verticalSection">
|
||||
<h2>Подключение к Яндекс.Музыке</h2>
|
||||
<div class="fieldDescription">
|
||||
Метаданные, обложки и жанры доступны без авторизации. Токен нужен только для текстов песен.
|
||||
Токен хранится в конфигурации плагина на сервере.
|
||||
</div>
|
||||
<div class="inputContainer">
|
||||
<label class="inputLabel inputLabelUnfocused" for="Token">OAuth-токен</label>
|
||||
<input id="Token" name="Token" type="password" is="emby-input" autocomplete="off" />
|
||||
</div>
|
||||
<div>
|
||||
<button id="LoginButton" is="emby-button" type="button" class="raised button-submit emby-button">
|
||||
<span>Войти в Яндекс</span>
|
||||
</button>
|
||||
<button id="LogoutButton" is="emby-button" type="button" class="raised emby-button">
|
||||
<span>Выйти</span>
|
||||
</button>
|
||||
<button id="CheckButton" is="emby-button" type="button" class="raised emby-button">
|
||||
<span>Проверить соединение</span>
|
||||
</button>
|
||||
</div>
|
||||
<div id="DeviceBox" style="display:none;margin-top:1em" class="paperList">
|
||||
<div class="fieldDescription">Откройте страницу и введите код:</div>
|
||||
<p>
|
||||
<a id="DeviceLink" href="https://ya.ru/device" target="_blank" rel="noopener noreferrer">https://ya.ru/device</a>
|
||||
— код: <strong id="DeviceCode" style="font-size:1.4em;letter-spacing:.12em"></strong>
|
||||
</p>
|
||||
<div id="DeviceStatus" class="fieldDescription"></div>
|
||||
</div>
|
||||
<div id="StatusBox" class="fieldDescription" style="margin-top:.6em"></div>
|
||||
</div>
|
||||
|
||||
<div class="verticalSection">
|
||||
<h2>Что обогащать</h2>
|
||||
<div class="checkboxContainer checkboxContainer-withDescription">
|
||||
<label class="emby-checkbox-label">
|
||||
<input id="EnableSongMetadata" type="checkbox" is="emby-checkbox" />
|
||||
<span>Треки (название, исполнитель, альбом, год, жанр, лейбл, номер трека)</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="checkboxContainer checkboxContainer-withDescription">
|
||||
<label class="emby-checkbox-label">
|
||||
<input id="EnableAlbumMetadata" type="checkbox" is="emby-checkbox" />
|
||||
<span>Альбомы</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="checkboxContainer checkboxContainer-withDescription">
|
||||
<label class="emby-checkbox-label">
|
||||
<input id="EnableArtistMetadata" type="checkbox" is="emby-checkbox" />
|
||||
<span>Исполнители (биография, жанры, фото)</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="checkboxContainer checkboxContainer-withDescription">
|
||||
<label class="emby-checkbox-label">
|
||||
<input id="EnableImages" type="checkbox" is="emby-checkbox" />
|
||||
<span>Обложки</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="checkboxContainer checkboxContainer-withDescription">
|
||||
<label class="emby-checkbox-label">
|
||||
<input id="EnableLyrics" type="checkbox" is="emby-checkbox" />
|
||||
<span>Тексты песен (нужен токен)</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="checkboxContainer checkboxContainer-withDescription">
|
||||
<label class="emby-checkbox-label">
|
||||
<input id="EnableGenres" type="checkbox" is="emby-checkbox" />
|
||||
<span>Жанры Яндекса</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="checkboxContainer checkboxContainer-withDescription">
|
||||
<label class="emby-checkbox-label">
|
||||
<input id="EnableLabels" type="checkbox" is="emby-checkbox" />
|
||||
<span>Лейблы (как студии)</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="verticalSection">
|
||||
<h2>Поведение</h2>
|
||||
<div class="selectContainer">
|
||||
<label class="selectLabel" for="Language">Язык жанров</label>
|
||||
<select is="emby-select" id="Language" class="emby-select-withcolor emby-select">
|
||||
<option value="ru">Русский</option>
|
||||
<option value="en">English</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="checkboxContainer checkboxContainer-withDescription">
|
||||
<label class="emby-checkbox-label">
|
||||
<input id="UseYandexAlbumName" type="checkbox" is="emby-checkbox" />
|
||||
<span>Подставлять настоящее название альбома из Яндекса</span>
|
||||
</label>
|
||||
<div class="fieldDescription">
|
||||
Если включить, отдельные файлы с одинаковым альбомом соберутся в альбомы после обновления метаданных.
|
||||
</div>
|
||||
</div>
|
||||
<div class="checkboxContainer checkboxContainer-withDescription">
|
||||
<label class="emby-checkbox-label">
|
||||
<input id="UseYandexYear" type="checkbox" is="emby-checkbox" />
|
||||
<span>Брать год из Яндекса</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="inputContainer">
|
||||
<label class="inputLabel inputLabelUnfocused" for="MatchThreshold">Порог совпадения (0.5–0.95)</label>
|
||||
<input id="MatchThreshold" type="number" is="emby-input" min="0.5" max="0.95" step="0.01" />
|
||||
<div class="fieldDescription">Чем выше, тем меньше ложных совпадений и больше пропусков.</div>
|
||||
</div>
|
||||
<div class="inputContainer">
|
||||
<label class="inputLabel inputLabelUnfocused" for="DurationToleranceSeconds">Допуск по длительности, сек</label>
|
||||
<input id="DurationToleranceSeconds" type="number" is="emby-input" min="2" max="60" step="1" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<button is="emby-button" type="submit" class="raised button-submit block emby-button">
|
||||
<span>Сохранить</span>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
var YandexMusicConfig = {
|
||||
pluginId: 'f3b9626b-da14-4cbf-8ad1-33b92cfa6656',
|
||||
pollTimer: null
|
||||
};
|
||||
|
||||
function adminPost(path, body) {
|
||||
var options = {
|
||||
type: 'POST',
|
||||
url: ApiClient.getUrl('YandexMusic/' + path),
|
||||
dataType: 'json'
|
||||
};
|
||||
if (body) {
|
||||
options.data = JSON.stringify(body);
|
||||
options.contentType = 'application/json';
|
||||
}
|
||||
return ApiClient.ajax(options);
|
||||
}
|
||||
|
||||
function setStatus(text) {
|
||||
document.querySelector('#StatusBox').textContent = text || '';
|
||||
}
|
||||
|
||||
function stopPolling() {
|
||||
if (YandexMusicConfig.pollTimer) {
|
||||
clearTimeout(YandexMusicConfig.pollTimer);
|
||||
YandexMusicConfig.pollTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
function pollDeviceCode(deviceCode, interval) {
|
||||
YandexMusicConfig.pollTimer = setTimeout(function () {
|
||||
adminPost('DeviceCode/Poll', { DeviceCode: deviceCode }).then(function (res) {
|
||||
var status = document.querySelector('#DeviceStatus');
|
||||
if (res.Status === 'pending') {
|
||||
status.textContent = 'Ожидаем подтверждение…';
|
||||
pollDeviceCode(deviceCode, interval);
|
||||
} else if (res.Status === 'ok') {
|
||||
document.querySelector('#Token').value = res.Token || '';
|
||||
status.textContent = 'Готово, токен сохранён.';
|
||||
setStatus('Токен получен.');
|
||||
setTimeout(function () { document.querySelector('#DeviceBox').style.display = 'none'; }, 2500);
|
||||
} else {
|
||||
status.textContent = res.Error || 'Не удалось получить токен.';
|
||||
}
|
||||
}).catch(function () {
|
||||
document.querySelector('#DeviceStatus').textContent = 'Ошибка запроса.';
|
||||
});
|
||||
}, Math.max(2, interval) * 1000);
|
||||
}
|
||||
|
||||
document.querySelector('#YandexMusicConfigPage').addEventListener('pageshow', function () {
|
||||
Dashboard.showLoadingMsg();
|
||||
ApiClient.getPluginConfiguration(YandexMusicConfig.pluginId).then(function (config) {
|
||||
document.querySelector('#Token').value = config.Token || '';
|
||||
document.querySelector('#Language').value = config.Language || 'ru';
|
||||
document.querySelector('#EnableSongMetadata').checked = config.EnableSongMetadata;
|
||||
document.querySelector('#EnableAlbumMetadata').checked = config.EnableAlbumMetadata;
|
||||
document.querySelector('#EnableArtistMetadata').checked = config.EnableArtistMetadata;
|
||||
document.querySelector('#EnableImages').checked = config.EnableImages;
|
||||
document.querySelector('#EnableLyrics').checked = config.EnableLyrics;
|
||||
document.querySelector('#EnableGenres').checked = config.EnableGenres;
|
||||
document.querySelector('#EnableLabels').checked = config.EnableLabels;
|
||||
document.querySelector('#UseYandexAlbumName').checked = config.UseYandexAlbumName;
|
||||
document.querySelector('#UseYandexYear').checked = config.UseYandexYear;
|
||||
document.querySelector('#MatchThreshold').value = config.MatchThreshold;
|
||||
document.querySelector('#DurationToleranceSeconds').value = config.DurationToleranceSeconds;
|
||||
Dashboard.hideLoadingMsg();
|
||||
ApiClient.ajax({
|
||||
type: 'GET',
|
||||
url: ApiClient.getUrl('YandexMusic/Status'),
|
||||
dataType: 'json'
|
||||
}).then(function (status) {
|
||||
setStatus(status.Connected
|
||||
? (status.HasToken ? 'API доступен, токен сохранён.' : 'API доступен, токен не задан (тексты песен выключены).')
|
||||
: 'API недоступен: ' + (status.Error || ''));
|
||||
}).catch(function () {
|
||||
setStatus('Не удалось проверить состояние API.');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelector('#YandexMusicConfigForm').addEventListener('submit', function (e) {
|
||||
Dashboard.showLoadingMsg();
|
||||
ApiClient.getPluginConfiguration(YandexMusicConfig.pluginId).then(function (config) {
|
||||
config.Token = document.querySelector('#Token').value;
|
||||
config.Language = document.querySelector('#Language').value;
|
||||
config.EnableSongMetadata = document.querySelector('#EnableSongMetadata').checked;
|
||||
config.EnableAlbumMetadata = document.querySelector('#EnableAlbumMetadata').checked;
|
||||
config.EnableArtistMetadata = document.querySelector('#EnableArtistMetadata').checked;
|
||||
config.EnableImages = document.querySelector('#EnableImages').checked;
|
||||
config.EnableLyrics = document.querySelector('#EnableLyrics').checked;
|
||||
config.EnableGenres = document.querySelector('#EnableGenres').checked;
|
||||
config.EnableLabels = document.querySelector('#EnableLabels').checked;
|
||||
config.UseYandexAlbumName = document.querySelector('#UseYandexAlbumName').checked;
|
||||
config.UseYandexYear = document.querySelector('#UseYandexYear').checked;
|
||||
config.MatchThreshold = parseFloat(document.querySelector('#MatchThreshold').value) || 0.72;
|
||||
config.DurationToleranceSeconds = parseInt(document.querySelector('#DurationToleranceSeconds').value, 10) || 12;
|
||||
ApiClient.updatePluginConfiguration(YandexMusicConfig.pluginId, config).then(function (result) {
|
||||
Dashboard.processPluginConfigurationUpdateResult(result);
|
||||
});
|
||||
});
|
||||
e.preventDefault();
|
||||
return false;
|
||||
});
|
||||
|
||||
document.querySelector('#LoginButton').addEventListener('click', function () {
|
||||
stopPolling();
|
||||
Dashboard.showLoadingMsg();
|
||||
adminPost('DeviceCode').then(function (res) {
|
||||
Dashboard.hideLoadingMsg();
|
||||
document.querySelector('#DeviceBox').style.display = 'block';
|
||||
document.querySelector('#DeviceCode').textContent = res.UserCode;
|
||||
document.querySelector('#DeviceLink').href = res.VerificationUrl || 'https://ya.ru/device';
|
||||
document.querySelector('#DeviceLink').textContent = res.VerificationUrl || 'https://ya.ru/device';
|
||||
document.querySelector('#DeviceStatus').textContent = 'Ожидаем подтверждение…';
|
||||
pollDeviceCode(res.DeviceCode, res.Interval);
|
||||
}).catch(function () {
|
||||
Dashboard.hideLoadingMsg();
|
||||
setStatus('Не удалось начать вход в Яндекс.');
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelector('#LogoutButton').addEventListener('click', function () {
|
||||
adminPost('Logout').then(function () {
|
||||
document.querySelector('#Token').value = '';
|
||||
setStatus('Токен удалён.');
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelector('#CheckButton').addEventListener('click', function () {
|
||||
setStatus('Проверяем…');
|
||||
ApiClient.ajax({
|
||||
type: 'GET',
|
||||
url: ApiClient.getUrl('YandexMusic/Status'),
|
||||
dataType: 'json'
|
||||
}).then(function (status) {
|
||||
setStatus(status.Connected ? 'API доступен.' : 'API недоступен: ' + (status.Error || ''));
|
||||
}).catch(function () {
|
||||
setStatus('Ошибка проверки.');
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user