Compare commits
24
Commits
74da0d2568
..
v1.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9180da16be | ||
|
|
d3fbaef417 | ||
|
|
c02469c6d0 | ||
|
|
1b7b836b3e | ||
|
|
609a16f468 | ||
|
|
c967b062a2 | ||
|
|
a8e0dcaf37 | ||
|
|
09808a2136 | ||
|
|
8b51a910f5 | ||
|
|
9723c13bd3 | ||
|
|
52120529ff | ||
|
|
046bf6afe4 | ||
|
|
83741d7980 | ||
|
|
2f5a182afd | ||
|
|
7a9dbdafcc | ||
|
|
6277846394 | ||
|
|
d544b71939 | ||
|
|
12988e127f | ||
|
|
e9312af2c2 | ||
|
|
4291891dfd | ||
|
|
e9c9f334cd | ||
|
|
3afa1fc407 | ||
|
|
2c1143b49f | ||
|
|
7fe332f29c |
@@ -0,0 +1,58 @@
|
|||||||
|
name: 'Build Plugin'
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
paths-ignore:
|
||||||
|
- '**/*.md'
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
paths-ignore:
|
||||||
|
- '**/*.md'
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Verify .NET installation
|
||||||
|
run: dotnet --version
|
||||||
|
|
||||||
|
- name: Restore dependencies
|
||||||
|
run: dotnet restore Jellyfin.Plugin.JellyLMS.sln
|
||||||
|
|
||||||
|
- name: Build solution
|
||||||
|
run: dotnet build Jellyfin.Plugin.JellyLMS.sln --configuration Release --no-restore --no-self-contained
|
||||||
|
|
||||||
|
- name: Install JPRM
|
||||||
|
run: |
|
||||||
|
python3 -m venv /tmp/jprm-venv
|
||||||
|
/tmp/jprm-venv/bin/pip install jprm
|
||||||
|
|
||||||
|
- name: Build Jellyfin Plugin
|
||||||
|
id: jprm
|
||||||
|
run: |
|
||||||
|
# Create artifacts directory for JPRM output
|
||||||
|
mkdir -p artifacts
|
||||||
|
|
||||||
|
# Build plugin using JPRM
|
||||||
|
/tmp/jprm-venv/bin/jprm --verbosity=debug plugin build .
|
||||||
|
|
||||||
|
# Find the generated zip file
|
||||||
|
ARTIFACT=$(find . -name "*.zip" -type f -print -quit)
|
||||||
|
echo "artifact=${ARTIFACT}" >> $GITHUB_OUTPUT
|
||||||
|
echo "Found artifact: ${ARTIFACT}"
|
||||||
|
|
||||||
|
- name: Upload build artifact
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: jellylms-plugin
|
||||||
|
path: ${{ steps.jprm.outputs.artifact }}
|
||||||
|
retention-days: 30
|
||||||
|
if-no-files-found: error
|
||||||
@@ -0,0 +1,173 @@
|
|||||||
|
name: 'Release Plugin'
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*.*.*'
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
version:
|
||||||
|
description: 'Version to release (e.g., v1.0.0)'
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Verify .NET installation
|
||||||
|
run: dotnet --version
|
||||||
|
|
||||||
|
- name: Get version
|
||||||
|
id: get_version
|
||||||
|
run: |
|
||||||
|
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
||||||
|
VERSION="${{ github.event.inputs.version }}"
|
||||||
|
else
|
||||||
|
VERSION="${GITHUB_REF#refs/tags/}"
|
||||||
|
fi
|
||||||
|
echo "version=${VERSION}" >> $GITHUB_OUTPUT
|
||||||
|
echo "version_number=${VERSION#v}" >> $GITHUB_OUTPUT
|
||||||
|
echo "Building version: ${VERSION}"
|
||||||
|
|
||||||
|
- name: Update build.yaml with version
|
||||||
|
run: |
|
||||||
|
VERSION="${{ steps.get_version.outputs.version_number }}"
|
||||||
|
sed -i "s/^version:.*/version: \"${VERSION}\"/" build.yaml
|
||||||
|
cat build.yaml
|
||||||
|
|
||||||
|
- name: Restore dependencies
|
||||||
|
run: dotnet restore Jellyfin.Plugin.JellyLMS.sln
|
||||||
|
|
||||||
|
- name: Build solution
|
||||||
|
run: dotnet build Jellyfin.Plugin.JellyLMS.sln --configuration Release --no-restore --no-self-contained
|
||||||
|
|
||||||
|
- name: Install JPRM
|
||||||
|
run: |
|
||||||
|
python3 -m venv /tmp/jprm-venv
|
||||||
|
/tmp/jprm-venv/bin/pip install jprm
|
||||||
|
|
||||||
|
- name: Build Jellyfin Plugin
|
||||||
|
id: jprm
|
||||||
|
run: |
|
||||||
|
# Create artifacts directory for JPRM output
|
||||||
|
mkdir -p artifacts
|
||||||
|
|
||||||
|
# Build plugin using JPRM
|
||||||
|
/tmp/jprm-venv/bin/jprm --verbosity=debug plugin build ./
|
||||||
|
|
||||||
|
# Find the generated zip file
|
||||||
|
ARTIFACT=$(find . -name "*.zip" -type f -print -quit)
|
||||||
|
ARTIFACT_NAME=$(basename "${ARTIFACT}")
|
||||||
|
echo "artifact=${ARTIFACT}" >> $GITHUB_OUTPUT
|
||||||
|
echo "artifact_name=${ARTIFACT_NAME}" >> $GITHUB_OUTPUT
|
||||||
|
echo "Found artifact: ${ARTIFACT}"
|
||||||
|
|
||||||
|
- name: Create Release
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: |
|
||||||
|
# Get repository information
|
||||||
|
REPO_OWNER="${{ github.repository_owner }}"
|
||||||
|
REPO_NAME="${{ github.event.repository.name }}"
|
||||||
|
GITEA_URL="${{ github.server_url }}"
|
||||||
|
|
||||||
|
# Prepare release body
|
||||||
|
RELEASE_BODY="JellyLMS Jellyfin Plugin ${{ steps.get_version.outputs.version }}\n\nSee attached files for plugin installation."
|
||||||
|
RELEASE_BODY_JSON=$(echo -n "${RELEASE_BODY}" | jq -Rs .)
|
||||||
|
|
||||||
|
# Create release using Gitea API
|
||||||
|
RESPONSE=$(curl -s -w "\n%{http_code}" -X POST \
|
||||||
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
"${GITEA_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/releases" \
|
||||||
|
-d "{
|
||||||
|
\"tag_name\": \"${{ steps.get_version.outputs.version }}\",
|
||||||
|
\"name\": \"Release ${{ steps.get_version.outputs.version }}\",
|
||||||
|
\"body\": ${RELEASE_BODY_JSON},
|
||||||
|
\"draft\": false,
|
||||||
|
\"prerelease\": false
|
||||||
|
}")
|
||||||
|
|
||||||
|
HTTP_CODE=$(echo "$RESPONSE" | tail -n1)
|
||||||
|
BODY=$(echo "$RESPONSE" | sed '$d')
|
||||||
|
|
||||||
|
if [ "$HTTP_CODE" -ge 200 ] && [ "$HTTP_CODE" -lt 300 ]; then
|
||||||
|
RELEASE_ID=$(echo "$BODY" | jq -r '.id')
|
||||||
|
echo "Created release with ID: ${RELEASE_ID}"
|
||||||
|
else
|
||||||
|
echo "Failed to create release. HTTP ${HTTP_CODE}"
|
||||||
|
echo "$BODY"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Upload plugin artifact
|
||||||
|
echo "Uploading plugin artifact..."
|
||||||
|
curl -f -X POST \
|
||||||
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||||
|
-H "Content-Type: application/zip" \
|
||||||
|
--data-binary "@${{ steps.jprm.outputs.artifact }}" \
|
||||||
|
"${GITEA_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/releases/${RELEASE_ID}/assets?name=${{ steps.jprm.outputs.artifact_name }}"
|
||||||
|
|
||||||
|
# Upload build.yaml
|
||||||
|
echo "Uploading build.yaml..."
|
||||||
|
curl -f -X POST \
|
||||||
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||||
|
-H "Content-Type: application/x-yaml" \
|
||||||
|
--data-binary "@build.yaml" \
|
||||||
|
"${GITEA_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/releases/${RELEASE_ID}/assets?name=build.yaml"
|
||||||
|
|
||||||
|
echo "Release created successfully!"
|
||||||
|
echo "View at: ${GITEA_URL}/${REPO_OWNER}/${REPO_NAME}/releases/tag/${{ steps.get_version.outputs.version }}"
|
||||||
|
|
||||||
|
- name: Calculate checksum
|
||||||
|
id: checksum
|
||||||
|
run: |
|
||||||
|
CHECKSUM=$(md5sum "${{ steps.jprm.outputs.artifact }}" | awk '{print $1}')
|
||||||
|
echo "checksum=${CHECKSUM}" >> $GITHUB_OUTPUT
|
||||||
|
echo "MD5 checksum: ${CHECKSUM}"
|
||||||
|
|
||||||
|
- name: Update manifest.json
|
||||||
|
run: |
|
||||||
|
VERSION="${{ steps.get_version.outputs.version_number }}"
|
||||||
|
CHECKSUM="${{ steps.checksum.outputs.checksum }}"
|
||||||
|
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
|
||||||
|
ARTIFACT_NAME="${{ steps.jprm.outputs.artifact_name }}"
|
||||||
|
REPO_OWNER="${{ github.repository_owner }}"
|
||||||
|
REPO_NAME="${{ github.event.repository.name }}"
|
||||||
|
GITEA_URL="${{ github.server_url }}"
|
||||||
|
DOWNLOAD_URL="${GITEA_URL}/${REPO_OWNER}/${REPO_NAME}/releases/download/${{ steps.get_version.outputs.version }}/${ARTIFACT_NAME}"
|
||||||
|
|
||||||
|
# Create the new version entry
|
||||||
|
NEW_VERSION=$(cat <<EOF
|
||||||
|
{
|
||||||
|
"version": "${VERSION}",
|
||||||
|
"changelog": "Release ${VERSION}",
|
||||||
|
"targetAbi": "10.10.0.0",
|
||||||
|
"sourceUrl": "${DOWNLOAD_URL}",
|
||||||
|
"checksum": "${CHECKSUM}",
|
||||||
|
"timestamp": "${TIMESTAMP}"
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
|
||||||
|
# Prepend new version to the versions array in manifest.json
|
||||||
|
jq --argjson newver "${NEW_VERSION}" '.[0].versions = [$newver] + .[0].versions' manifest.json > manifest.tmp.json
|
||||||
|
mv manifest.tmp.json manifest.json
|
||||||
|
|
||||||
|
echo "Updated manifest.json:"
|
||||||
|
cat manifest.json
|
||||||
|
|
||||||
|
- name: Commit and push manifest
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: |
|
||||||
|
git config user.name "Gitea Actions"
|
||||||
|
git config user.email "actions@gitea.tourolle.paris"
|
||||||
|
git add manifest.json
|
||||||
|
git commit -m "Update manifest.json for ${{ steps.get_version.outputs.version }}"
|
||||||
|
git push origin HEAD:master
|
||||||
Vendored
+1
-1
@@ -7,7 +7,7 @@
|
|||||||
"name": "Launch",
|
"name": "Launch",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"preLaunchTask": "build-and-copy",
|
"preLaunchTask": "build-and-copy",
|
||||||
"program": "${config:jellyfinDir}/bin/Debug/net6.0/jellyfin.dll",
|
"program": "${config:jellyfinDir}/bin/Debug/net9.0/jellyfin.dll",
|
||||||
"args": [
|
"args": [
|
||||||
//"--nowebclient"
|
//"--nowebclient"
|
||||||
"--webdir",
|
"--webdir",
|
||||||
|
|||||||
Vendored
+4
-3
@@ -20,6 +20,7 @@
|
|||||||
"type": "shell",
|
"type": "shell",
|
||||||
"args": [
|
"args": [
|
||||||
"publish",
|
"publish",
|
||||||
|
"--configuration=Debug",
|
||||||
"${workspaceFolder}/${config:pluginName}.sln",
|
"${workspaceFolder}/${config:pluginName}.sln",
|
||||||
"/property:GenerateFullPaths=true",
|
"/property:GenerateFullPaths=true",
|
||||||
"/consoleloggerparameters:NoSummary"
|
"/consoleloggerparameters:NoSummary"
|
||||||
@@ -59,17 +60,17 @@
|
|||||||
"command": "cp",
|
"command": "cp",
|
||||||
"windows": {
|
"windows": {
|
||||||
"args": [
|
"args": [
|
||||||
"./${config:pluginName}/bin/Debug/net6.0/publish/*",
|
"./${config:pluginName}/bin/Debug/net9.0/publish/*",
|
||||||
"${config:jellyfinWindowsDataDir}/plugins/${config:pluginName}/"
|
"${config:jellyfinWindowsDataDir}/plugins/${config:pluginName}/"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"linux": {
|
"linux": {
|
||||||
"args": [
|
"args": [
|
||||||
"-r",
|
"-r",
|
||||||
"./${config:pluginName}/bin/Debug/net6.0/publish/*",
|
"./${config:pluginName}/bin/Debug/net9.0/publish/*",
|
||||||
"${config:jellyfinLinuxDataDir}/plugins/${config:pluginName}/"
|
"${config:jellyfinLinuxDataDir}/plugins/${config:pluginName}/"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
#
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jellyfin.Plugin.JellyLMS", "Jellyfin.Plugin.JellyLMS\Jellyfin.Plugin.JellyLMS.csproj", "{D921B930-CF91-406F-ACBC-08914DCD0D34}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Debug|x64 = Debug|x64
|
||||||
|
Debug|x86 = Debug|x86
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
Release|x64 = Release|x64
|
||||||
|
Release|x86 = Release|x86
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{D921B930-CF91-406F-ACBC-08914DCD0D34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{D921B930-CF91-406F-ACBC-08914DCD0D34}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{D921B930-CF91-406F-ACBC-08914DCD0D34}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{D921B930-CF91-406F-ACBC-08914DCD0D34}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{D921B930-CF91-406F-ACBC-08914DCD0D34}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{D921B930-CF91-406F-ACBC-08914DCD0D34}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{D921B930-CF91-406F-ACBC-08914DCD0D34}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{D921B930-CF91-406F-ACBC-08914DCD0D34}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{D921B930-CF91-406F-ACBC-08914DCD0D34}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{D921B930-CF91-406F-ACBC-08914DCD0D34}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{D921B930-CF91-406F-ACBC-08914DCD0D34}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{D921B930-CF91-406F-ACBC-08914DCD0D34}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
@@ -0,0 +1,443 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net.Mime;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Jellyfin.Data.Enums;
|
||||||
|
using Jellyfin.Plugin.JellyLMS.Models;
|
||||||
|
using Jellyfin.Plugin.JellyLMS.Services;
|
||||||
|
using MediaBrowser.Controller.Entities;
|
||||||
|
using MediaBrowser.Controller.Entities.Audio;
|
||||||
|
using MediaBrowser.Controller.Library;
|
||||||
|
using MediaBrowser.Model.Entities;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace Jellyfin.Plugin.JellyLMS.Api;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// REST API controller for JellyLMS operations.
|
||||||
|
/// </summary>
|
||||||
|
[ApiController]
|
||||||
|
[Route("JellyLms")]
|
||||||
|
[Authorize]
|
||||||
|
[Produces(MediaTypeNames.Application.Json)]
|
||||||
|
public class JellyLmsController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly ILmsApiClient _lmsClient;
|
||||||
|
private readonly LmsPlayerManager _playerManager;
|
||||||
|
private readonly LmsSessionManager _sessionManager;
|
||||||
|
private readonly ILibraryManager _libraryManager;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="JellyLmsController"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="lmsClient">The LMS API client.</param>
|
||||||
|
/// <param name="playerManager">The player manager.</param>
|
||||||
|
/// <param name="sessionManager">The session manager.</param>
|
||||||
|
/// <param name="libraryManager">The library manager.</param>
|
||||||
|
public JellyLmsController(
|
||||||
|
ILmsApiClient lmsClient,
|
||||||
|
LmsPlayerManager playerManager,
|
||||||
|
LmsSessionManager sessionManager,
|
||||||
|
ILibraryManager libraryManager)
|
||||||
|
{
|
||||||
|
_lmsClient = lmsClient;
|
||||||
|
_playerManager = playerManager;
|
||||||
|
_sessionManager = sessionManager;
|
||||||
|
_libraryManager = libraryManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests the connection to the LMS server.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The connection status.</returns>
|
||||||
|
[HttpPost("TestConnection")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
public async Task<ActionResult<LmsServerStatus>> TestConnection()
|
||||||
|
{
|
||||||
|
var status = await _lmsClient.TestConnectionAsync().ConfigureAwait(false);
|
||||||
|
return Ok(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all LMS players.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="refresh">Force refresh from LMS.</param>
|
||||||
|
/// <returns>List of players.</returns>
|
||||||
|
[HttpGet("Players")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
public async Task<ActionResult<List<LmsPlayer>>> GetPlayers([FromQuery] bool refresh = false)
|
||||||
|
{
|
||||||
|
var players = await _playerManager.GetPlayersAsync(refresh).ConfigureAwait(false);
|
||||||
|
return Ok(players);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a specific player by MAC address.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="mac">The player's MAC address.</param>
|
||||||
|
/// <returns>The player details.</returns>
|
||||||
|
[HttpGet("Players/{mac}")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
|
public async Task<ActionResult<LmsPlayer>> GetPlayer(string mac)
|
||||||
|
{
|
||||||
|
var player = await _playerManager.GetPlayerAsync(mac).ConfigureAwait(false);
|
||||||
|
if (player == null)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Powers on a player.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="mac">The player's MAC address.</param>
|
||||||
|
/// <returns>Success status.</returns>
|
||||||
|
[HttpPost("Players/{mac}/PowerOn")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||||
|
public async Task<ActionResult> PowerOn(string mac)
|
||||||
|
{
|
||||||
|
var success = await _lmsClient.PowerOnAsync(mac).ConfigureAwait(false);
|
||||||
|
return success ? Ok() : BadRequest("Failed to power on player");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Powers off a player.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="mac">The player's MAC address.</param>
|
||||||
|
/// <returns>Success status.</returns>
|
||||||
|
[HttpPost("Players/{mac}/PowerOff")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||||
|
public async Task<ActionResult> PowerOff(string mac)
|
||||||
|
{
|
||||||
|
var success = await _lmsClient.PowerOffAsync(mac).ConfigureAwait(false);
|
||||||
|
return success ? Ok() : BadRequest("Failed to power off player");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the volume on a player.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="mac">The player's MAC address.</param>
|
||||||
|
/// <param name="request">The volume request.</param>
|
||||||
|
/// <returns>Success status.</returns>
|
||||||
|
[HttpPost("Players/{mac}/Volume")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||||
|
public async Task<ActionResult> SetVolume(string mac, [FromBody] VolumeRequest request)
|
||||||
|
{
|
||||||
|
var success = await _lmsClient.SetVolumeAsync(mac, request.Volume).ConfigureAwait(false);
|
||||||
|
return success ? Ok() : BadRequest("Failed to set volume");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all sync groups.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>List of sync groups.</returns>
|
||||||
|
[HttpGet("SyncGroups")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
public async Task<ActionResult<List<SyncGroup>>> GetSyncGroups()
|
||||||
|
{
|
||||||
|
var groups = await _playerManager.GetSyncGroupsAsync().ConfigureAwait(false);
|
||||||
|
return Ok(groups);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a sync group.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request">The sync request.</param>
|
||||||
|
/// <returns>Success status.</returns>
|
||||||
|
[HttpPost("SyncGroups")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||||
|
public async Task<ActionResult> CreateSyncGroup([FromBody] CreateSyncGroupRequest request)
|
||||||
|
{
|
||||||
|
var success = await _playerManager.CreateSyncGroupAsync(request.MasterMac, request.SlaveMacs)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
return success ? Ok() : BadRequest("Failed to create sync group");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes a player from its sync group.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="mac">The player's MAC address.</param>
|
||||||
|
/// <returns>Success status.</returns>
|
||||||
|
[HttpDelete("SyncGroups/Players/{mac}")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||||
|
public async Task<ActionResult> UnsyncPlayer(string mac)
|
||||||
|
{
|
||||||
|
var success = await _playerManager.UnsyncPlayerAsync(mac).ConfigureAwait(false);
|
||||||
|
return success ? Ok() : BadRequest("Failed to unsync player");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Dissolves an entire sync group.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="masterMac">The master player's MAC address.</param>
|
||||||
|
/// <returns>Success status.</returns>
|
||||||
|
[HttpDelete("SyncGroups/{masterMac}")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||||
|
public async Task<ActionResult> DissolveSyncGroup(string masterMac)
|
||||||
|
{
|
||||||
|
var success = await _playerManager.DissolveSyncGroupAsync(masterMac).ConfigureAwait(false);
|
||||||
|
return success ? Ok() : BadRequest("Failed to dissolve sync group");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all active playback sessions.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>List of active sessions.</returns>
|
||||||
|
[HttpGet("Sessions")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
public ActionResult<List<LmsPlaybackSession>> GetSessions()
|
||||||
|
{
|
||||||
|
return Ok(_sessionManager.GetActiveSessions());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Starts playback of a Jellyfin item on LMS players.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request">The playback request.</param>
|
||||||
|
/// <returns>The created session.</returns>
|
||||||
|
[HttpPost("Sessions/Play")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||||
|
public async Task<ActionResult<LmsPlaybackSession>> StartPlayback([FromBody] StartPlaybackRequest request)
|
||||||
|
{
|
||||||
|
var session = await _sessionManager.StartPlaybackAsync(request.ItemId, request.PlayerMacs, request.UserId)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (session == null)
|
||||||
|
{
|
||||||
|
return BadRequest("Failed to start playback");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Pauses a playback session.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sessionId">The session ID.</param>
|
||||||
|
/// <returns>Success status.</returns>
|
||||||
|
[HttpPost("Sessions/{sessionId}/Pause")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
|
public async Task<ActionResult> PauseSession(string sessionId)
|
||||||
|
{
|
||||||
|
var success = await _sessionManager.PauseSessionAsync(sessionId).ConfigureAwait(false);
|
||||||
|
return success ? Ok() : NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Resumes a paused playback session.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sessionId">The session ID.</param>
|
||||||
|
/// <returns>Success status.</returns>
|
||||||
|
[HttpPost("Sessions/{sessionId}/Resume")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
|
public async Task<ActionResult> ResumeSession(string sessionId)
|
||||||
|
{
|
||||||
|
var success = await _sessionManager.ResumeSessionAsync(sessionId).ConfigureAwait(false);
|
||||||
|
return success ? Ok() : NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Stops a playback session.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sessionId">The session ID.</param>
|
||||||
|
/// <returns>Success status.</returns>
|
||||||
|
[HttpPost("Sessions/{sessionId}/Stop")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
|
public async Task<ActionResult> StopSession(string sessionId)
|
||||||
|
{
|
||||||
|
var success = await _sessionManager.StopSessionAsync(sessionId).ConfigureAwait(false);
|
||||||
|
return success ? Ok() : NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Seeks to a position in the playback session.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sessionId">The session ID.</param>
|
||||||
|
/// <param name="request">The seek request.</param>
|
||||||
|
/// <returns>Success status.</returns>
|
||||||
|
[HttpPost("Sessions/{sessionId}/Seek")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
|
public async Task<ActionResult> SeekSession(string sessionId, [FromBody] SeekRequest request)
|
||||||
|
{
|
||||||
|
var success = await _sessionManager.SeekAsync(sessionId, request.PositionTicks).ConfigureAwait(false);
|
||||||
|
return success ? Ok() : NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the volume for all players in a session.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sessionId">The session ID.</param>
|
||||||
|
/// <param name="request">The volume request.</param>
|
||||||
|
/// <returns>Success status.</returns>
|
||||||
|
[HttpPost("Sessions/{sessionId}/Volume")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
|
public async Task<ActionResult> SetSessionVolume(string sessionId, [FromBody] VolumeRequest request)
|
||||||
|
{
|
||||||
|
var success = await _sessionManager.SetVolumeAsync(sessionId, request.Volume).ConfigureAwait(false);
|
||||||
|
return success ? Ok() : NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Discovers file paths used by Jellyfin's music libraries.
|
||||||
|
/// Helps users configure path mappings for direct file access.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Sample file paths from each music library.</returns>
|
||||||
|
[HttpGet("DiscoverPaths")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
public ActionResult<DiscoveredPathsResponse> DiscoverPaths()
|
||||||
|
{
|
||||||
|
var response = new DiscoveredPathsResponse();
|
||||||
|
|
||||||
|
// Get sample audio files from the library
|
||||||
|
var query = new InternalItemsQuery
|
||||||
|
{
|
||||||
|
IncludeItemTypes = [BaseItemKind.Audio],
|
||||||
|
Limit = 50,
|
||||||
|
Recursive = true
|
||||||
|
};
|
||||||
|
|
||||||
|
var items = _libraryManager.GetItemsResult(query).Items;
|
||||||
|
|
||||||
|
// Extract unique path prefixes
|
||||||
|
var pathPrefixes = new HashSet<string>();
|
||||||
|
|
||||||
|
foreach (var item in items)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(item.Path))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add sample paths
|
||||||
|
if (response.SamplePaths.Count < 5)
|
||||||
|
{
|
||||||
|
response.SamplePaths.Add(item.Path);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to find common path prefixes
|
||||||
|
var path = item.Path.Replace('\\', '/');
|
||||||
|
var parts = path.Split('/');
|
||||||
|
|
||||||
|
// Build prefix from first few directory levels
|
||||||
|
if (parts.Length > 2)
|
||||||
|
{
|
||||||
|
// Try different prefix lengths to find common ones
|
||||||
|
for (var i = 2; i <= Math.Min(4, parts.Length - 1); i++)
|
||||||
|
{
|
||||||
|
var prefix = string.Join('/', parts.Take(i));
|
||||||
|
if (!string.IsNullOrEmpty(prefix) && !prefix.Contains('.', StringComparison.Ordinal))
|
||||||
|
{
|
||||||
|
pathPrefixes.Add(prefix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort prefixes by length (shorter = more general)
|
||||||
|
response.DetectedPrefixes = pathPrefixes
|
||||||
|
.OrderBy(p => p.Length)
|
||||||
|
.Take(10)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
return Ok(response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Response containing discovered file paths from Jellyfin libraries.
|
||||||
|
/// </summary>
|
||||||
|
public class DiscoveredPathsResponse
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets sample file paths from the music library.
|
||||||
|
/// </summary>
|
||||||
|
public List<string> SamplePaths { get; set; } = [];
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets detected common path prefixes.
|
||||||
|
/// </summary>
|
||||||
|
public List<string> DetectedPrefixes { get; set; } = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Request to set volume.
|
||||||
|
/// </summary>
|
||||||
|
public class VolumeRequest
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the volume level (0-100).
|
||||||
|
/// </summary>
|
||||||
|
[Range(0, 100)]
|
||||||
|
public int Volume { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Request to create a sync group.
|
||||||
|
/// </summary>
|
||||||
|
public class CreateSyncGroupRequest
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the master player MAC address.
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
public string MasterMac { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the slave player MAC addresses.
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
public List<string> SlaveMacs { get; set; } = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Request to start playback.
|
||||||
|
/// </summary>
|
||||||
|
public class StartPlaybackRequest
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the Jellyfin item ID.
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
public Guid ItemId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the LMS player MAC addresses.
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
public List<string> PlayerMacs { get; set; } = [];
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the optional user ID.
|
||||||
|
/// </summary>
|
||||||
|
public Guid? UserId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Request to seek to a position.
|
||||||
|
/// </summary>
|
||||||
|
public class SeekRequest
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the position in ticks.
|
||||||
|
/// </summary>
|
||||||
|
public long PositionTicks { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,134 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using MediaBrowser.Model.Plugins;
|
||||||
|
|
||||||
|
namespace Jellyfin.Plugin.JellyLMS.Configuration;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a path mapping between Jellyfin and LMS file paths.
|
||||||
|
/// </summary>
|
||||||
|
public class PathMapping
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the path prefix as seen by Jellyfin.
|
||||||
|
/// </summary>
|
||||||
|
public string JellyfinPath { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the same path prefix as seen by LMS.
|
||||||
|
/// </summary>
|
||||||
|
public string LmsPath { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Plugin configuration for JellyLMS.
|
||||||
|
/// </summary>
|
||||||
|
public class PluginConfiguration : BasePluginConfiguration
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="PluginConfiguration"/> class.
|
||||||
|
/// </summary>
|
||||||
|
public PluginConfiguration()
|
||||||
|
{
|
||||||
|
LmsServerUrl = "http://localhost:9000";
|
||||||
|
LmsUsername = string.Empty;
|
||||||
|
LmsPassword = string.Empty;
|
||||||
|
JellyfinServerUrl = "http://localhost:8096";
|
||||||
|
ConnectionTimeoutSeconds = 10;
|
||||||
|
EnableAutoSync = true;
|
||||||
|
DefaultPlayerMac = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the LMS server URL (e.g., http://192.168.1.100:9000).
|
||||||
|
/// </summary>
|
||||||
|
public string LmsServerUrl { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the LMS username (if authentication is enabled).
|
||||||
|
/// </summary>
|
||||||
|
public string LmsUsername { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the LMS password (if authentication is enabled).
|
||||||
|
/// </summary>
|
||||||
|
public string LmsPassword { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the Jellyfin server URL that LMS will use to stream audio.
|
||||||
|
/// This should be accessible from the LMS server.
|
||||||
|
/// </summary>
|
||||||
|
public string JellyfinServerUrl { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the connection timeout in seconds.
|
||||||
|
/// </summary>
|
||||||
|
public int ConnectionTimeoutSeconds { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating whether to automatically sync players
|
||||||
|
/// when playing to multiple devices.
|
||||||
|
/// </summary>
|
||||||
|
public bool EnableAutoSync { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the default player MAC address to use when none is specified.
|
||||||
|
/// </summary>
|
||||||
|
public string DefaultPlayerMac { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the Jellyfin API key for authenticating stream requests from LMS.
|
||||||
|
/// </summary>
|
||||||
|
public string JellyfinApiKey { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating whether to use direct file paths instead of HTTP streaming.
|
||||||
|
/// When enabled, LMS accesses files directly from shared storage, enabling native seeking.
|
||||||
|
/// </summary>
|
||||||
|
public bool UseDirectFilePath { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the media path prefix as seen by Jellyfin.
|
||||||
|
/// Used for path mapping when UseDirectFilePath is enabled.
|
||||||
|
/// Deprecated: Use PathMappings instead. Kept for backwards compatibility.
|
||||||
|
/// </summary>
|
||||||
|
public string JellyfinMediaPath { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the media path prefix as seen by LMS.
|
||||||
|
/// Used for path mapping when UseDirectFilePath is enabled.
|
||||||
|
/// Deprecated: Use PathMappings instead. Kept for backwards compatibility.
|
||||||
|
/// </summary>
|
||||||
|
public string LmsMediaPath { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the list of path mappings between Jellyfin and LMS.
|
||||||
|
/// Each mapping allows files from different locations to be played via direct file access.
|
||||||
|
/// </summary>
|
||||||
|
public List<PathMapping> PathMappings { get; set; } = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all effective path mappings, including legacy single mapping if configured.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Enumerable of all configured path mappings.</returns>
|
||||||
|
public IEnumerable<PathMapping> GetAllPathMappings()
|
||||||
|
{
|
||||||
|
// Return configured list mappings first
|
||||||
|
foreach (var mapping in PathMappings)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(mapping.JellyfinPath) && !string.IsNullOrEmpty(mapping.LmsPath))
|
||||||
|
{
|
||||||
|
yield return mapping;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fall back to legacy single mapping for backwards compatibility
|
||||||
|
if (!string.IsNullOrEmpty(JellyfinMediaPath) && !string.IsNullOrEmpty(LmsMediaPath))
|
||||||
|
{
|
||||||
|
yield return new PathMapping
|
||||||
|
{
|
||||||
|
JellyfinPath = JellyfinMediaPath,
|
||||||
|
LmsPath = LmsMediaPath
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,650 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>JellyLMS</title>
|
||||||
|
<style>
|
||||||
|
.sync-group {
|
||||||
|
border: 2px solid #00a4dc;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 12px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
background: rgba(0, 164, 220, 0.05);
|
||||||
|
}
|
||||||
|
.sync-group-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
.sync-group-players {
|
||||||
|
color: #ccc;
|
||||||
|
}
|
||||||
|
.player-sync-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 8px 0;
|
||||||
|
border-bottom: 1px solid #333;
|
||||||
|
}
|
||||||
|
.player-sync-row:last-child {
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
.player-sync-checkbox {
|
||||||
|
margin-right: 12px;
|
||||||
|
}
|
||||||
|
.player-sync-name {
|
||||||
|
flex: 1;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
.player-sync-status {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
color: #888;
|
||||||
|
font-size: 0.9em;
|
||||||
|
}
|
||||||
|
.status-dot {
|
||||||
|
width: 8px;
|
||||||
|
height: 8px;
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
.status-dot.on { background: #52b54b; }
|
||||||
|
.status-dot.standby { background: #f9a825; }
|
||||||
|
.status-dot.off { background: #f44336; }
|
||||||
|
.sync-actions {
|
||||||
|
margin-top: 15px;
|
||||||
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
#syncStatus {
|
||||||
|
margin-left: 10px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="JellyLmsConfigPage" 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">
|
||||||
|
<h2>JellyLMS Configuration</h2>
|
||||||
|
<p>Configure the connection between Jellyfin and Logitech Media Server (LMS) for multi-room audio playback.</p>
|
||||||
|
|
||||||
|
<form id="JellyLmsConfigForm">
|
||||||
|
<div class="verticalSection">
|
||||||
|
<h3>LMS Server Settings</h3>
|
||||||
|
|
||||||
|
<div class="inputContainer">
|
||||||
|
<label class="inputLabel inputLabelUnfocused" for="LmsServerUrl">LMS Server URL</label>
|
||||||
|
<input id="LmsServerUrl" name="LmsServerUrl" type="url" is="emby-input" />
|
||||||
|
<div class="fieldDescription">The URL of your LMS server (e.g., http://192.168.1.100:9000)</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="inputContainer">
|
||||||
|
<label class="inputLabel inputLabelUnfocused" for="LmsUsername">LMS Username (optional)</label>
|
||||||
|
<input id="LmsUsername" name="LmsUsername" type="text" is="emby-input" />
|
||||||
|
<div class="fieldDescription">Username if LMS authentication is enabled</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="inputContainer">
|
||||||
|
<label class="inputLabel inputLabelUnfocused" for="LmsPassword">LMS Password (optional)</label>
|
||||||
|
<input id="LmsPassword" name="LmsPassword" type="password" is="emby-input" />
|
||||||
|
<div class="fieldDescription">Password if LMS authentication is enabled</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<button is="emby-button" type="button" id="btnTestConnection" class="raised button-alt block emby-button">
|
||||||
|
<span>Test Connection</span>
|
||||||
|
</button>
|
||||||
|
<div id="connectionStatus" style="margin-top: 10px;"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="verticalSection">
|
||||||
|
<h3>Jellyfin Server Settings</h3>
|
||||||
|
|
||||||
|
<div class="inputContainer">
|
||||||
|
<label class="inputLabel inputLabelUnfocused" for="JellyfinServerUrl">Jellyfin Server URL</label>
|
||||||
|
<input id="JellyfinServerUrl" name="JellyfinServerUrl" type="url" is="emby-input" />
|
||||||
|
<div class="fieldDescription">The URL that LMS will use to stream audio from Jellyfin. This must be accessible from the LMS server (e.g., http://192.168.1.4:8096).</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="inputContainer">
|
||||||
|
<label class="inputLabel inputLabelUnfocused" for="JellyfinApiKey">Jellyfin API Key</label>
|
||||||
|
<input id="JellyfinApiKey" name="JellyfinApiKey" type="password" is="emby-input" />
|
||||||
|
<div class="fieldDescription">API key for LMS to authenticate with Jellyfin. Create one in Dashboard > API Keys.</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="verticalSection">
|
||||||
|
<h3>Playback Settings</h3>
|
||||||
|
|
||||||
|
<div class="inputContainer">
|
||||||
|
<label class="inputLabel inputLabelUnfocused" for="ConnectionTimeoutSeconds">Connection Timeout (seconds)</label>
|
||||||
|
<input id="ConnectionTimeoutSeconds" name="ConnectionTimeoutSeconds" type="number" is="emby-input" min="5" max="60" />
|
||||||
|
<div class="fieldDescription">Timeout for LMS API requests</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="checkboxContainer checkboxContainer-withDescription">
|
||||||
|
<label class="emby-checkbox-label">
|
||||||
|
<input id="EnableAutoSync" name="EnableAutoSync" type="checkbox" is="emby-checkbox" />
|
||||||
|
<span>Enable Auto-Sync</span>
|
||||||
|
</label>
|
||||||
|
<div class="fieldDescription checkboxFieldDescription">Automatically sync players when playing to multiple devices</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="inputContainer" style="margin-top: 15px;">
|
||||||
|
<label class="inputLabel inputLabelUnfocused" for="DefaultPlayerMac">Default Player</label>
|
||||||
|
<select is="emby-select" id="DefaultPlayerMac" name="DefaultPlayerMac" class="emby-select-withcolor emby-select">
|
||||||
|
<option value="">None</option>
|
||||||
|
</select>
|
||||||
|
<div class="fieldDescription">Default player to use when none is specified</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="verticalSection">
|
||||||
|
<h3>Direct File Access (Optional)</h3>
|
||||||
|
<p class="fieldDescription">If LMS and Jellyfin share the same storage (e.g., NAS), enable direct file access for native seeking support. This provides smooth seeking without audio restart.</p>
|
||||||
|
|
||||||
|
<div class="checkboxContainer checkboxContainer-withDescription">
|
||||||
|
<label class="emby-checkbox-label">
|
||||||
|
<input id="UseDirectFilePath" name="UseDirectFilePath" type="checkbox" is="emby-checkbox" />
|
||||||
|
<span>Enable Direct File Access</span>
|
||||||
|
</label>
|
||||||
|
<div class="fieldDescription checkboxFieldDescription">When enabled, LMS will access files directly instead of streaming via HTTP</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="directPathSettings" style="margin-top: 15px;">
|
||||||
|
<h4 style="margin-bottom: 10px;">Path Mappings</h4>
|
||||||
|
<p class="fieldDescription">Map Jellyfin paths to LMS paths. Add multiple mappings if your music and podcasts are in different locations.</p>
|
||||||
|
|
||||||
|
<div style="margin-bottom: 15px;">
|
||||||
|
<button is="emby-button" type="button" id="btnDiscoverPaths" class="raised button-alt emby-button">
|
||||||
|
<span>Discover Jellyfin Paths</span>
|
||||||
|
</button>
|
||||||
|
<span id="discoverStatus" style="margin-left: 10px;"></span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="discoveredPaths" style="display: none; margin-bottom: 15px; padding: 10px; background: rgba(0,0,0,0.2); border-radius: 4px;">
|
||||||
|
<strong>Detected Jellyfin paths:</strong>
|
||||||
|
<ul id="detectedPrefixList" style="margin: 5px 0; padding-left: 20px;"></ul>
|
||||||
|
<div class="fieldDescription">Click a path to use it as the Jellyfin path in a new mapping</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="pathMappingsList">
|
||||||
|
<!-- Dynamic path mappings will be added here -->
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="margin-top: 10px;">
|
||||||
|
<button is="emby-button" type="button" id="btnAddMapping" class="raised button-alt emby-button">
|
||||||
|
<span>+ Add Mapping</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="verticalSection">
|
||||||
|
<h3>Player Sync</h3>
|
||||||
|
<p class="fieldDescription">Select players to sync together for multi-room audio. Synced players play in perfect sync.</p>
|
||||||
|
|
||||||
|
<div id="currentSyncGroups">
|
||||||
|
<!-- Existing sync groups shown here -->
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="playerSyncList">
|
||||||
|
<p>Loading players...</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="sync-actions">
|
||||||
|
<button is="emby-button" type="button" id="btnSyncSelected" class="raised button-submit emby-button" disabled>
|
||||||
|
<span>Sync Selected</span>
|
||||||
|
</button>
|
||||||
|
<button is="emby-button" type="button" id="btnRefreshPlayers" class="raised button-alt emby-button">
|
||||||
|
<span>Refresh</span>
|
||||||
|
</button>
|
||||||
|
<span id="syncStatus"></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<button is="emby-button" type="submit" class="raised button-submit block emby-button">
|
||||||
|
<span>Save</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script type="text/javascript">
|
||||||
|
var JellyLmsConfig = {
|
||||||
|
pluginUniqueId: 'a5b8c9d0-1e2f-3a4b-5c6d-7e8f9a0b1c2d',
|
||||||
|
players: [],
|
||||||
|
syncGroups: []
|
||||||
|
};
|
||||||
|
|
||||||
|
function getStatusClass(player) {
|
||||||
|
if (!player.IsConnected) return 'off';
|
||||||
|
return player.IsPoweredOn ? 'on' : 'standby';
|
||||||
|
}
|
||||||
|
|
||||||
|
function getStatusText(player) {
|
||||||
|
if (!player.IsConnected) return 'Disconnected';
|
||||||
|
return player.IsPoweredOn ? 'On' : 'Standby';
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadPlayers() {
|
||||||
|
var defaultSelect = document.querySelector('#DefaultPlayerMac');
|
||||||
|
var currentDefault = defaultSelect.value;
|
||||||
|
|
||||||
|
ApiClient.ajax({
|
||||||
|
url: ApiClient.getUrl('JellyLms/Players', { refresh: true }),
|
||||||
|
type: 'GET',
|
||||||
|
dataType: 'json'
|
||||||
|
}).then(function(players) {
|
||||||
|
JellyLmsConfig.players = players || [];
|
||||||
|
defaultSelect.innerHTML = '<option value="">None</option>';
|
||||||
|
|
||||||
|
players.forEach(function(player) {
|
||||||
|
var option = document.createElement('option');
|
||||||
|
option.value = player.MacAddress;
|
||||||
|
option.text = player.Name;
|
||||||
|
if (player.MacAddress === currentDefault) {
|
||||||
|
option.selected = true;
|
||||||
|
}
|
||||||
|
defaultSelect.appendChild(option);
|
||||||
|
});
|
||||||
|
|
||||||
|
renderPlayerList();
|
||||||
|
}).catch(function(err) {
|
||||||
|
document.querySelector('#playerSyncList').innerHTML = '<p style="color: red;">Error loading players. Check LMS connection.</p>';
|
||||||
|
console.error('Error loading players:', err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadSyncGroups() {
|
||||||
|
ApiClient.ajax({
|
||||||
|
url: ApiClient.getUrl('JellyLms/SyncGroups'),
|
||||||
|
type: 'GET',
|
||||||
|
dataType: 'json'
|
||||||
|
}).then(function(groups) {
|
||||||
|
JellyLmsConfig.syncGroups = groups || [];
|
||||||
|
renderSyncGroups();
|
||||||
|
renderPlayerList();
|
||||||
|
}).catch(function(err) {
|
||||||
|
console.error('Error loading sync groups:', err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderSyncGroups() {
|
||||||
|
var container = document.querySelector('#currentSyncGroups');
|
||||||
|
var groups = JellyLmsConfig.syncGroups;
|
||||||
|
|
||||||
|
if (!groups || groups.length === 0) {
|
||||||
|
container.innerHTML = '';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var html = '';
|
||||||
|
groups.forEach(function(group) {
|
||||||
|
var playerNames = [];
|
||||||
|
var masterPlayer = JellyLmsConfig.players.find(function(p) { return p.MacAddress === group.MasterMac; });
|
||||||
|
if (masterPlayer) playerNames.push(masterPlayer.Name);
|
||||||
|
|
||||||
|
group.SlaveMacs.forEach(function(mac) {
|
||||||
|
var player = JellyLmsConfig.players.find(function(p) { return p.MacAddress === mac; });
|
||||||
|
if (player) playerNames.push(player.Name);
|
||||||
|
});
|
||||||
|
|
||||||
|
html += '<div class="sync-group">';
|
||||||
|
html += '<div class="sync-group-header">';
|
||||||
|
html += '<span class="sync-group-players">' + playerNames.join(' + ') + '</span>';
|
||||||
|
html += '<button is="emby-button" type="button" class="raised button-alt emby-button btnUnsyncGroup" data-master="' + group.MasterMac + '">';
|
||||||
|
html += '<span>Unsync</span>';
|
||||||
|
html += '</button>';
|
||||||
|
html += '</div>';
|
||||||
|
html += '</div>';
|
||||||
|
});
|
||||||
|
|
||||||
|
container.innerHTML = html;
|
||||||
|
|
||||||
|
container.querySelectorAll('.btnUnsyncGroup').forEach(function(btn) {
|
||||||
|
btn.addEventListener('click', function() {
|
||||||
|
unsyncGroup(this.getAttribute('data-master'));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderPlayerList() {
|
||||||
|
var container = document.querySelector('#playerSyncList');
|
||||||
|
var players = JellyLmsConfig.players;
|
||||||
|
|
||||||
|
if (!players || players.length === 0) {
|
||||||
|
container.innerHTML = '<p>No players found. Make sure LMS is running.</p>';
|
||||||
|
updateSyncButton();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get MACs of already synced players
|
||||||
|
var syncedMacs = new Set();
|
||||||
|
JellyLmsConfig.syncGroups.forEach(function(group) {
|
||||||
|
syncedMacs.add(group.MasterMac);
|
||||||
|
group.SlaveMacs.forEach(function(mac) { syncedMacs.add(mac); });
|
||||||
|
});
|
||||||
|
|
||||||
|
// Only show unsynced players
|
||||||
|
var unsyncedPlayers = players.filter(function(p) {
|
||||||
|
return !syncedMacs.has(p.MacAddress);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (unsyncedPlayers.length === 0) {
|
||||||
|
container.innerHTML = '<p>All players are synced.</p>';
|
||||||
|
updateSyncButton();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var html = '';
|
||||||
|
unsyncedPlayers.forEach(function(player) {
|
||||||
|
var statusClass = getStatusClass(player);
|
||||||
|
html += '<div class="player-sync-row">';
|
||||||
|
html += '<input type="checkbox" class="player-sync-checkbox" data-mac="' + player.MacAddress + '" id="sync-' + player.MacAddress + '">';
|
||||||
|
html += '<label class="player-sync-name" for="sync-' + player.MacAddress + '">' + player.Name + '</label>';
|
||||||
|
html += '<div class="player-sync-status">';
|
||||||
|
html += '<span class="status-dot ' + statusClass + '"></span>';
|
||||||
|
html += '<span>' + getStatusText(player) + '</span>';
|
||||||
|
html += '</div>';
|
||||||
|
html += '</div>';
|
||||||
|
});
|
||||||
|
|
||||||
|
container.innerHTML = html;
|
||||||
|
|
||||||
|
// Add change listeners
|
||||||
|
container.querySelectorAll('.player-sync-checkbox').forEach(function(cb) {
|
||||||
|
cb.addEventListener('change', updateSyncButton);
|
||||||
|
});
|
||||||
|
|
||||||
|
updateSyncButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSelectedMacs() {
|
||||||
|
var checkboxes = document.querySelectorAll('.player-sync-checkbox:checked');
|
||||||
|
var macs = [];
|
||||||
|
checkboxes.forEach(function(cb) {
|
||||||
|
macs.push(cb.getAttribute('data-mac'));
|
||||||
|
});
|
||||||
|
return macs;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateSyncButton() {
|
||||||
|
var btn = document.querySelector('#btnSyncSelected');
|
||||||
|
var selected = getSelectedMacs();
|
||||||
|
btn.disabled = selected.length < 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncSelected() {
|
||||||
|
var macs = getSelectedMacs();
|
||||||
|
if (macs.length < 2) return;
|
||||||
|
|
||||||
|
var statusDiv = document.querySelector('#syncStatus');
|
||||||
|
statusDiv.innerHTML = '<span style="color: orange;">Syncing...</span>';
|
||||||
|
|
||||||
|
// First MAC becomes master (arbitrary, user doesn't need to know)
|
||||||
|
var masterMac = macs[0];
|
||||||
|
var slaveMacs = macs.slice(1);
|
||||||
|
|
||||||
|
ApiClient.ajax({
|
||||||
|
url: ApiClient.getUrl('JellyLms/SyncGroups'),
|
||||||
|
type: 'POST',
|
||||||
|
contentType: 'application/json',
|
||||||
|
data: JSON.stringify({
|
||||||
|
MasterMac: masterMac,
|
||||||
|
SlaveMacs: slaveMacs
|
||||||
|
})
|
||||||
|
}).then(function() {
|
||||||
|
statusDiv.innerHTML = '<span style="color: green;">Synced!</span>';
|
||||||
|
setTimeout(function() {
|
||||||
|
statusDiv.innerHTML = '';
|
||||||
|
loadSyncGroups();
|
||||||
|
}, 1500);
|
||||||
|
}).catch(function(err) {
|
||||||
|
statusDiv.innerHTML = '<span style="color: red;">Failed to sync.</span>';
|
||||||
|
console.error('Error syncing:', err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function unsyncGroup(masterMac) {
|
||||||
|
var statusDiv = document.querySelector('#syncStatus');
|
||||||
|
statusDiv.innerHTML = '<span style="color: orange;">Unsyncing...</span>';
|
||||||
|
|
||||||
|
ApiClient.ajax({
|
||||||
|
url: ApiClient.getUrl('JellyLms/SyncGroups/' + encodeURIComponent(masterMac)),
|
||||||
|
type: 'DELETE'
|
||||||
|
}).then(function() {
|
||||||
|
statusDiv.innerHTML = '';
|
||||||
|
loadSyncGroups();
|
||||||
|
}).catch(function(err) {
|
||||||
|
statusDiv.innerHTML = '<span style="color: red;">Failed to unsync.</span>';
|
||||||
|
console.error('Error unsyncing:', err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function testConnection() {
|
||||||
|
var statusDiv = document.querySelector('#connectionStatus');
|
||||||
|
statusDiv.innerHTML = '<span style="color: orange;">Testing connection...</span>';
|
||||||
|
|
||||||
|
ApiClient.ajax({
|
||||||
|
url: ApiClient.getUrl('JellyLms/TestConnection'),
|
||||||
|
type: 'POST',
|
||||||
|
dataType: 'json'
|
||||||
|
}).then(function(result) {
|
||||||
|
if (result.IsConnected) {
|
||||||
|
statusDiv.innerHTML = '<span style="color: green;">Connected! Found ' + result.PlayerCount + ' player(s).</span>';
|
||||||
|
loadPlayers();
|
||||||
|
loadSyncGroups();
|
||||||
|
} else {
|
||||||
|
statusDiv.innerHTML = '<span style="color: red;">Connection failed: ' + (result.LastError || 'Unknown error') + '</span>';
|
||||||
|
}
|
||||||
|
}).catch(function(err) {
|
||||||
|
statusDiv.innerHTML = '<span style="color: red;">Connection failed. Check the server URL.</span>';
|
||||||
|
console.error('Connection test failed:', err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Path Mapping Functions
|
||||||
|
function renderPathMappings(mappings) {
|
||||||
|
var container = document.querySelector('#pathMappingsList');
|
||||||
|
if (!mappings || mappings.length === 0) {
|
||||||
|
container.innerHTML = '<p class="fieldDescription">No path mappings configured. Click "Discover Jellyfin Paths" to get started.</p>';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var html = '';
|
||||||
|
mappings.forEach(function(mapping, index) {
|
||||||
|
html += '<div class="path-mapping-row" style="display: flex; gap: 10px; align-items: flex-end; margin-bottom: 10px; padding: 10px; background: rgba(0,0,0,0.1); border-radius: 4px;">';
|
||||||
|
html += '<div style="flex: 1;">';
|
||||||
|
html += '<label class="inputLabel inputLabelUnfocused">Jellyfin Path</label>';
|
||||||
|
html += '<input type="text" is="emby-input" class="mapping-jellyfin-path" data-index="' + index + '" value="' + (mapping.JellyfinPath || '') + '" placeholder="/media/music" />';
|
||||||
|
html += '</div>';
|
||||||
|
html += '<div style="flex: 1;">';
|
||||||
|
html += '<label class="inputLabel inputLabelUnfocused">LMS Path</label>';
|
||||||
|
html += '<input type="text" is="emby-input" class="mapping-lms-path" data-index="' + index + '" value="' + (mapping.LmsPath || '') + '" placeholder="/mnt/music" />';
|
||||||
|
html += '</div>';
|
||||||
|
html += '<button is="emby-button" type="button" class="raised button-alt emby-button btnRemoveMapping" data-index="' + index + '" style="margin-bottom: 0;">';
|
||||||
|
html += '<span>Remove</span>';
|
||||||
|
html += '</button>';
|
||||||
|
html += '</div>';
|
||||||
|
});
|
||||||
|
container.innerHTML = html;
|
||||||
|
|
||||||
|
// Add remove handlers
|
||||||
|
container.querySelectorAll('.btnRemoveMapping').forEach(function(btn) {
|
||||||
|
btn.addEventListener('click', function() {
|
||||||
|
var idx = parseInt(this.getAttribute('data-index'));
|
||||||
|
JellyLmsConfig.pathMappings.splice(idx, 1);
|
||||||
|
renderPathMappings(JellyLmsConfig.pathMappings);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Update stored mappings when inputs change
|
||||||
|
container.querySelectorAll('.mapping-jellyfin-path, .mapping-lms-path').forEach(function(input) {
|
||||||
|
input.addEventListener('change', function() {
|
||||||
|
var idx = parseInt(this.getAttribute('data-index'));
|
||||||
|
if (this.classList.contains('mapping-jellyfin-path')) {
|
||||||
|
JellyLmsConfig.pathMappings[idx].JellyfinPath = this.value;
|
||||||
|
} else {
|
||||||
|
JellyLmsConfig.pathMappings[idx].LmsPath = this.value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function addPathMapping(jellyfinPath, lmsPath) {
|
||||||
|
JellyLmsConfig.pathMappings = JellyLmsConfig.pathMappings || [];
|
||||||
|
JellyLmsConfig.pathMappings.push({
|
||||||
|
JellyfinPath: jellyfinPath || '',
|
||||||
|
LmsPath: lmsPath || ''
|
||||||
|
});
|
||||||
|
renderPathMappings(JellyLmsConfig.pathMappings);
|
||||||
|
}
|
||||||
|
|
||||||
|
function discoverPaths() {
|
||||||
|
var statusDiv = document.querySelector('#discoverStatus');
|
||||||
|
statusDiv.innerHTML = '<span style="color: orange;">Discovering...</span>';
|
||||||
|
|
||||||
|
ApiClient.ajax({
|
||||||
|
url: ApiClient.getUrl('JellyLms/DiscoverPaths'),
|
||||||
|
type: 'GET',
|
||||||
|
dataType: 'json'
|
||||||
|
}).then(function(result) {
|
||||||
|
statusDiv.innerHTML = '';
|
||||||
|
var discoveredDiv = document.querySelector('#discoveredPaths');
|
||||||
|
var prefixList = document.querySelector('#detectedPrefixList');
|
||||||
|
|
||||||
|
if (result.DetectedPrefixes && result.DetectedPrefixes.length > 0) {
|
||||||
|
discoveredDiv.style.display = 'block';
|
||||||
|
var html = '';
|
||||||
|
result.DetectedPrefixes.forEach(function(prefix) {
|
||||||
|
html += '<li><a href="#" class="detected-prefix-link" data-path="' + prefix + '" style="color: #00a4dc;">' + prefix + '</a></li>';
|
||||||
|
});
|
||||||
|
prefixList.innerHTML = html;
|
||||||
|
|
||||||
|
// Add click handlers to use detected paths
|
||||||
|
prefixList.querySelectorAll('.detected-prefix-link').forEach(function(link) {
|
||||||
|
link.addEventListener('click', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
addPathMapping(this.getAttribute('data-path'), '');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
discoveredDiv.style.display = 'block';
|
||||||
|
prefixList.innerHTML = '<li>No audio files found in library</li>';
|
||||||
|
}
|
||||||
|
}).catch(function(err) {
|
||||||
|
statusDiv.innerHTML = '<span style="color: red;">Discovery failed</span>';
|
||||||
|
console.error('Path discovery failed:', err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPathMappingsFromUI() {
|
||||||
|
var mappings = [];
|
||||||
|
document.querySelectorAll('.path-mapping-row').forEach(function(row) {
|
||||||
|
var jellyfinPath = row.querySelector('.mapping-jellyfin-path').value;
|
||||||
|
var lmsPath = row.querySelector('.mapping-lms-path').value;
|
||||||
|
if (jellyfinPath || lmsPath) {
|
||||||
|
mappings.push({ JellyfinPath: jellyfinPath, LmsPath: lmsPath });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return mappings;
|
||||||
|
}
|
||||||
|
|
||||||
|
document.querySelector('#JellyLmsConfigPage')
|
||||||
|
.addEventListener('pageshow', function() {
|
||||||
|
Dashboard.showLoadingMsg();
|
||||||
|
ApiClient.getPluginConfiguration(JellyLmsConfig.pluginUniqueId).then(function (config) {
|
||||||
|
document.querySelector('#LmsServerUrl').value = config.LmsServerUrl || 'http://localhost:9000';
|
||||||
|
document.querySelector('#LmsUsername').value = config.LmsUsername || '';
|
||||||
|
document.querySelector('#LmsPassword').value = config.LmsPassword || '';
|
||||||
|
document.querySelector('#JellyfinServerUrl').value = config.JellyfinServerUrl || 'http://localhost:8096';
|
||||||
|
document.querySelector('#JellyfinApiKey').value = config.JellyfinApiKey || '';
|
||||||
|
document.querySelector('#ConnectionTimeoutSeconds').value = config.ConnectionTimeoutSeconds || 10;
|
||||||
|
document.querySelector('#EnableAutoSync').checked = config.EnableAutoSync !== false;
|
||||||
|
document.querySelector('#DefaultPlayerMac').value = config.DefaultPlayerMac || '';
|
||||||
|
document.querySelector('#UseDirectFilePath').checked = config.UseDirectFilePath || false;
|
||||||
|
|
||||||
|
// Load path mappings (new list format, with fallback to legacy single mapping)
|
||||||
|
JellyLmsConfig.pathMappings = config.PathMappings || [];
|
||||||
|
// If no list mappings but legacy single mapping exists, show it
|
||||||
|
if (JellyLmsConfig.pathMappings.length === 0 && config.JellyfinMediaPath && config.LmsMediaPath) {
|
||||||
|
JellyLmsConfig.pathMappings = [{
|
||||||
|
JellyfinPath: config.JellyfinMediaPath,
|
||||||
|
LmsPath: config.LmsMediaPath
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
renderPathMappings(JellyLmsConfig.pathMappings);
|
||||||
|
|
||||||
|
Dashboard.hideLoadingMsg();
|
||||||
|
|
||||||
|
loadPlayers();
|
||||||
|
loadSyncGroups();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
document.querySelector('#btnTestConnection')
|
||||||
|
.addEventListener('click', function() {
|
||||||
|
ApiClient.getPluginConfiguration(JellyLmsConfig.pluginUniqueId).then(function (config) {
|
||||||
|
config.LmsServerUrl = document.querySelector('#LmsServerUrl').value;
|
||||||
|
config.LmsUsername = document.querySelector('#LmsUsername').value;
|
||||||
|
config.LmsPassword = document.querySelector('#LmsPassword').value;
|
||||||
|
ApiClient.updatePluginConfiguration(JellyLmsConfig.pluginUniqueId, config).then(function() {
|
||||||
|
testConnection();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
document.querySelector('#btnRefreshPlayers')
|
||||||
|
.addEventListener('click', function() {
|
||||||
|
loadPlayers();
|
||||||
|
loadSyncGroups();
|
||||||
|
});
|
||||||
|
|
||||||
|
document.querySelector('#btnSyncSelected')
|
||||||
|
.addEventListener('click', function() {
|
||||||
|
syncSelected();
|
||||||
|
});
|
||||||
|
|
||||||
|
document.querySelector('#JellyLmsConfigForm')
|
||||||
|
.addEventListener('submit', function(e) {
|
||||||
|
Dashboard.showLoadingMsg();
|
||||||
|
ApiClient.getPluginConfiguration(JellyLmsConfig.pluginUniqueId).then(function (config) {
|
||||||
|
config.LmsServerUrl = document.querySelector('#LmsServerUrl').value;
|
||||||
|
config.LmsUsername = document.querySelector('#LmsUsername').value;
|
||||||
|
config.LmsPassword = document.querySelector('#LmsPassword').value;
|
||||||
|
config.JellyfinServerUrl = document.querySelector('#JellyfinServerUrl').value;
|
||||||
|
config.JellyfinApiKey = document.querySelector('#JellyfinApiKey').value;
|
||||||
|
config.ConnectionTimeoutSeconds = parseInt(document.querySelector('#ConnectionTimeoutSeconds').value) || 10;
|
||||||
|
config.EnableAutoSync = document.querySelector('#EnableAutoSync').checked;
|
||||||
|
config.DefaultPlayerMac = document.querySelector('#DefaultPlayerMac').value;
|
||||||
|
config.UseDirectFilePath = document.querySelector('#UseDirectFilePath').checked;
|
||||||
|
// Save path mappings (clear legacy single mapping when using list)
|
||||||
|
config.PathMappings = getPathMappingsFromUI();
|
||||||
|
config.JellyfinMediaPath = '';
|
||||||
|
config.LmsMediaPath = '';
|
||||||
|
ApiClient.updatePluginConfiguration(JellyLmsConfig.pluginUniqueId, config).then(function (result) {
|
||||||
|
Dashboard.processPluginConfigurationUpdateResult(result);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
document.querySelector('#btnDiscoverPaths')
|
||||||
|
.addEventListener('click', function() {
|
||||||
|
discoverPaths();
|
||||||
|
});
|
||||||
|
|
||||||
|
document.querySelector('#btnAddMapping')
|
||||||
|
.addEventListener('click', function() {
|
||||||
|
addPathMapping('', '');
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
+9
-5
@@ -1,8 +1,8 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
<RootNamespace>Jellyfin.Plugin.Template</RootNamespace>
|
<RootNamespace>Jellyfin.Plugin.JellyLMS</RootNamespace>
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
@@ -11,13 +11,17 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Jellyfin.Controller" Version="10.8.13" />
|
<PackageReference Include="Jellyfin.Controller" Version="10.11.0" >
|
||||||
<PackageReference Include="Jellyfin.Model" Version="10.8.13" />
|
<ExcludeAssets>runtime</ExcludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Jellyfin.Model" Version="10.11.0">
|
||||||
|
<ExcludeAssets>runtime</ExcludeAssets>
|
||||||
|
</PackageReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="SerilogAnalyzer" Version="0.15.0" PrivateAssets="All" />
|
<PackageReference Include="SerilogAnalyzer" Version="0.15.0" PrivateAssets="All" />
|
||||||
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.507" PrivateAssets="All" />
|
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556" PrivateAssets="All" />
|
||||||
<PackageReference Include="SmartAnalyzers.MultithreadingAnalyzer" Version="1.1.31" PrivateAssets="All" />
|
<PackageReference Include="SmartAnalyzers.MultithreadingAnalyzer" Version="1.1.31" PrivateAssets="All" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
@@ -0,0 +1,254 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace Jellyfin.Plugin.JellyLMS.Models;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// JSON-RPC request for LMS API.
|
||||||
|
/// </summary>
|
||||||
|
public class LmsJsonRpcRequest
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the request ID.
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("id")]
|
||||||
|
public int Id { get; set; } = 1;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the method name (always "slim.request").
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("method")]
|
||||||
|
public string Method { get; set; } = "slim.request";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the parameters [playerMac, [command, args...]].
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("params")]
|
||||||
|
public object[] Params { get; set; } = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// JSON-RPC response from LMS API.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The result type.</typeparam>
|
||||||
|
public class LmsJsonRpcResponse<T>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the request ID.
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("id")]
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the result data.
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("result")]
|
||||||
|
public T? Result { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets any error message.
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("error")]
|
||||||
|
public string? Error { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Player count response.
|
||||||
|
/// </summary>
|
||||||
|
public class PlayerCountResult
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the count value.
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("_count")]
|
||||||
|
public int Count { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Players list response.
|
||||||
|
/// </summary>
|
||||||
|
public class PlayersListResult
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the player count.
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("count")]
|
||||||
|
public int Count { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the list of players.
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("players_loop")]
|
||||||
|
public List<LmsPlayerInfo> Players { get; set; } = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Player info from LMS API.
|
||||||
|
/// </summary>
|
||||||
|
public class LmsPlayerInfo
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the player name.
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("name")]
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the player ID (MAC address).
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("playerid")]
|
||||||
|
public string PlayerId { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the player IP address.
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("ip")]
|
||||||
|
public string Ip { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets whether the player is connected.
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("connected")]
|
||||||
|
public int Connected { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the power state.
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("power")]
|
||||||
|
public int Power { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the player model.
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("model")]
|
||||||
|
public string Model { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the player model name.
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("modelname")]
|
||||||
|
public string ModelName { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Player status response.
|
||||||
|
/// </summary>
|
||||||
|
public class PlayerStatusResult
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the player name.
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("player_name")]
|
||||||
|
public string PlayerName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the player connected state.
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("player_connected")]
|
||||||
|
public int PlayerConnected { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the power state.
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("power")]
|
||||||
|
public int Power { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the playback mode (play, pause, stop).
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("mode")]
|
||||||
|
public string Mode { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the current time position in seconds.
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("time")]
|
||||||
|
public double Time { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the mixer volume (0-100).
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("mixer volume")]
|
||||||
|
public int Volume { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the total duration in seconds.
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("duration")]
|
||||||
|
public double Duration { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the sync master MAC address.
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("sync_master")]
|
||||||
|
public string? SyncMaster { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the list of synced player MACs.
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("sync_slaves")]
|
||||||
|
public string? SyncSlaves { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the current track title.
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("current_title")]
|
||||||
|
public string? CurrentTitle { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// LMS server status.
|
||||||
|
/// </summary>
|
||||||
|
public class LmsServerStatus
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the server version.
|
||||||
|
/// </summary>
|
||||||
|
public string Version { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the player count.
|
||||||
|
/// </summary>
|
||||||
|
public int PlayerCount { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets whether the server is reachable.
|
||||||
|
/// </summary>
|
||||||
|
public bool IsConnected { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the last error message.
|
||||||
|
/// </summary>
|
||||||
|
public string? LastError { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sync group information.
|
||||||
|
/// </summary>
|
||||||
|
public class SyncGroup
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the master player MAC address.
|
||||||
|
/// </summary>
|
||||||
|
public string MasterMac { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the master player name.
|
||||||
|
/// </summary>
|
||||||
|
public string MasterName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the slave player MAC addresses.
|
||||||
|
/// </summary>
|
||||||
|
public List<string> SlaveMacs { get; set; } = [];
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the slave player names.
|
||||||
|
/// </summary>
|
||||||
|
public List<string> SlaveNames { get; set; } = [];
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the total number of players in this sync group.
|
||||||
|
/// </summary>
|
||||||
|
public int PlayerCount => 1 + SlaveMacs.Count;
|
||||||
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Jellyfin.Plugin.JellyLMS.Models;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents the current playback state.
|
||||||
|
/// </summary>
|
||||||
|
public enum PlaybackState
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Playback is stopped.
|
||||||
|
/// </summary>
|
||||||
|
Stopped,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Playback is active.
|
||||||
|
/// </summary>
|
||||||
|
Playing,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Playback is paused.
|
||||||
|
/// </summary>
|
||||||
|
Paused
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents an active playback session bridging Jellyfin to LMS.
|
||||||
|
/// </summary>
|
||||||
|
public class LmsPlaybackSession
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the unique session identifier.
|
||||||
|
/// </summary>
|
||||||
|
public string SessionId { get; set; } = Guid.NewGuid().ToString();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the Jellyfin session ID.
|
||||||
|
/// </summary>
|
||||||
|
public string? JellyfinSessionId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the Jellyfin item ID being played.
|
||||||
|
/// </summary>
|
||||||
|
public Guid ItemId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the item name for display.
|
||||||
|
/// </summary>
|
||||||
|
public string ItemName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the artist name (for audio).
|
||||||
|
/// </summary>
|
||||||
|
public string? Artist { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the album name (for audio).
|
||||||
|
/// </summary>
|
||||||
|
public string? Album { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the MAC addresses of LMS players in this session.
|
||||||
|
/// </summary>
|
||||||
|
public List<string> PlayerMacs { get; set; } = [];
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the current playback state.
|
||||||
|
/// </summary>
|
||||||
|
public PlaybackState State { get; set; } = PlaybackState.Stopped;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the current playback position in ticks.
|
||||||
|
/// </summary>
|
||||||
|
public long PositionTicks { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the total runtime in ticks.
|
||||||
|
/// </summary>
|
||||||
|
public long RuntimeTicks { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets when this session started.
|
||||||
|
/// </summary>
|
||||||
|
public DateTime StartedAt { get; set; } = DateTime.UtcNow;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the audio stream URL being played on LMS.
|
||||||
|
/// </summary>
|
||||||
|
public string? StreamUrl { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the Jellyfin user ID who initiated playback.
|
||||||
|
/// </summary>
|
||||||
|
public Guid? UserId { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Jellyfin.Plugin.JellyLMS.Models;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents an LMS player/zone.
|
||||||
|
/// </summary>
|
||||||
|
public class LmsPlayer
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the player's display name.
|
||||||
|
/// </summary>
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the player's MAC address (unique identifier).
|
||||||
|
/// </summary>
|
||||||
|
public string MacAddress { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the player's IP address.
|
||||||
|
/// </summary>
|
||||||
|
public string IpAddress { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating whether the player is connected to LMS.
|
||||||
|
/// </summary>
|
||||||
|
public bool IsConnected { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating whether the player is powered on.
|
||||||
|
/// </summary>
|
||||||
|
public bool IsPoweredOn { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the player's current volume (0-100).
|
||||||
|
/// </summary>
|
||||||
|
public int Volume { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the player model name.
|
||||||
|
/// </summary>
|
||||||
|
public string Model { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the MAC address of the sync master, if this player is synced.
|
||||||
|
/// </summary>
|
||||||
|
public string? SyncMaster { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the list of synced player MAC addresses (if this is a sync master).
|
||||||
|
/// </summary>
|
||||||
|
public List<string> SyncSlaves { get; set; } = [];
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether this player is part of a sync group.
|
||||||
|
/// </summary>
|
||||||
|
public bool IsSynced => !string.IsNullOrEmpty(SyncMaster) || SyncSlaves.Count > 0;
|
||||||
|
}
|
||||||
@@ -1,16 +1,17 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using Jellyfin.Plugin.Template.Configuration;
|
using Jellyfin.Plugin.JellyLMS.Configuration;
|
||||||
using MediaBrowser.Common.Configuration;
|
using MediaBrowser.Common.Configuration;
|
||||||
using MediaBrowser.Common.Plugins;
|
using MediaBrowser.Common.Plugins;
|
||||||
using MediaBrowser.Model.Plugins;
|
using MediaBrowser.Model.Plugins;
|
||||||
using MediaBrowser.Model.Serialization;
|
using MediaBrowser.Model.Serialization;
|
||||||
|
|
||||||
namespace Jellyfin.Plugin.Template;
|
namespace Jellyfin.Plugin.JellyLMS;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The main plugin.
|
/// The main JellyLMS plugin class.
|
||||||
|
/// Bridges Jellyfin audio playback to LMS for multi-room synchronized playback.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
|
public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
|
||||||
{
|
{
|
||||||
@@ -26,10 +27,13 @@ public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override string Name => "Template";
|
public override string Name => "JellyLMS";
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override Guid Id => Guid.Parse("eb5d7894-8eef-4b36-aa6f-5d124e828ce1");
|
public override Guid Id => Guid.Parse("a5b8c9d0-1e2f-3a4b-5c6d-7e8f9a0b1c2d");
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override string Description => "Stream Jellyfin audio to Logitech Media Server (LMS) for multi-room playback";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the current plugin instance.
|
/// Gets the current plugin instance.
|
||||||
@@ -39,13 +43,13 @@ public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IEnumerable<PluginPageInfo> GetPages()
|
public IEnumerable<PluginPageInfo> GetPages()
|
||||||
{
|
{
|
||||||
return new[]
|
return
|
||||||
{
|
[
|
||||||
new PluginPageInfo
|
new PluginPageInfo
|
||||||
{
|
{
|
||||||
Name = this.Name,
|
Name = Name,
|
||||||
EmbeddedResourcePath = string.Format(CultureInfo.InvariantCulture, "{0}.Configuration.configPage.html", GetType().Namespace)
|
EmbeddedResourcePath = string.Format(CultureInfo.InvariantCulture, "{0}.Configuration.configPage.html", GetType().Namespace)
|
||||||
}
|
}
|
||||||
};
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
using Jellyfin.Plugin.JellyLMS.Services;
|
||||||
|
using MediaBrowser.Controller;
|
||||||
|
using MediaBrowser.Controller.Plugins;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
|
namespace Jellyfin.Plugin.JellyLMS;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Registers plugin services with Jellyfin's DI container.
|
||||||
|
/// </summary>
|
||||||
|
public class PluginServiceRegistrator : IPluginServiceRegistrator
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void RegisterServices(IServiceCollection serviceCollection, IServerApplicationHost applicationHost)
|
||||||
|
{
|
||||||
|
serviceCollection.AddSingleton<ILmsApiClient, LmsApiClient>();
|
||||||
|
serviceCollection.AddSingleton<LmsPlayerManager>();
|
||||||
|
serviceCollection.AddSingleton<LmsSessionManager>();
|
||||||
|
serviceCollection.AddHostedService(sp => sp.GetRequiredService<LmsSessionManager>());
|
||||||
|
|
||||||
|
// Device discovery service - registers LMS players as Jellyfin sessions for casting
|
||||||
|
// Use AddHostedService directly to let DI handle construction
|
||||||
|
serviceCollection.AddHostedService<LmsDeviceDiscoveryService>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,112 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Jellyfin.Plugin.JellyLMS.Models;
|
||||||
|
|
||||||
|
namespace Jellyfin.Plugin.JellyLMS.Services;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Interface for LMS JSON-RPC API communication.
|
||||||
|
/// </summary>
|
||||||
|
public interface ILmsApiClient
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Tests the connection to the LMS server.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Server status with connection result.</returns>
|
||||||
|
Task<LmsServerStatus> TestConnectionAsync();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all players connected to LMS.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>List of LMS players.</returns>
|
||||||
|
Task<List<LmsPlayer>> GetPlayersAsync();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the status of a specific player.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="playerMac">The player's MAC address.</param>
|
||||||
|
/// <returns>The player status.</returns>
|
||||||
|
Task<PlayerStatusResult?> GetPlayerStatusAsync(string playerMac);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Plays a URL on the specified player.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="playerMac">The player's MAC address.</param>
|
||||||
|
/// <param name="url">The audio URL to play.</param>
|
||||||
|
/// <param name="title">Optional title for display.</param>
|
||||||
|
/// <returns>True if successful.</returns>
|
||||||
|
Task<bool> PlayUrlAsync(string playerMac, string url, string? title = null);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Pauses playback on the specified player.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="playerMac">The player's MAC address.</param>
|
||||||
|
/// <returns>True if successful.</returns>
|
||||||
|
Task<bool> PauseAsync(string playerMac);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Resumes playback on the specified player.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="playerMac">The player's MAC address.</param>
|
||||||
|
/// <returns>True if successful.</returns>
|
||||||
|
Task<bool> PlayAsync(string playerMac);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Stops playback on the specified player.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="playerMac">The player's MAC address.</param>
|
||||||
|
/// <returns>True if successful.</returns>
|
||||||
|
Task<bool> StopAsync(string playerMac);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the volume on the specified player.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="playerMac">The player's MAC address.</param>
|
||||||
|
/// <param name="volume">Volume level (0-100).</param>
|
||||||
|
/// <returns>True if successful.</returns>
|
||||||
|
Task<bool> SetVolumeAsync(string playerMac, int volume);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Seeks to a position on the specified player.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="playerMac">The player's MAC address.</param>
|
||||||
|
/// <param name="positionSeconds">Position in seconds.</param>
|
||||||
|
/// <returns>True if successful.</returns>
|
||||||
|
Task<bool> SeekAsync(string playerMac, double positionSeconds);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Powers on the specified player.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="playerMac">The player's MAC address.</param>
|
||||||
|
/// <returns>True if successful.</returns>
|
||||||
|
Task<bool> PowerOnAsync(string playerMac);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Powers off the specified player.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="playerMac">The player's MAC address.</param>
|
||||||
|
/// <returns>True if successful.</returns>
|
||||||
|
Task<bool> PowerOffAsync(string playerMac);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Syncs a slave player to a master player.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="masterMac">The master player's MAC address.</param>
|
||||||
|
/// <param name="slaveMac">The slave player's MAC address.</param>
|
||||||
|
/// <returns>True if successful.</returns>
|
||||||
|
Task<bool> SyncPlayerAsync(string masterMac, string slaveMac);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes a player from its sync group.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="playerMac">The player's MAC address.</param>
|
||||||
|
/// <returns>True if successful.</returns>
|
||||||
|
Task<bool> UnsyncPlayerAsync(string playerMac);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all current sync groups.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>List of sync groups.</returns>
|
||||||
|
Task<List<SyncGroup>> GetSyncGroupsAsync();
|
||||||
|
}
|
||||||
@@ -0,0 +1,384 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Json;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Jellyfin.Plugin.JellyLMS.Configuration;
|
||||||
|
using Jellyfin.Plugin.JellyLMS.Models;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace Jellyfin.Plugin.JellyLMS.Services;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// HTTP client for LMS JSON-RPC API communication.
|
||||||
|
/// </summary>
|
||||||
|
public class LmsApiClient : ILmsApiClient, IDisposable
|
||||||
|
{
|
||||||
|
private readonly ILogger<LmsApiClient> _logger;
|
||||||
|
private readonly HttpClient _httpClient;
|
||||||
|
private bool _disposed;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="LmsApiClient"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="logger">The logger instance.</param>
|
||||||
|
public LmsApiClient(ILogger<LmsApiClient> logger)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_httpClient = new HttpClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
private PluginConfiguration Config => Plugin.Instance?.Configuration ?? new PluginConfiguration();
|
||||||
|
|
||||||
|
private string JsonRpcEndpoint => $"{Config.LmsServerUrl.TrimEnd('/')}/jsonrpc.js";
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task<LmsServerStatus> TestConnectionAsync()
|
||||||
|
{
|
||||||
|
var status = new LmsServerStatus();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var result = await SendCommandAsync<PlayersListResult>("-", ["players", "0", "1"]).ConfigureAwait(false);
|
||||||
|
status.IsConnected = result != null;
|
||||||
|
status.PlayerCount = result?.Count ?? 0;
|
||||||
|
status.Version = "Connected";
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
status.IsConnected = false;
|
||||||
|
status.LastError = ex.Message;
|
||||||
|
_logger.LogError(ex, "Failed to connect to LMS at {Endpoint}", JsonRpcEndpoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task<List<LmsPlayer>> GetPlayersAsync()
|
||||||
|
{
|
||||||
|
var players = new List<LmsPlayer>();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// First get player count
|
||||||
|
var countResult = await SendCommandAsync<PlayerCountResult>("-", ["player", "count", "?"]).ConfigureAwait(false);
|
||||||
|
var count = countResult?.Count ?? 0;
|
||||||
|
|
||||||
|
if (count == 0)
|
||||||
|
{
|
||||||
|
return players;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Then get player list
|
||||||
|
var listResult = await SendCommandAsync<PlayersListResult>("-", ["players", "0", count.ToString(CultureInfo.InvariantCulture)]).ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (listResult?.Players == null)
|
||||||
|
{
|
||||||
|
return players;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var p in listResult.Players)
|
||||||
|
{
|
||||||
|
var player = new LmsPlayer
|
||||||
|
{
|
||||||
|
Name = p.Name,
|
||||||
|
MacAddress = p.PlayerId,
|
||||||
|
IpAddress = p.Ip.Split(':')[0], // Remove port if present
|
||||||
|
IsConnected = p.Connected == 1,
|
||||||
|
IsPoweredOn = p.Power == 1,
|
||||||
|
Model = p.ModelName
|
||||||
|
};
|
||||||
|
|
||||||
|
// Get additional status for sync info
|
||||||
|
var status = await GetPlayerStatusAsync(p.PlayerId).ConfigureAwait(false);
|
||||||
|
if (status != null)
|
||||||
|
{
|
||||||
|
player.Volume = status.Volume;
|
||||||
|
player.SyncMaster = status.SyncMaster;
|
||||||
|
if (!string.IsNullOrEmpty(status.SyncSlaves))
|
||||||
|
{
|
||||||
|
player.SyncSlaves = status.SyncSlaves.Split(',').ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
players.Add(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Failed to get players from LMS");
|
||||||
|
}
|
||||||
|
|
||||||
|
return players;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task<PlayerStatusResult?> GetPlayerStatusAsync(string playerMac)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return await SendCommandAsync<PlayerStatusResult>(playerMac, ["status", "-", "1", "tags:"])
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Failed to get status for player {Mac}", playerMac);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task<bool> PlayUrlAsync(string playerMac, string url, string? title = null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// First clear the playlist and add the URL
|
||||||
|
await SendCommandAsync<object>(playerMac, ["playlist", "clear"]).ConfigureAwait(false);
|
||||||
|
await SendCommandAsync<object>(playerMac, ["playlist", "add", url]).ConfigureAwait(false);
|
||||||
|
|
||||||
|
// Set title if provided
|
||||||
|
if (!string.IsNullOrEmpty(title))
|
||||||
|
{
|
||||||
|
await SendCommandAsync<object>(playerMac, ["playlist", "title", title]).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start playback
|
||||||
|
await SendCommandAsync<object>(playerMac, ["play"]).ConfigureAwait(false);
|
||||||
|
|
||||||
|
_logger.LogInformation("Started playback of {Url} on player {Mac}", url, playerMac);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Failed to play URL on player {Mac}", playerMac);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task<bool> PauseAsync(string playerMac)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await SendCommandAsync<object>(playerMac, ["pause", "1"]).ConfigureAwait(false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Failed to pause player {Mac}", playerMac);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task<bool> PlayAsync(string playerMac)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await SendCommandAsync<object>(playerMac, ["play"]).ConfigureAwait(false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Failed to resume player {Mac}", playerMac);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task<bool> StopAsync(string playerMac)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await SendCommandAsync<object>(playerMac, ["stop"]).ConfigureAwait(false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Failed to stop player {Mac}", playerMac);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task<bool> SetVolumeAsync(string playerMac, int volume)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
volume = Math.Clamp(volume, 0, 100);
|
||||||
|
await SendCommandAsync<object>(playerMac, ["mixer", "volume", volume.ToString(CultureInfo.InvariantCulture)])
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Failed to set volume on player {Mac}", playerMac);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task<bool> SeekAsync(string playerMac, double positionSeconds)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logger.LogInformation("LMS SeekAsync: player {Mac}, position {Seconds}s", playerMac, positionSeconds);
|
||||||
|
await SendCommandAsync<object>(playerMac, ["time", positionSeconds.ToString("F1", CultureInfo.InvariantCulture)])
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
_logger.LogInformation("LMS SeekAsync: command sent successfully");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Failed to seek on player {Mac}", playerMac);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task<bool> PowerOnAsync(string playerMac)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await SendCommandAsync<object>(playerMac, ["power", "1"]).ConfigureAwait(false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Failed to power on player {Mac}", playerMac);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task<bool> PowerOffAsync(string playerMac)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await SendCommandAsync<object>(playerMac, ["power", "0"]).ConfigureAwait(false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Failed to power off player {Mac}", playerMac);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task<bool> SyncPlayerAsync(string masterMac, string slaveMac)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await SendCommandAsync<object>(masterMac, ["sync", slaveMac]).ConfigureAwait(false);
|
||||||
|
_logger.LogInformation("Synced player {Slave} to master {Master}", slaveMac, masterMac);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Failed to sync player {Slave} to {Master}", slaveMac, masterMac);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task<bool> UnsyncPlayerAsync(string playerMac)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await SendCommandAsync<object>(playerMac, ["sync", "-"]).ConfigureAwait(false);
|
||||||
|
_logger.LogInformation("Unsynced player {Mac}", playerMac);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Failed to unsync player {Mac}", playerMac);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task<List<SyncGroup>> GetSyncGroupsAsync()
|
||||||
|
{
|
||||||
|
var groups = new List<SyncGroup>();
|
||||||
|
var players = await GetPlayersAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
|
// Find all masters (players with slaves)
|
||||||
|
var masters = players.Where(p => p.SyncSlaves.Count > 0).ToList();
|
||||||
|
|
||||||
|
foreach (var master in masters)
|
||||||
|
{
|
||||||
|
var group = new SyncGroup
|
||||||
|
{
|
||||||
|
MasterMac = master.MacAddress,
|
||||||
|
MasterName = master.Name,
|
||||||
|
SlaveMacs = master.SyncSlaves
|
||||||
|
};
|
||||||
|
|
||||||
|
// Resolve slave names
|
||||||
|
foreach (var slaveMac in master.SyncSlaves)
|
||||||
|
{
|
||||||
|
var slave = players.FirstOrDefault(p => p.MacAddress == slaveMac);
|
||||||
|
if (slave != null)
|
||||||
|
{
|
||||||
|
group.SlaveNames.Add(slave.Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
groups.Add(group);
|
||||||
|
}
|
||||||
|
|
||||||
|
return groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<T?> SendCommandAsync<T>(string playerMac, string[] command)
|
||||||
|
{
|
||||||
|
var request = new LmsJsonRpcRequest
|
||||||
|
{
|
||||||
|
Params = [playerMac, command]
|
||||||
|
};
|
||||||
|
|
||||||
|
var response = await _httpClient.PostAsJsonAsync(JsonRpcEndpoint, request).ConfigureAwait(false);
|
||||||
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
|
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||||
|
var result = JsonSerializer.Deserialize<LmsJsonRpcResponse<T>>(content);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(result?.Error))
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"LMS API error: {result.Error}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return result != null ? result.Result : default;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Dispose(true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Disposes managed resources.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">Whether to dispose managed resources.</param>
|
||||||
|
protected virtual void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (_disposed)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
_httpClient.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
_disposed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,254 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Jellyfin.Data.Enums;
|
||||||
|
using Jellyfin.Plugin.JellyLMS.Models;
|
||||||
|
using MediaBrowser.Controller.Library;
|
||||||
|
using MediaBrowser.Controller.Session;
|
||||||
|
using MediaBrowser.Model.Session;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace Jellyfin.Plugin.JellyLMS.Services;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Background service that discovers LMS players and registers them as Jellyfin sessions.
|
||||||
|
/// This enables LMS players to appear in Jellyfin's "Cast to" device picker.
|
||||||
|
/// </summary>
|
||||||
|
public class LmsDeviceDiscoveryService : IHostedService, IDisposable
|
||||||
|
{
|
||||||
|
private const string AppName = "JellyLMS";
|
||||||
|
private const string AppVersion = "1.0.0";
|
||||||
|
|
||||||
|
private readonly ILogger<LmsDeviceDiscoveryService> _logger;
|
||||||
|
private readonly IServiceProvider _serviceProvider;
|
||||||
|
private readonly ILmsApiClient _lmsClient;
|
||||||
|
private readonly LmsPlayerManager _playerManager;
|
||||||
|
private readonly ConcurrentDictionary<string, string> _registeredDeviceIds = new();
|
||||||
|
private ISessionManager? _sessionManager;
|
||||||
|
private Timer? _discoveryTimer;
|
||||||
|
private bool _disposed;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="LmsDeviceDiscoveryService"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="logger">The logger instance.</param>
|
||||||
|
/// <param name="serviceProvider">The service provider for lazy resolution.</param>
|
||||||
|
/// <param name="lmsClient">The LMS API client.</param>
|
||||||
|
/// <param name="playerManager">The LMS player manager.</param>
|
||||||
|
public LmsDeviceDiscoveryService(
|
||||||
|
ILogger<LmsDeviceDiscoveryService> logger,
|
||||||
|
IServiceProvider serviceProvider,
|
||||||
|
ILmsApiClient lmsClient,
|
||||||
|
LmsPlayerManager playerManager)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_serviceProvider = serviceProvider;
|
||||||
|
_lmsClient = lmsClient;
|
||||||
|
_playerManager = playerManager;
|
||||||
|
_logger.LogInformation("LMS Device Discovery Service constructed");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public Task StartAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("LMS Device Discovery Service starting");
|
||||||
|
|
||||||
|
// Run initial discovery after a delay, then every 15 seconds
|
||||||
|
_discoveryTimer = new Timer(
|
||||||
|
async _ => await DiscoverAndRegisterPlayersAsync().ConfigureAwait(false),
|
||||||
|
null,
|
||||||
|
TimeSpan.FromSeconds(10),
|
||||||
|
TimeSpan.FromSeconds(15));
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public Task StopAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("LMS Device Discovery Service stopping");
|
||||||
|
|
||||||
|
_discoveryTimer?.Change(Timeout.Infinite, 0);
|
||||||
|
_registeredDeviceIds.Clear();
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ISessionManager? GetSessionManager()
|
||||||
|
{
|
||||||
|
if (_sessionManager != null)
|
||||||
|
{
|
||||||
|
return _sessionManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_sessionManager = _serviceProvider.GetService<ISessionManager>();
|
||||||
|
if (_sessionManager == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ISessionManager not available yet");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Failed to resolve ISessionManager");
|
||||||
|
}
|
||||||
|
|
||||||
|
return _sessionManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task DiscoverAndRegisterPlayersAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var sessionManager = GetSessionManager();
|
||||||
|
if (sessionManager == null)
|
||||||
|
{
|
||||||
|
_logger.LogDebug("Session manager not available, skipping discovery");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// First test connection
|
||||||
|
var status = await _lmsClient.TestConnectionAsync().ConfigureAwait(false);
|
||||||
|
if (!status.IsConnected)
|
||||||
|
{
|
||||||
|
_logger.LogDebug("LMS server not connected, skipping player discovery");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get all players from LMS
|
||||||
|
var players = await _playerManager.GetPlayersAsync(forceRefresh: true).ConfigureAwait(false);
|
||||||
|
|
||||||
|
_logger.LogDebug("Discovered {Count} LMS players", players.Count);
|
||||||
|
|
||||||
|
foreach (var player in players)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await RegisterOrRefreshPlayerSessionAsync(sessionManager, player).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Failed to register player {Name} ({Mac})", player.Name, player.MacAddress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean up tracked device IDs for players that no longer exist
|
||||||
|
foreach (var mac in _registeredDeviceIds.Keys)
|
||||||
|
{
|
||||||
|
if (!players.Exists(p => p.MacAddress == mac))
|
||||||
|
{
|
||||||
|
_registeredDeviceIds.TryRemove(mac, out _);
|
||||||
|
_logger.LogDebug("Removed tracking for disconnected player {Mac}", mac);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error during LMS player discovery");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task RegisterOrRefreshPlayerSessionAsync(ISessionManager sessionManager, LmsPlayer player)
|
||||||
|
{
|
||||||
|
// Create a unique device ID for this player
|
||||||
|
var deviceId = $"lms-{player.MacAddress}";
|
||||||
|
|
||||||
|
// Always call LogSessionActivity to keep the session alive
|
||||||
|
// This creates a new session if one doesn't exist, or refreshes the existing one
|
||||||
|
var session = await sessionManager.LogSessionActivity(
|
||||||
|
appName: AppName,
|
||||||
|
appVersion: AppVersion,
|
||||||
|
deviceId: deviceId,
|
||||||
|
deviceName: player.Name,
|
||||||
|
remoteEndPoint: player.IpAddress,
|
||||||
|
user: null).ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (session == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Failed to create/refresh session for player {Name}", player.Name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if this is a new registration
|
||||||
|
var isNew = !_registeredDeviceIds.ContainsKey(player.MacAddress);
|
||||||
|
|
||||||
|
// Add our controller to the session using EnsureController pattern
|
||||||
|
var libraryManager = _serviceProvider.GetRequiredService<ILibraryManager>();
|
||||||
|
var (controller, created) = session.EnsureController<LmsSessionController>(
|
||||||
|
s => new LmsSessionController(
|
||||||
|
_logger,
|
||||||
|
_lmsClient,
|
||||||
|
player,
|
||||||
|
s,
|
||||||
|
sessionManager,
|
||||||
|
libraryManager));
|
||||||
|
|
||||||
|
if (created)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Created LmsSessionController for player {Name}", player.Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Always report capabilities to ensure they're set
|
||||||
|
// This is critical for the device to appear in "Play On" menu
|
||||||
|
var capabilities = new ClientCapabilities
|
||||||
|
{
|
||||||
|
PlayableMediaTypes = [MediaType.Audio],
|
||||||
|
SupportedCommands =
|
||||||
|
[
|
||||||
|
GeneralCommandType.VolumeUp,
|
||||||
|
GeneralCommandType.VolumeDown,
|
||||||
|
GeneralCommandType.Mute,
|
||||||
|
GeneralCommandType.Unmute,
|
||||||
|
GeneralCommandType.SetVolume,
|
||||||
|
GeneralCommandType.ToggleMute
|
||||||
|
],
|
||||||
|
SupportsMediaControl = true,
|
||||||
|
SupportsPersistentIdentifier = true
|
||||||
|
};
|
||||||
|
|
||||||
|
sessionManager.ReportCapabilities(session.Id, capabilities);
|
||||||
|
|
||||||
|
// Track this device
|
||||||
|
_registeredDeviceIds[player.MacAddress] = deviceId;
|
||||||
|
|
||||||
|
if (isNew)
|
||||||
|
{
|
||||||
|
_logger.LogInformation(
|
||||||
|
"Registered LMS player {Name} ({Mac}) as session {SessionId}",
|
||||||
|
player.Name,
|
||||||
|
player.MacAddress,
|
||||||
|
session.Id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Dispose(true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Disposes managed resources.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">Whether to dispose managed resources.</param>
|
||||||
|
protected virtual void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (_disposed)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
_discoveryTimer?.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
_disposed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,163 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Jellyfin.Plugin.JellyLMS.Models;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace Jellyfin.Plugin.JellyLMS.Services;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Manages LMS player discovery and state tracking.
|
||||||
|
/// </summary>
|
||||||
|
public class LmsPlayerManager
|
||||||
|
{
|
||||||
|
private readonly ILogger<LmsPlayerManager> _logger;
|
||||||
|
private readonly ILmsApiClient _lmsClient;
|
||||||
|
private readonly ConcurrentDictionary<string, LmsPlayer> _players = new();
|
||||||
|
private DateTime _lastRefresh = DateTime.MinValue;
|
||||||
|
private readonly TimeSpan _cacheExpiry = TimeSpan.FromSeconds(30);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="LmsPlayerManager"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="logger">The logger instance.</param>
|
||||||
|
/// <param name="lmsClient">The LMS API client.</param>
|
||||||
|
public LmsPlayerManager(ILogger<LmsPlayerManager> logger, ILmsApiClient lmsClient)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_lmsClient = lmsClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all known LMS players, refreshing if cache is stale.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="forceRefresh">Force a refresh from LMS.</param>
|
||||||
|
/// <returns>List of LMS players.</returns>
|
||||||
|
public async Task<List<LmsPlayer>> GetPlayersAsync(bool forceRefresh = false)
|
||||||
|
{
|
||||||
|
if (!forceRefresh && DateTime.UtcNow - _lastRefresh < _cacheExpiry && _players.Count > 0)
|
||||||
|
{
|
||||||
|
return _players.Values.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
await RefreshPlayersAsync().ConfigureAwait(false);
|
||||||
|
return _players.Values.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a specific player by MAC address.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="macAddress">The player's MAC address.</param>
|
||||||
|
/// <returns>The player, or null if not found.</returns>
|
||||||
|
public async Task<LmsPlayer?> GetPlayerAsync(string macAddress)
|
||||||
|
{
|
||||||
|
if (_players.TryGetValue(macAddress, out var player))
|
||||||
|
{
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
await RefreshPlayersAsync().ConfigureAwait(false);
|
||||||
|
return _players.GetValueOrDefault(macAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Refreshes the player list from LMS.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A task representing the operation.</returns>
|
||||||
|
public async Task RefreshPlayersAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var players = await _lmsClient.GetPlayersAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
|
_players.Clear();
|
||||||
|
foreach (var player in players)
|
||||||
|
{
|
||||||
|
_players[player.MacAddress] = player;
|
||||||
|
}
|
||||||
|
|
||||||
|
_lastRefresh = DateTime.UtcNow;
|
||||||
|
_logger.LogDebug("Refreshed {Count} players from LMS", players.Count);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Failed to refresh players from LMS");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all current sync groups.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>List of sync groups.</returns>
|
||||||
|
public async Task<List<SyncGroup>> GetSyncGroupsAsync()
|
||||||
|
{
|
||||||
|
return await _lmsClient.GetSyncGroupsAsync().ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a sync group with the specified players.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="masterMac">The master player's MAC address.</param>
|
||||||
|
/// <param name="slaveMacs">The slave players' MAC addresses.</param>
|
||||||
|
/// <returns>True if successful.</returns>
|
||||||
|
public async Task<bool> CreateSyncGroupAsync(string masterMac, IEnumerable<string> slaveMacs)
|
||||||
|
{
|
||||||
|
var success = true;
|
||||||
|
|
||||||
|
foreach (var slaveMac in slaveMacs)
|
||||||
|
{
|
||||||
|
if (!await _lmsClient.SyncPlayerAsync(masterMac, slaveMac).ConfigureAwait(false))
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Failed to sync player {Slave} to master {Master}", slaveMac, masterMac);
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Refresh player state to update sync info
|
||||||
|
await RefreshPlayersAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes a player from its sync group.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="playerMac">The player's MAC address.</param>
|
||||||
|
/// <returns>True if successful.</returns>
|
||||||
|
public async Task<bool> UnsyncPlayerAsync(string playerMac)
|
||||||
|
{
|
||||||
|
var result = await _lmsClient.UnsyncPlayerAsync(playerMac).ConfigureAwait(false);
|
||||||
|
await RefreshPlayersAsync().ConfigureAwait(false);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Dissolves an entire sync group (unsyncs all members).
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="masterMac">The master player's MAC address.</param>
|
||||||
|
/// <returns>True if successful.</returns>
|
||||||
|
public async Task<bool> DissolveSyncGroupAsync(string masterMac)
|
||||||
|
{
|
||||||
|
var player = await GetPlayerAsync(masterMac).ConfigureAwait(false);
|
||||||
|
if (player == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var success = true;
|
||||||
|
|
||||||
|
// Unsync all slaves
|
||||||
|
foreach (var slaveMac in player.SyncSlaves)
|
||||||
|
{
|
||||||
|
if (!await _lmsClient.UnsyncPlayerAsync(slaveMac).ConfigureAwait(false))
|
||||||
|
{
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await RefreshPlayersAsync().ConfigureAwait(false);
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,694 @@
|
|||||||
|
using System;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Jellyfin.Plugin.JellyLMS.Models;
|
||||||
|
using MediaBrowser.Controller.Entities;
|
||||||
|
using MediaBrowser.Controller.Library;
|
||||||
|
using MediaBrowser.Controller.Session;
|
||||||
|
using MediaBrowser.Model.Session;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace Jellyfin.Plugin.JellyLMS.Services;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Session controller for LMS player devices.
|
||||||
|
/// Enables Jellyfin to send playback commands to LMS players via the cast interface.
|
||||||
|
/// </summary>
|
||||||
|
public class LmsSessionController : ISessionController, IDisposable
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly ILmsApiClient _lmsClient;
|
||||||
|
private readonly LmsPlayer _player;
|
||||||
|
private readonly SessionInfo _session;
|
||||||
|
private readonly ISessionManager _sessionManager;
|
||||||
|
private readonly ILibraryManager _libraryManager;
|
||||||
|
private Timer? _progressTimer;
|
||||||
|
private bool _disposed;
|
||||||
|
private BaseItem? _currentItem;
|
||||||
|
private Guid[] _playlist = [];
|
||||||
|
private int _playlistIndex;
|
||||||
|
private long _seekOffsetTicks; // Offset from transcoded stream start position
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="LmsSessionController"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="logger">The logger instance.</param>
|
||||||
|
/// <param name="lmsClient">The LMS API client.</param>
|
||||||
|
/// <param name="player">The LMS player this controller manages.</param>
|
||||||
|
/// <param name="session">The Jellyfin session associated with this controller.</param>
|
||||||
|
/// <param name="sessionManager">The session manager for reporting playback events.</param>
|
||||||
|
/// <param name="libraryManager">The library manager for item lookups.</param>
|
||||||
|
public LmsSessionController(
|
||||||
|
ILogger logger,
|
||||||
|
ILmsApiClient lmsClient,
|
||||||
|
LmsPlayer player,
|
||||||
|
SessionInfo session,
|
||||||
|
ISessionManager sessionManager,
|
||||||
|
ILibraryManager libraryManager)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_lmsClient = lmsClient;
|
||||||
|
_player = player;
|
||||||
|
_session = session;
|
||||||
|
_sessionManager = sessionManager;
|
||||||
|
_libraryManager = libraryManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the currently playing item ID.
|
||||||
|
/// </summary>
|
||||||
|
public Guid? CurrentItemId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating whether playback is currently active.
|
||||||
|
/// </summary>
|
||||||
|
public bool IsPlaying { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating whether playback is paused.
|
||||||
|
/// </summary>
|
||||||
|
public bool IsPaused { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public bool IsSessionActive => _player.IsConnected;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public bool SupportsMediaControl => true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the MAC address of the LMS player.
|
||||||
|
/// </summary>
|
||||||
|
public string PlayerMac => _player.MacAddress;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task SendMessage<T>(
|
||||||
|
SessionMessageType name,
|
||||||
|
Guid messageId,
|
||||||
|
T data,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
_logger.LogInformation(
|
||||||
|
"LMS Session Controller received message {MessageType} for player {PlayerName} ({Mac}), data type: {DataType}",
|
||||||
|
name,
|
||||||
|
_player.Name,
|
||||||
|
_player.MacAddress,
|
||||||
|
data?.GetType().Name ?? "null");
|
||||||
|
|
||||||
|
// Log the data for debugging
|
||||||
|
if (data is PlaystateRequest psr)
|
||||||
|
{
|
||||||
|
_logger.LogInformation(
|
||||||
|
"PlaystateRequest: Command={Command}, SeekPositionTicks={Ticks}",
|
||||||
|
psr.Command,
|
||||||
|
psr.SeekPositionTicks);
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
switch (name)
|
||||||
|
{
|
||||||
|
case SessionMessageType.Play:
|
||||||
|
await HandlePlayCommandAsync(data, cancellationToken).ConfigureAwait(false);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SessionMessageType.Playstate:
|
||||||
|
await HandlePlaystateCommandAsync(data, cancellationToken).ConfigureAwait(false);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SessionMessageType.GeneralCommand:
|
||||||
|
await HandleGeneralCommandAsync(data, cancellationToken).ConfigureAwait(false);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
_logger.LogDebug("Unhandled message type: {MessageType}", name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error handling message {MessageType} for player {PlayerName}", name, _player.Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task HandlePlayCommandAsync<T>(T data, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
if (data is not PlayRequest playRequest)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Expected PlayRequest but got {Type}", data?.GetType().Name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation(
|
||||||
|
"Play command received for player {PlayerName}: {ItemCount} items",
|
||||||
|
_player.Name,
|
||||||
|
playRequest.ItemIds.Length);
|
||||||
|
|
||||||
|
// Power on the player if needed
|
||||||
|
if (!_player.IsPoweredOn)
|
||||||
|
{
|
||||||
|
await _lmsClient.PowerOnAsync(_player.MacAddress).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (playRequest.ItemIds.Length > 0)
|
||||||
|
{
|
||||||
|
// Store the full playlist
|
||||||
|
_playlist = playRequest.ItemIds;
|
||||||
|
_playlistIndex = playRequest.StartIndex ?? 0;
|
||||||
|
|
||||||
|
// Play the item at the start index
|
||||||
|
await PlayItemAtIndexAsync(_playlistIndex, playRequest.StartPositionTicks ?? 0).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task PlayItemAtIndexAsync(int index, long startPositionTicks = 0)
|
||||||
|
{
|
||||||
|
if (index < 0 || index >= _playlist.Length)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Invalid playlist index {Index}, playlist has {Count} items", index, _playlist.Length);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var itemId = _playlist[index];
|
||||||
|
_playlistIndex = index;
|
||||||
|
|
||||||
|
// Look up the item first - we need it for file path if using direct mode
|
||||||
|
_currentItem = _libraryManager.GetItemById(itemId);
|
||||||
|
|
||||||
|
// Build stream URL/path with start position
|
||||||
|
var (streamUrl, useDirectPath) = BuildPlaybackUrl(itemId, startPositionTicks);
|
||||||
|
_logger.LogInformation(
|
||||||
|
"Playing item {Index}/{Total} from position {Position}s (direct={Direct}): {Url}",
|
||||||
|
index + 1,
|
||||||
|
_playlist.Length,
|
||||||
|
startPositionTicks / TimeSpan.TicksPerSecond,
|
||||||
|
useDirectPath,
|
||||||
|
streamUrl);
|
||||||
|
|
||||||
|
await _lmsClient.PlayUrlAsync(_player.MacAddress, streamUrl).ConfigureAwait(false);
|
||||||
|
|
||||||
|
// Track current playback state
|
||||||
|
CurrentItemId = itemId;
|
||||||
|
IsPlaying = true;
|
||||||
|
IsPaused = false;
|
||||||
|
|
||||||
|
// Track the seek offset so we report the correct position
|
||||||
|
// When using direct file paths, LMS handles seeking natively so no offset needed
|
||||||
|
// When using HTTP streaming with startTimeTicks, the stream starts at 0 but we need to report actual position
|
||||||
|
_seekOffsetTicks = useDirectPath ? 0 : startPositionTicks;
|
||||||
|
|
||||||
|
// Report playback start to Jellyfin
|
||||||
|
await ReportPlaybackStartAsync(itemId, startPositionTicks).ConfigureAwait(false);
|
||||||
|
|
||||||
|
// Start progress reporting timer (every 2 seconds)
|
||||||
|
StartProgressTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ReportPlaybackStartAsync(Guid itemId, long positionTicks)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var startInfo = new PlaybackStartInfo
|
||||||
|
{
|
||||||
|
ItemId = itemId,
|
||||||
|
SessionId = _session.Id,
|
||||||
|
PositionTicks = positionTicks,
|
||||||
|
PlayMethod = PlayMethod.DirectStream,
|
||||||
|
CanSeek = true,
|
||||||
|
IsPaused = false,
|
||||||
|
IsMuted = false
|
||||||
|
};
|
||||||
|
|
||||||
|
_logger.LogInformation(
|
||||||
|
"Reporting playback start for item {ItemId}, duration: {Duration}",
|
||||||
|
itemId,
|
||||||
|
_currentItem?.RunTimeTicks);
|
||||||
|
await _sessionManager.OnPlaybackStart(startInfo).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Failed to report playback start");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StartProgressTimer()
|
||||||
|
{
|
||||||
|
// Stop any existing timer
|
||||||
|
_progressTimer?.Dispose();
|
||||||
|
|
||||||
|
// Report progress every 2 seconds
|
||||||
|
_progressTimer = new Timer(
|
||||||
|
async _ => await ReportPlaybackProgressAsync().ConfigureAwait(false),
|
||||||
|
null,
|
||||||
|
TimeSpan.FromSeconds(2),
|
||||||
|
TimeSpan.FromSeconds(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StopProgressTimer()
|
||||||
|
{
|
||||||
|
_progressTimer?.Dispose();
|
||||||
|
_progressTimer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ReportPlaybackProgressAsync()
|
||||||
|
{
|
||||||
|
if (!IsPlaying || !CurrentItemId.HasValue)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var status = await _lmsClient.GetPlayerStatusAsync(_player.MacAddress).ConfigureAwait(false);
|
||||||
|
if (status == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// LMS reports time relative to the current stream, but after seeking
|
||||||
|
// we're playing a transcoded stream that starts at the seek position.
|
||||||
|
// Add the seek offset to get the actual track position.
|
||||||
|
var positionTicks = (long)(status.Time * TimeSpan.TicksPerSecond) + _seekOffsetTicks;
|
||||||
|
var isPaused = status.Mode == "pause";
|
||||||
|
|
||||||
|
// Update our local state from LMS
|
||||||
|
IsPaused = isPaused;
|
||||||
|
|
||||||
|
// Check if playback has stopped on LMS side (track ended)
|
||||||
|
// Only advance if we're not paused - LMS can briefly report "stop" during transitions
|
||||||
|
if (status.Mode == "stop" && !IsPaused)
|
||||||
|
{
|
||||||
|
// Double-check by getting status again after a brief delay to avoid false positives
|
||||||
|
await Task.Delay(500).ConfigureAwait(false);
|
||||||
|
var confirmStatus = await _lmsClient.GetPlayerStatusAsync(_player.MacAddress).ConfigureAwait(false);
|
||||||
|
if (confirmStatus?.Mode != "stop")
|
||||||
|
{
|
||||||
|
_logger.LogDebug("LMS mode changed from stop, ignoring");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("LMS playback stopped, checking if we should advance to next track");
|
||||||
|
|
||||||
|
// Check if there are more tracks in the playlist
|
||||||
|
if (_playlistIndex < _playlist.Length - 1)
|
||||||
|
{
|
||||||
|
_logger.LogInformation(
|
||||||
|
"Track ended, advancing to next track (index {Index}/{Total})",
|
||||||
|
_playlistIndex + 2,
|
||||||
|
_playlist.Length);
|
||||||
|
await PlayItemAtIndexAsync(_playlistIndex + 1).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Playlist finished, reporting playback stopped");
|
||||||
|
await ReportPlaybackStoppedAsync().ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var progressInfo = new PlaybackProgressInfo
|
||||||
|
{
|
||||||
|
ItemId = CurrentItemId.Value,
|
||||||
|
SessionId = _session.Id,
|
||||||
|
IsPaused = isPaused,
|
||||||
|
PositionTicks = positionTicks,
|
||||||
|
PlayMethod = PlayMethod.DirectStream,
|
||||||
|
CanSeek = true,
|
||||||
|
IsMuted = status.Volume == 0,
|
||||||
|
VolumeLevel = status.Volume
|
||||||
|
};
|
||||||
|
|
||||||
|
await _sessionManager.OnPlaybackProgress(progressInfo).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogDebug(ex, "Error reporting playback progress");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ReportPlaybackStoppedAsync()
|
||||||
|
{
|
||||||
|
if (!CurrentItemId.HasValue)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
StopProgressTimer();
|
||||||
|
|
||||||
|
var stopInfo = new PlaybackStopInfo
|
||||||
|
{
|
||||||
|
ItemId = CurrentItemId.Value,
|
||||||
|
SessionId = _session.Id
|
||||||
|
};
|
||||||
|
|
||||||
|
_logger.LogInformation("Reporting playback stopped for item {ItemId}", CurrentItemId.Value);
|
||||||
|
await _sessionManager.OnPlaybackStopped(stopInfo).ConfigureAwait(false);
|
||||||
|
|
||||||
|
IsPlaying = false;
|
||||||
|
IsPaused = false;
|
||||||
|
CurrentItemId = null;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Failed to report playback stopped");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task HandlePlaystateCommandAsync<T>(T data, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
if (data is not PlaystateRequest playstateRequest)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Expected PlaystateRequest but got {Type}", data?.GetType().Name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation(
|
||||||
|
"Playstate command {Command} for player {PlayerName} ({Mac})",
|
||||||
|
playstateRequest.Command,
|
||||||
|
_player.Name,
|
||||||
|
_player.MacAddress);
|
||||||
|
|
||||||
|
switch (playstateRequest.Command)
|
||||||
|
{
|
||||||
|
case PlaystateCommand.Stop:
|
||||||
|
var stopResult = await _lmsClient.StopAsync(_player.MacAddress).ConfigureAwait(false);
|
||||||
|
_logger.LogInformation("Stop command result: {Result}", stopResult);
|
||||||
|
await ReportPlaybackStoppedAsync().ConfigureAwait(false);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PlaystateCommand.Pause:
|
||||||
|
var pauseResult = await _lmsClient.PauseAsync(_player.MacAddress).ConfigureAwait(false);
|
||||||
|
_logger.LogInformation("Pause command result: {Result}", pauseResult);
|
||||||
|
IsPaused = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PlaystateCommand.Unpause:
|
||||||
|
var playResult = await _lmsClient.PlayAsync(_player.MacAddress).ConfigureAwait(false);
|
||||||
|
_logger.LogInformation("Unpause/Play command result: {Result}", playResult);
|
||||||
|
IsPaused = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PlaystateCommand.PlayPause:
|
||||||
|
// Toggle play/pause - check current state first
|
||||||
|
var currentState = await _lmsClient.GetPlayerStatusAsync(_player.MacAddress).ConfigureAwait(false);
|
||||||
|
if (currentState?.Mode == "play")
|
||||||
|
{
|
||||||
|
var togglePauseResult = await _lmsClient.PauseAsync(_player.MacAddress).ConfigureAwait(false);
|
||||||
|
_logger.LogInformation("PlayPause toggle (pause) result: {Result}", togglePauseResult);
|
||||||
|
IsPaused = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var togglePlayResult = await _lmsClient.PlayAsync(_player.MacAddress).ConfigureAwait(false);
|
||||||
|
_logger.LogInformation("PlayPause toggle (play) result: {Result}", togglePlayResult);
|
||||||
|
IsPaused = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PlaystateCommand.Seek:
|
||||||
|
_logger.LogInformation(
|
||||||
|
"Seek command received for player {PlayerName}, SeekPositionTicks: {Ticks}, CurrentItemId: {ItemId}, CurrentSeekOffset: {Offset}",
|
||||||
|
_player.Name,
|
||||||
|
playstateRequest.SeekPositionTicks,
|
||||||
|
CurrentItemId,
|
||||||
|
_seekOffsetTicks);
|
||||||
|
if (playstateRequest.SeekPositionTicks.HasValue && CurrentItemId.HasValue)
|
||||||
|
{
|
||||||
|
var positionTicks = playstateRequest.SeekPositionTicks.Value;
|
||||||
|
var positionSeconds = positionTicks / TimeSpan.TicksPerSecond;
|
||||||
|
|
||||||
|
// Check if we're using direct file path mode - if so, LMS can seek natively
|
||||||
|
if (CanSeekNatively())
|
||||||
|
{
|
||||||
|
// Use native LMS seeking - much smoother!
|
||||||
|
_logger.LogInformation("Seeking natively to {Seconds}s using LMS time command", positionSeconds);
|
||||||
|
await _lmsClient.SeekAsync(_player.MacAddress, positionSeconds).ConfigureAwait(false);
|
||||||
|
// No seek offset needed - LMS handles position tracking natively
|
||||||
|
_seekOffsetTicks = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// For HTTP streams, LMS can't seek directly - we need to restart with startTimeTicks
|
||||||
|
// Build a new URL with the seek position and restart playback
|
||||||
|
var streamUrl = BuildStreamUrlWithPosition(CurrentItemId.Value, positionTicks);
|
||||||
|
_logger.LogInformation(
|
||||||
|
"Seeking by restarting stream at position {Seconds}s: {Url}",
|
||||||
|
positionSeconds,
|
||||||
|
streamUrl);
|
||||||
|
|
||||||
|
await _lmsClient.PlayUrlAsync(_player.MacAddress, streamUrl).ConfigureAwait(false);
|
||||||
|
|
||||||
|
// Track the seek offset so we report the correct position
|
||||||
|
// The transcoded stream starts at 0, but we need to report the actual track position
|
||||||
|
_seekOffsetTicks = positionTicks;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("Seek offset is now {Ticks} ticks ({Seconds}s)", _seekOffsetTicks, _seekOffsetTicks / TimeSpan.TicksPerSecond);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Seek command received but SeekPositionTicks or CurrentItemId is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PlaystateCommand.NextTrack:
|
||||||
|
if (_playlistIndex < _playlist.Length - 1)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Skipping to next track (index {Index})", _playlistIndex + 1);
|
||||||
|
await PlayItemAtIndexAsync(_playlistIndex + 1).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Already at last track, stopping playback");
|
||||||
|
await _lmsClient.StopAsync(_player.MacAddress).ConfigureAwait(false);
|
||||||
|
await ReportPlaybackStoppedAsync().ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PlaystateCommand.PreviousTrack:
|
||||||
|
if (_playlistIndex > 0)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Skipping to previous track (index {Index})", _playlistIndex - 1);
|
||||||
|
await PlayItemAtIndexAsync(_playlistIndex - 1).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// At first track, restart from beginning
|
||||||
|
_logger.LogInformation("At first track, restarting from beginning");
|
||||||
|
await _lmsClient.SeekAsync(_player.MacAddress, 0).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
_logger.LogDebug("Unhandled playstate command: {Command}", playstateRequest.Command);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task HandleGeneralCommandAsync<T>(T data, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
if (data is not GeneralCommand command)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Expected GeneralCommand but got {Type}", data?.GetType().Name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogDebug(
|
||||||
|
"General command {CommandName} for player {PlayerName}",
|
||||||
|
command.Name,
|
||||||
|
_player.Name);
|
||||||
|
|
||||||
|
switch (command.Name)
|
||||||
|
{
|
||||||
|
case GeneralCommandType.SetVolume:
|
||||||
|
if (command.Arguments.TryGetValue("Volume", out var volumeStr) &&
|
||||||
|
int.TryParse(volumeStr, out var volume))
|
||||||
|
{
|
||||||
|
await _lmsClient.SetVolumeAsync(_player.MacAddress, volume).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GeneralCommandType.VolumeUp:
|
||||||
|
var currentStatus = await _lmsClient.GetPlayerStatusAsync(_player.MacAddress).ConfigureAwait(false);
|
||||||
|
if (currentStatus != null)
|
||||||
|
{
|
||||||
|
var newVolume = Math.Min(100, currentStatus.Volume + 5);
|
||||||
|
await _lmsClient.SetVolumeAsync(_player.MacAddress, newVolume).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GeneralCommandType.VolumeDown:
|
||||||
|
var status = await _lmsClient.GetPlayerStatusAsync(_player.MacAddress).ConfigureAwait(false);
|
||||||
|
if (status != null)
|
||||||
|
{
|
||||||
|
var newVolume = Math.Max(0, status.Volume - 5);
|
||||||
|
await _lmsClient.SetVolumeAsync(_player.MacAddress, newVolume).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GeneralCommandType.Mute:
|
||||||
|
await _lmsClient.SetVolumeAsync(_player.MacAddress, 0).ConfigureAwait(false);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GeneralCommandType.ToggleMute:
|
||||||
|
// TODO: Track mute state to toggle properly
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
_logger.LogDebug("Unhandled general command: {Command}", command.Name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Builds the playback URL or file path for the given item.
|
||||||
|
/// Returns a tuple of (url/path, isDirectFilePath).
|
||||||
|
/// </summary>
|
||||||
|
private (string Url, bool IsDirectPath) BuildPlaybackUrl(Guid itemId, long startPositionTicks)
|
||||||
|
{
|
||||||
|
var config = Plugin.Instance?.Configuration;
|
||||||
|
|
||||||
|
// Check if direct file path mode is enabled
|
||||||
|
if (config?.UseDirectFilePath == true && _currentItem?.Path != null)
|
||||||
|
{
|
||||||
|
// Try each path mapping until one matches
|
||||||
|
foreach (var mapping in config.GetAllPathMappings())
|
||||||
|
{
|
||||||
|
var directPath = BuildDirectFilePath(_currentItem.Path, mapping.JellyfinPath, mapping.LmsPath);
|
||||||
|
if (directPath != null)
|
||||||
|
{
|
||||||
|
_logger.LogDebug(
|
||||||
|
"Using direct file path with mapping '{JellyfinPath}' -> '{LmsPath}': {OriginalPath} -> {MappedPath}",
|
||||||
|
mapping.JellyfinPath,
|
||||||
|
mapping.LmsPath,
|
||||||
|
_currentItem.Path,
|
||||||
|
directPath);
|
||||||
|
return (directPath, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogWarning(
|
||||||
|
"Direct file path mode enabled but no path mapping matched for: {Path}",
|
||||||
|
_currentItem.Path);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fall back to HTTP streaming
|
||||||
|
return (BuildStreamUrlWithPosition(itemId, startPositionTicks), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if the current item can use native LMS seeking (direct file path mode).
|
||||||
|
/// </summary>
|
||||||
|
private bool CanSeekNatively()
|
||||||
|
{
|
||||||
|
var config = Plugin.Instance?.Configuration;
|
||||||
|
if (config?.UseDirectFilePath != true || _currentItem?.Path == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if any mapping matches the current item's path
|
||||||
|
foreach (var mapping in config.GetAllPathMappings())
|
||||||
|
{
|
||||||
|
var normalizedPath = _currentItem.Path.Replace('\\', '/');
|
||||||
|
var normalizedPrefix = mapping.JellyfinPath.TrimEnd('/', '\\').Replace('\\', '/');
|
||||||
|
if (normalizedPath.StartsWith(normalizedPrefix, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Maps a Jellyfin file path to an LMS file path using the configured path prefixes.
|
||||||
|
/// </summary>
|
||||||
|
private static string? BuildDirectFilePath(string jellyfinPath, string jellyfinPrefix, string lmsPrefix)
|
||||||
|
{
|
||||||
|
// Normalize path separators for comparison
|
||||||
|
var normalizedPath = jellyfinPath.Replace('\\', '/');
|
||||||
|
var normalizedJellyfinPrefix = jellyfinPrefix.TrimEnd('/', '\\').Replace('\\', '/');
|
||||||
|
var normalizedLmsPrefix = lmsPrefix.TrimEnd('/', '\\').Replace('\\', '/');
|
||||||
|
|
||||||
|
if (!normalizedPath.StartsWith(normalizedJellyfinPrefix, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace the prefix
|
||||||
|
var relativePath = normalizedPath[normalizedJellyfinPrefix.Length..];
|
||||||
|
return normalizedLmsPrefix + relativePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string BuildStreamUrl(Guid itemId)
|
||||||
|
{
|
||||||
|
return BuildStreamUrlWithPosition(itemId, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private string BuildStreamUrlWithPosition(Guid itemId, long startPositionTicks)
|
||||||
|
{
|
||||||
|
var config = Plugin.Instance?.Configuration;
|
||||||
|
var jellyfinUrl = config?.JellyfinServerUrl?.TrimEnd('/') ?? "http://localhost:8096";
|
||||||
|
var apiKey = config?.JellyfinApiKey ?? string.Empty;
|
||||||
|
|
||||||
|
string url;
|
||||||
|
|
||||||
|
if (startPositionTicks > 0)
|
||||||
|
{
|
||||||
|
// For seeking, we need to use transcoding (static=true doesn't support startTimeTicks)
|
||||||
|
// Use MP3 transcoding with the start position
|
||||||
|
// Add a cache-busting parameter to ensure we get a fresh stream on each seek
|
||||||
|
var cacheBuster = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||||
|
url = $"{jellyfinUrl}/Audio/{itemId}/stream.mp3?audioCodec=mp3&audioBitRate=320000&startTimeTicks={startPositionTicks}&_={cacheBuster}";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// For normal playback from start, use static streaming (better quality, no transcoding)
|
||||||
|
url = $"{jellyfinUrl}/Audio/{itemId}/stream.mp3?static=true";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(apiKey))
|
||||||
|
{
|
||||||
|
url += $"&api_key={apiKey}";
|
||||||
|
}
|
||||||
|
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Dispose(true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Disposes managed resources.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">Whether to dispose managed resources.</param>
|
||||||
|
protected virtual void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (_disposed)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
StopProgressTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
_disposed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,313 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Jellyfin.Plugin.JellyLMS.Configuration;
|
||||||
|
using Jellyfin.Plugin.JellyLMS.Models;
|
||||||
|
using MediaBrowser.Controller.Library;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace Jellyfin.Plugin.JellyLMS.Services;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Manages active playback sessions between Jellyfin and LMS.
|
||||||
|
/// </summary>
|
||||||
|
public class LmsSessionManager : IHostedService
|
||||||
|
{
|
||||||
|
private readonly ILogger<LmsSessionManager> _logger;
|
||||||
|
private readonly ILmsApiClient _lmsClient;
|
||||||
|
private readonly LmsPlayerManager _playerManager;
|
||||||
|
private readonly ILibraryManager _libraryManager;
|
||||||
|
private readonly ConcurrentDictionary<string, LmsPlaybackSession> _sessions = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="LmsSessionManager"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="logger">The logger instance.</param>
|
||||||
|
/// <param name="lmsClient">The LMS API client.</param>
|
||||||
|
/// <param name="playerManager">The player manager.</param>
|
||||||
|
/// <param name="libraryManager">The Jellyfin library manager.</param>
|
||||||
|
public LmsSessionManager(
|
||||||
|
ILogger<LmsSessionManager> logger,
|
||||||
|
ILmsApiClient lmsClient,
|
||||||
|
LmsPlayerManager playerManager,
|
||||||
|
ILibraryManager libraryManager)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_lmsClient = lmsClient;
|
||||||
|
_playerManager = playerManager;
|
||||||
|
_libraryManager = libraryManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
private PluginConfiguration Config => Plugin.Instance?.Configuration ?? new PluginConfiguration();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all active sessions.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>List of active sessions.</returns>
|
||||||
|
public List<LmsPlaybackSession> GetActiveSessions()
|
||||||
|
{
|
||||||
|
return _sessions.Values.Where(s => s.State != PlaybackState.Stopped).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a session by ID.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sessionId">The session ID.</param>
|
||||||
|
/// <returns>The session, or null if not found.</returns>
|
||||||
|
public LmsPlaybackSession? GetSession(string sessionId)
|
||||||
|
{
|
||||||
|
return _sessions.GetValueOrDefault(sessionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Starts playback of a Jellyfin item on LMS players.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="itemId">The Jellyfin item ID.</param>
|
||||||
|
/// <param name="playerMacs">The LMS player MAC addresses.</param>
|
||||||
|
/// <param name="userId">Optional user ID.</param>
|
||||||
|
/// <returns>The created session.</returns>
|
||||||
|
public async Task<LmsPlaybackSession?> StartPlaybackAsync(
|
||||||
|
Guid itemId,
|
||||||
|
IEnumerable<string> playerMacs,
|
||||||
|
Guid? userId = null)
|
||||||
|
{
|
||||||
|
var macList = playerMacs.ToList();
|
||||||
|
if (macList.Count == 0)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("No players specified for playback");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var item = _libraryManager.GetItemById(itemId);
|
||||||
|
if (item == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Item {ItemId} not found", itemId);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build the audio stream URL
|
||||||
|
var streamUrl = BuildStreamUrl(itemId);
|
||||||
|
|
||||||
|
var session = new LmsPlaybackSession
|
||||||
|
{
|
||||||
|
ItemId = itemId,
|
||||||
|
ItemName = item.Name,
|
||||||
|
PlayerMacs = macList,
|
||||||
|
State = PlaybackState.Playing,
|
||||||
|
StreamUrl = streamUrl,
|
||||||
|
UserId = userId,
|
||||||
|
RuntimeTicks = item.RunTimeTicks ?? 0
|
||||||
|
};
|
||||||
|
|
||||||
|
// If multiple players, sync them first
|
||||||
|
if (macList.Count > 1)
|
||||||
|
{
|
||||||
|
var masterMac = macList[0];
|
||||||
|
var slaveMacs = macList.Skip(1);
|
||||||
|
await _playerManager.CreateSyncGroupAsync(masterMac, slaveMacs).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start playback on the first player (others will sync)
|
||||||
|
var targetMac = macList[0];
|
||||||
|
var success = await _lmsClient.PlayUrlAsync(targetMac, streamUrl, item.Name).ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (!success)
|
||||||
|
{
|
||||||
|
_logger.LogError("Failed to start playback on player {Mac}", targetMac);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
_sessions[session.SessionId] = session;
|
||||||
|
_logger.LogInformation(
|
||||||
|
"Started playback session {SessionId} for {Item} on {Count} players",
|
||||||
|
session.SessionId,
|
||||||
|
item.Name,
|
||||||
|
macList.Count);
|
||||||
|
|
||||||
|
return session;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Pauses a playback session.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sessionId">The session ID.</param>
|
||||||
|
/// <returns>True if successful.</returns>
|
||||||
|
public async Task<bool> PauseSessionAsync(string sessionId)
|
||||||
|
{
|
||||||
|
if (!_sessions.TryGetValue(sessionId, out var session))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pause the master player (synced players will follow)
|
||||||
|
var success = await _lmsClient.PauseAsync(session.PlayerMacs[0]).ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
session.State = PlaybackState.Paused;
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Resumes a paused playback session.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sessionId">The session ID.</param>
|
||||||
|
/// <returns>True if successful.</returns>
|
||||||
|
public async Task<bool> ResumeSessionAsync(string sessionId)
|
||||||
|
{
|
||||||
|
if (!_sessions.TryGetValue(sessionId, out var session))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var success = await _lmsClient.PlayAsync(session.PlayerMacs[0]).ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
session.State = PlaybackState.Playing;
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Stops a playback session.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sessionId">The session ID.</param>
|
||||||
|
/// <returns>True if successful.</returns>
|
||||||
|
public async Task<bool> StopSessionAsync(string sessionId)
|
||||||
|
{
|
||||||
|
if (!_sessions.TryGetValue(sessionId, out var session))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var success = await _lmsClient.StopAsync(session.PlayerMacs[0]).ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
session.State = PlaybackState.Stopped;
|
||||||
|
|
||||||
|
// Unsync players if there were multiple
|
||||||
|
if (session.PlayerMacs.Count > 1)
|
||||||
|
{
|
||||||
|
await _playerManager.DissolveSyncGroupAsync(session.PlayerMacs[0]).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove the session
|
||||||
|
_sessions.TryRemove(sessionId, out _);
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Seeks to a position in the playback session.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sessionId">The session ID.</param>
|
||||||
|
/// <param name="positionTicks">The position in ticks.</param>
|
||||||
|
/// <returns>True if successful.</returns>
|
||||||
|
public async Task<bool> SeekAsync(string sessionId, long positionTicks)
|
||||||
|
{
|
||||||
|
if (!_sessions.TryGetValue(sessionId, out var session))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var positionSeconds = positionTicks / TimeSpan.TicksPerSecond;
|
||||||
|
var success = await _lmsClient.SeekAsync(session.PlayerMacs[0], positionSeconds).ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
session.PositionTicks = positionTicks;
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the volume for all players in a session.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sessionId">The session ID.</param>
|
||||||
|
/// <param name="volume">The volume level (0-100).</param>
|
||||||
|
/// <returns>True if successful.</returns>
|
||||||
|
public async Task<bool> SetVolumeAsync(string sessionId, int volume)
|
||||||
|
{
|
||||||
|
if (!_sessions.TryGetValue(sessionId, out var session))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var success = true;
|
||||||
|
foreach (var mac in session.PlayerMacs)
|
||||||
|
{
|
||||||
|
if (!await _lmsClient.SetVolumeAsync(mac, volume).ConfigureAwait(false))
|
||||||
|
{
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates the session state from LMS.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sessionId">The session ID.</param>
|
||||||
|
/// <returns>A task representing the operation.</returns>
|
||||||
|
public async Task RefreshSessionStateAsync(string sessionId)
|
||||||
|
{
|
||||||
|
if (!_sessions.TryGetValue(sessionId, out var session))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var status = await _lmsClient.GetPlayerStatusAsync(session.PlayerMacs[0]).ConfigureAwait(false);
|
||||||
|
if (status == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
session.PositionTicks = (long)(status.Time * TimeSpan.TicksPerSecond);
|
||||||
|
session.State = status.Mode switch
|
||||||
|
{
|
||||||
|
"play" => PlaybackState.Playing,
|
||||||
|
"pause" => PlaybackState.Paused,
|
||||||
|
_ => PlaybackState.Stopped
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private string BuildStreamUrl(Guid itemId)
|
||||||
|
{
|
||||||
|
var baseUrl = Config.JellyfinServerUrl.TrimEnd('/');
|
||||||
|
// Direct stream URL - LMS will pull audio from Jellyfin
|
||||||
|
return $"{baseUrl}/Audio/{itemId}/stream.mp3";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public Task StartAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("LMS Session Manager started");
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public Task StopAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("LMS Session Manager stopping");
|
||||||
|
|
||||||
|
// Stop all active sessions
|
||||||
|
foreach (var sessionId in _sessions.Keys.ToList())
|
||||||
|
{
|
||||||
|
_ = StopSessionAsync(sessionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jellyfin.Plugin.Template", "Jellyfin.Plugin.Template\Jellyfin.Plugin.Template.csproj", "{D921B930-CF91-406F-ACBC-08914DCD0D34}"
|
|
||||||
EndProject
|
|
||||||
Global
|
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
|
||||||
Debug|Any CPU = Debug|Any CPU
|
|
||||||
Release|Any CPU = Release|Any CPU
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
|
||||||
{D921B930-CF91-406F-ACBC-08914DCD0D34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{D921B930-CF91-406F-ACBC-08914DCD0D34}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{D921B930-CF91-406F-ACBC-08914DCD0D34}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{D921B930-CF91-406F-ACBC-08914DCD0D34}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
|
||||||
EndGlobal
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
using MediaBrowser.Model.Plugins;
|
|
||||||
|
|
||||||
namespace Jellyfin.Plugin.Template.Configuration;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The configuration options.
|
|
||||||
/// </summary>
|
|
||||||
public enum SomeOptions
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Option one.
|
|
||||||
/// </summary>
|
|
||||||
OneOption,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Second option.
|
|
||||||
/// </summary>
|
|
||||||
AnotherOption
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Plugin configuration.
|
|
||||||
/// </summary>
|
|
||||||
public class PluginConfiguration : BasePluginConfiguration
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="PluginConfiguration"/> class.
|
|
||||||
/// </summary>
|
|
||||||
public PluginConfiguration()
|
|
||||||
{
|
|
||||||
// set default options here
|
|
||||||
Options = SomeOptions.AnotherOption;
|
|
||||||
TrueFalseSetting = true;
|
|
||||||
AnInteger = 2;
|
|
||||||
AString = "string";
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets a value indicating whether some true or false setting is enabled..
|
|
||||||
/// </summary>
|
|
||||||
public bool TrueFalseSetting { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets an integer setting.
|
|
||||||
/// </summary>
|
|
||||||
public int AnInteger { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets a string setting.
|
|
||||||
/// </summary>
|
|
||||||
public string AString { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets an enum option.
|
|
||||||
/// </summary>
|
|
||||||
public SomeOptions Options { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Template</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="TemplateConfigPage" 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="TemplateConfigForm">
|
|
||||||
<div class="selectContainer">
|
|
||||||
<label class="selectLabel" for="Options">Several Options</label>
|
|
||||||
<select is="emby-select" id="Options" name="Options" class="emby-select-withcolor emby-select">
|
|
||||||
<option id="optOneOption" value="OneOption">One Option</option>
|
|
||||||
<option id="optAnotherOption" value="AnotherOption">Another Option</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="inputContainer">
|
|
||||||
<label class="inputLabel inputLabelUnfocused" for="AnInteger">An Integer</label>
|
|
||||||
<input id="AnInteger" name="AnInteger" type="number" is="emby-input" min="0" />
|
|
||||||
<div class="fieldDescription">A Description</div>
|
|
||||||
</div>
|
|
||||||
<div class="checkboxContainer checkboxContainer-withDescription">
|
|
||||||
<label class="emby-checkbox-label">
|
|
||||||
<input id="TrueFalseSetting" name="TrueFalseCheckBox" type="checkbox" is="emby-checkbox" />
|
|
||||||
<span>A Checkbox</span>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
<div class="inputContainer">
|
|
||||||
<label class="inputLabel inputLabelUnfocused" for="AString">A String</label>
|
|
||||||
<input id="AString" name="AString" type="text" is="emby-input" />
|
|
||||||
<div class="fieldDescription">Another Description</div>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<button is="emby-button" type="submit" class="raised button-submit block emby-button">
|
|
||||||
<span>Save</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<script type="text/javascript">
|
|
||||||
var TemplateConfig = {
|
|
||||||
pluginUniqueId: 'eb5d7894-8eef-4b36-aa6f-5d124e828ce1'
|
|
||||||
};
|
|
||||||
|
|
||||||
document.querySelector('#TemplateConfigPage')
|
|
||||||
.addEventListener('pageshow', function() {
|
|
||||||
Dashboard.showLoadingMsg();
|
|
||||||
ApiClient.getPluginConfiguration(TemplateConfig.pluginUniqueId).then(function (config) {
|
|
||||||
document.querySelector('#Options').value = config.Options;
|
|
||||||
document.querySelector('#AnInteger').value = config.AnInteger;
|
|
||||||
document.querySelector('#TrueFalseSetting').checked = config.TrueFalseSetting;
|
|
||||||
document.querySelector('#AString').value = config.AString;
|
|
||||||
Dashboard.hideLoadingMsg();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
document.querySelector('#TemplateConfigForm')
|
|
||||||
.addEventListener('submit', function(e) {
|
|
||||||
Dashboard.showLoadingMsg();
|
|
||||||
ApiClient.getPluginConfiguration(TemplateConfig.pluginUniqueId).then(function (config) {
|
|
||||||
config.Options = document.querySelector('#Options').value;
|
|
||||||
config.AnInteger = document.querySelector('#AnInteger').value;
|
|
||||||
config.TrueFalseSetting = document.querySelector('#TrueFalseSetting').checked;
|
|
||||||
config.AString = document.querySelector('#AString').value;
|
|
||||||
ApiClient.updatePluginConfiguration(TemplateConfig.pluginUniqueId, config).then(function (result) {
|
|
||||||
Dashboard.processPluginConfigurationUpdateResult(result);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
e.preventDefault();
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,373 +1,259 @@
|
|||||||
# So you want to make a Jellyfin plugin
|
# JellyLMS
|
||||||
|
|
||||||
Awesome! This guide is for you. Jellyfin plugins are written using the dotnet standard framework. What that means is you can write them in any language that implements the CLI or the DLI and can compile to net6.0. The examples on this page are in C# because that is what most of Jellyfin is written in, but F#, Visual Basic, and IronPython should all be compatible once compiled.
|
A Jellyfin plugin that bridges audio playback to Logitech Media Server (LMS) for multi-room synchronized playback.
|
||||||
|
|
||||||
## 0. Things you need to get started
|
## Quick Install
|
||||||
|
|
||||||
- [Dotnet SDK 6.0](https://dotnet.microsoft.com/download)
|
Add the following repository URL to your Jellyfin server to install JellyLMS directly from the plugin catalog:
|
||||||
|
|
||||||
- An editor of your choice. Some free choices are:
|
|
||||||
|
|
||||||
[Visual Studio Code](https://code.visualstudio.com)
|
|
||||||
|
|
||||||
[Visual Studio Community Edition](https://visualstudio.microsoft.com/downloads)
|
|
||||||
|
|
||||||
[Mono Develop](https://www.monodevelop.com)
|
|
||||||
|
|
||||||
## 0.5. Quickstarts
|
|
||||||
|
|
||||||
We have a number of quickstart options available to speed you along the way.
|
|
||||||
|
|
||||||
- [Download the Example Plugin Project](https://github.com/jellyfin/jellyfin-plugin-template/tree/master/Jellyfin.Plugin.Template) from this repository, open it in your IDE and go to [step 3](https://github.com/jellyfin/jellyfin-plugin-template#3-customize-plugin-information)
|
|
||||||
|
|
||||||
- Install our dotnet template by [downloading the dotnet-template/content folder from this repo](https://github.com/jellyfin/jellyfin-plugin-template/tree/master/dotnet-template/content) or off of Nuget (Coming soon)
|
|
||||||
|
|
||||||
```
|
|
||||||
dotnet new -i /path/to/templatefolder
|
|
||||||
```
|
|
||||||
|
|
||||||
- Run this command then skip to step 4
|
|
||||||
|
|
||||||
```
|
|
||||||
dotnet new Jellyfin-plugin -name MyPlugin
|
|
||||||
```
|
|
||||||
|
|
||||||
If you'd rather start from scratch keep going on to step one. This assumes no specific editor or IDE and requires only the command line with dotnet in the path.
|
|
||||||
|
|
||||||
## 1. Initialize Your Project
|
|
||||||
|
|
||||||
Make a new dotnet standard project with the following command, it will make a directory for itself.
|
|
||||||
|
|
||||||
```
|
```
|
||||||
dotnet new classlib -f net6.0 -n MyJellyfinPlugin
|
https://gitea.tourolle.paris/dtourolle/jellyLMS/raw/branch/master/manifest.json
|
||||||
```
|
```
|
||||||
|
|
||||||
Now add the Jellyfin shared libraries.
|
**Steps:**
|
||||||
|
1. Go to **Dashboard** → **Plugins** → **Repositories**
|
||||||
|
2. Click **Add** and paste the URL above
|
||||||
|
3. Go to **Catalog** and find "JellyLMS"
|
||||||
|
4. Click **Install** and restart Jellyfin
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
JellyLMS enables Jellyfin to stream audio to LMS, which acts as a multi-room speaker system. The architecture is:
|
||||||
|
|
||||||
|
- **Jellyfin** owns the library, queue, and playback intent
|
||||||
|
- **LMS** owns synchronized audio delivery to players (Squeezebox, piCorePlayer, etc.)
|
||||||
|
|
||||||
```
|
```
|
||||||
dotnet add package Jellyfin.Model
|
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
|
||||||
dotnet add package Jellyfin.Controller
|
│ Jellyfin │ │ JellyLMS │ │ LMS │
|
||||||
|
│ │ │ Plugin │ │ │
|
||||||
|
│ ┌───────────┐ │ │ │ │ ┌───────────┐ │
|
||||||
|
│ │ Library │──┼────────►│ LmsApiClient │────────►│ │ Players │ │
|
||||||
|
│ │ (Audio) │ │ │ │ │ │ (Zones) │ │
|
||||||
|
│ └───────────┘ │ │ ┌───────────┐ │ │ └───────────┘ │
|
||||||
|
│ │ │ │ Session │ │ │ │
|
||||||
|
│ ┌───────────┐ │ │ │ Manager │ │ │ ┌───────────┐ │
|
||||||
|
│ │ Queue │──┼────────►│ └───────────┘ │────────►│ │ Sync │ │
|
||||||
|
│ │ │ │ │ │ │ │ Groups │ │
|
||||||
|
│ └───────────┘ │ │ ┌───────────┐ │ │ └───────────┘ │
|
||||||
|
│ │ │ │ REST API │ │ │ │
|
||||||
|
│ ┌───────────┐ │ │ │Controller │ │ │ │
|
||||||
|
│ │ Playback │──┼────────►│ └───────────┘ │ │ │
|
||||||
|
│ │ Controls │ │ │ │ │ │
|
||||||
|
│ └───────────┘ │ └─────────────────┘ └─────────────────┘
|
||||||
|
└─────────────────┘
|
||||||
```
|
```
|
||||||
|
|
||||||
You have an autogenerated Class1.cs file. You won't be needing this, so go ahead and delete it.
|
## Features
|
||||||
|
|
||||||
## 2. Set Up the Basics
|
- **Player Discovery**: Automatically discovers all LMS players/zones
|
||||||
|
- **Multi-Room Sync**: Create and manage sync groups for synchronized playback across multiple rooms
|
||||||
|
- **Playback Control**: Play, pause, stop, seek, and volume control forwarded to LMS
|
||||||
|
- **Stream Bridging**: Generates audio stream URLs from Jellyfin for LMS to consume
|
||||||
|
|
||||||
There are a few mandatory classes you'll need for a plugin so we need to make them.
|
## Screenshots
|
||||||
|
|
||||||
### PluginConfiguration
|
### Cast to LMS Players
|
||||||
|
Select any LMS player directly from Jellyfin's "Play On" menu:
|
||||||
|
|
||||||
You can call it whatever you'd like really. This class is used to hold settings your plugin might need. We can leave it empty for now. This class should inherit from `MediaBrowser.Model.Plugins.BasePluginConfiguration`
|

|
||||||
|
|
||||||
### Plugin
|
### Plugin Configuration
|
||||||
|
Configure LMS and Jellyfin server connections:
|
||||||
|
|
||||||
This is the main class for your plugin. It will define your name, version and Id. It should inherit from `MediaBrowser.Common.Plugins.BasePlugin<PluginConfiguration>`
|

|
||||||
|
|
||||||
Note: If you called your PluginConfiguration class something different, you need to put that between the <>
|
### Player Discovery
|
||||||
|
View discovered LMS players with their status and volume levels:
|
||||||
|
|
||||||
### Implement Required Properties
|

|
||||||
|
|
||||||
The Plugin class needs a few properties implemented before it can work correctly.
|
### Sync Group Management
|
||||||
|
Create and manage synchronized playback groups for multi-room audio:
|
||||||
|
|
||||||
It needs an override on ID, an override on Name, and a constructor that follows a specific model. To get started you can use the following section.
|

|
||||||
|
|
||||||
```c#
|
## Requirements
|
||||||
public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer) : base(applicationPaths, xmlSerializer){}
|
|
||||||
public override string Name => throw new System.NotImplementedException();
|
- Jellyfin Server 10.10.0 or later
|
||||||
public override Guid Id => Guid.Parse("");
|
- .NET 8.0 Runtime
|
||||||
|
- Logitech Media Server (LMS) with JSON-RPC API enabled (default on port 9000)
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
### Manual Installation
|
||||||
|
|
||||||
|
1. Download the latest release or build from source
|
||||||
|
2. Copy `Jellyfin.Plugin.JellyLMS.dll` to your Jellyfin plugins directory:
|
||||||
|
- **Linux**: `~/.local/share/jellyfin/plugins/JellyLMS/`
|
||||||
|
- **Windows**: `%APPDATA%\jellyfin\plugins\JellyLMS\`
|
||||||
|
- **Docker**: `/config/plugins/JellyLMS/`
|
||||||
|
3. Restart Jellyfin
|
||||||
|
|
||||||
|
### Building from Source
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Clone the repository
|
||||||
|
git clone https://gitea.tourolle.paris/dtourolle/jellyLMS.git
|
||||||
|
cd jellyLMS
|
||||||
|
|
||||||
|
# Build
|
||||||
|
dotnet build Jellyfin.Plugin.JellyLMS.sln -c Release
|
||||||
|
|
||||||
|
# The DLL will be in:
|
||||||
|
# Jellyfin.Plugin.JellyLMS/bin/Release/net8.0/
|
||||||
```
|
```
|
||||||
|
|
||||||
## 3. Customize Plugin Information
|
## Configuration
|
||||||
|
|
||||||
You need to populate some of your plugin's information. Go ahead a put in a string of the Name you've overridden name, and generate a GUID
|
1. Navigate to Jellyfin Dashboard → Plugins → JellyLMS
|
||||||
|
2. Configure the following settings:
|
||||||
|
|
||||||
- **Windows Users**: you can use the Powershell command `New-Guid`, `[guid]::NewGuid()` or the Visual Studio GUID generator
|
| Setting | Description | Default |
|
||||||
|
|---------|-------------|---------|
|
||||||
|
| LMS Server URL | Full URL to your LMS server | `http://localhost:9000` |
|
||||||
|
| Jellyfin Server URL | URL where LMS can reach Jellyfin | `http://localhost:8096` |
|
||||||
|
| Connection Timeout | Timeout for LMS API calls (seconds) | `10` |
|
||||||
|
| Enable Auto Sync | Automatically sync players when creating groups | `true` |
|
||||||
|
| Default Player | MAC address of the default player | (none) |
|
||||||
|
|
||||||
- **Linux and OS X Users**: you can use the Powershell Core command `New-Guid` or this command from your shell of choice:
|
3. Click "Test Connection" to verify connectivity to LMS
|
||||||
|
4. Use "Discover Players" to see available LMS players
|
||||||
|
|
||||||
```bash
|
## API Endpoints
|
||||||
od -x /dev/urandom | head -1 | awk '{OFS="-"; srand($6); sub(/./,"4",$5); sub(/./,substr("89ab",rand()*4,1),$6); print $2$3,$4,$5,$6,$7$8$9}'
|
|
||||||
```
|
|
||||||
|
|
||||||
or
|
The plugin exposes REST API endpoints under `/JellyLms/`:
|
||||||
|
|
||||||
```bash
|
### Players
|
||||||
uuidgen
|
|
||||||
```
|
|
||||||
|
|
||||||
- Place that guid inside the `Guid.Parse("")` quotes to define your plugin's ID.
|
- `GET /JellyLms/Players` - List all LMS players
|
||||||
|
- `GET /JellyLms/Players/{mac}` - Get specific player details
|
||||||
|
- `POST /JellyLms/Players/Refresh` - Refresh player list from LMS
|
||||||
|
|
||||||
## 4. Adding Functionality
|
### Sync Groups
|
||||||
|
|
||||||
Congratulations, you now have everything you need for a perfectly functional functionless Jellyfin plugin! You can try it out right now if you'd like by compiling it, then placing the dll you generate in a subfolder (named after your plugin for example) within the plugins folder under your Jellyfin config directory. If you want to try and hook it up to a debugger make sure you copy the generated PDB file alongside it.
|
- `GET /JellyLms/SyncGroups` - List all sync groups
|
||||||
|
- `POST /JellyLms/SyncGroups` - Create a new sync group
|
||||||
|
- `DELETE /JellyLms/SyncGroups/{masterMac}` - Dissolve a sync group
|
||||||
|
- `DELETE /JellyLms/SyncGroups/{masterMac}/Players/{slaveMac}` - Remove player from group
|
||||||
|
|
||||||
Most people aren't satisfied with just having an entry in a menu for their plugin, most people want to have some functionality, so lets look at how to add it.
|
### Sessions
|
||||||
|
|
||||||
### 4a. Implement Interfaces
|
- `GET /JellyLms/Sessions` - List active playback sessions
|
||||||
|
- `POST /JellyLms/Sessions` - Start a new playback session
|
||||||
|
- `POST /JellyLms/Sessions/{id}/Pause` - Pause playback
|
||||||
|
- `POST /JellyLms/Sessions/{id}/Resume` - Resume playback
|
||||||
|
- `POST /JellyLms/Sessions/{id}/Stop` - Stop playback
|
||||||
|
- `POST /JellyLms/Sessions/{id}/Seek` - Seek to position
|
||||||
|
- `POST /JellyLms/Sessions/{id}/Volume` - Set volume
|
||||||
|
|
||||||
If the functionality you are trying to add is functionality related to something that Jellyfin has an interface for you're in luck. Jellyfin uses some automatic discovery and injection to allow any interfaces you implement in your plugin to be available in Jellyfin.
|
### Status
|
||||||
|
|
||||||
Here's some interfaces you could implement for common use cases:
|
- `GET /JellyLms/Status` - Get LMS connection status
|
||||||
|
- `POST /JellyLms/TestConnection` - Test LMS connectivity
|
||||||
|
|
||||||
- **IAuthenticationProvider** - Allows you to add an authentication provider that can authenticate a user based on a name and a password, but that doesn't expect to deal with local users.
|
## LMS Setup
|
||||||
- **IBaseItemComparer** - Allows you to add sorting rules for dealing with media that will show up in sort menus
|
|
||||||
- **IIntroProvider** - Allows you to play a piece of media before another piece of media (i.e. a trailer before a movie, or a network bumper before an episode of a show)
|
|
||||||
- **IItemResolver** - Allows you to define custom media types
|
|
||||||
- **ILibraryPostScanTask** - Allows you to define a task that fires after scanning a library
|
|
||||||
- **IMetadataSaver** - Allows you to define a metadata standard that Jellyfin can use to write metadata
|
|
||||||
- **IResolverIgnoreRule** - Allows you to define subpaths that are ignored by media resolvers for use with another function (i.e. you wanted to have a theme song for each tv series stored in a subfolder that could be accessed by your plugin for playback in a menu).
|
|
||||||
- **IScheduledTask** - Allows you to create a scheduled task that will appear in the scheduled task lists on the dashboard.
|
|
||||||
|
|
||||||
There are loads of other interfaces that can be used, but you'll need to poke around the API to get some info. If you're an expert on a particular interface, you should help [contribute some documentation](https://docs.jellyfin.org/general/contributing/index.html)!
|
Ensure your LMS server has the JSON-RPC API available. This is enabled by default and accessible at:
|
||||||
|
|
||||||
### 4b. Use plugin aimed interfaces to add custom functionality
|
```
|
||||||
|
http://<lms-server>:9000/jsonrpc.js
|
||||||
If your plugin doesn't fit perfectly neatly into a predefined interface, never fear, there are a set of interfaces and classes that allow your plugin to extend Jellyfin any which way you please. Here's a quick overview on how to use them
|
|
||||||
|
|
||||||
- **IPluginConfigurationPage** - Allows you to have a plugin config page on the dashboard. If you used one of the quickstart example projects, a premade page with some useful components to work with has been created for you! If not you can check out this guide here for how to whip one up.
|
|
||||||
|
|
||||||
- **IServerEntryPoint** - Allows you to run code at server startup that will stay in memory. You can make as many of these as you need and it is wildly useful for loading configs or persisting state. **Be aware that your main plugin class (IBasePlugin) cannot also be a IServerEntryPoint.**
|
|
||||||
|
|
||||||
- **ControllerBase** - Allows you to define custom REST-API endpoints. This is the default ASP.NET Web-API controller. You can use it exactly as you would in a normal Web-API project. Learn more about it [here](https://docs.microsoft.com/aspnet/core/web-api/?view=aspnetcore-5.0).
|
|
||||||
|
|
||||||
Likewise you might need to get data and services from the Jellyfin core, Jellyfin provides a number of interfaces you can add as parameters to your plugin constructor which are then made available in your project (you can see the 2 mandatory ones that are needed by the plugin system in the constructor as is).
|
|
||||||
|
|
||||||
- **IBlurayExaminer** - Allows you to examine blu-ray folders
|
|
||||||
- **IDtoService** - Allows you to create data transport objects, presumably to send to other plugins or to the core
|
|
||||||
- **ILibraryManager** - Allows you to directly access the media libraries without hopping through the API
|
|
||||||
- **ILocalizationManager** - Allows you tap into the main localization engine which governs translations, rating systems, units etc...
|
|
||||||
- **INetworkManager** - Allows you to get information about the server's networking status
|
|
||||||
- **IServerApplicationPaths** - Allows you to get the running server's paths
|
|
||||||
- **IServerConfigurationManager** - Allows you to write or read server configuration data into the application paths
|
|
||||||
- **ITaskManager** - Allows you to execute and manipulate scheduled tasks
|
|
||||||
- **IUserManager** - Allows you to retrieve user info and user library related info
|
|
||||||
- **IXmlSerializer** - Allows you to use the main xml serializer
|
|
||||||
- **IZipClient** - Allows you to use the core zip client for compressing and decompressing data
|
|
||||||
|
|
||||||
## 5. Create a Repository
|
|
||||||
|
|
||||||
- [See blog post](https://jellyfin.org/posts/plugin-updates/)
|
|
||||||
|
|
||||||
## 6. Set Up Debugging
|
|
||||||
|
|
||||||
Debugging can be set up by creating tasks which will be executed when running the plugin project. The specifics on setting up these tasks are not included as they may differ from IDE to IDE. The following list describes the general process:
|
|
||||||
|
|
||||||
- Compile the plugin in debug mode.
|
|
||||||
- Create the plugin directory if it doesn't exist.
|
|
||||||
- Copy the plugin into your server's plugin directory. The server will then execute it.
|
|
||||||
- Make sure to set the working directory of the program being debugged to the working directory of the Jellyfin Server.
|
|
||||||
- Start the server.
|
|
||||||
|
|
||||||
Some IDEs like Visual Studio Code may need the following compile flags to compile the plugin:
|
|
||||||
|
|
||||||
```shell
|
|
||||||
dotnet build Your-Plugin.sln /property:GenerateFullPaths=true /consoleloggerparameters:NoSummary
|
|
||||||
```
|
```
|
||||||
|
|
||||||
These flags generate the full paths for file names and **do not** generate a summary during the build process as this may lead to duplicate errors in the problem panel of your IDE.
|
The plugin communicates with LMS using the `slim.request` JSON-RPC method.
|
||||||
|
|
||||||
### 6.a Set Up Debugging on Visual Studio
|
## Troubleshooting
|
||||||
|
|
||||||
Visual Studio allows developers to connect to other processes and debug them, setting breakpoints and inspecting the variables of the program. We can set this up following this steps:
|
### Cannot connect to LMS
|
||||||
On this section we will explain how to set up our solution to enable debugging before the server starts.
|
|
||||||
|
|
||||||
1. Right-click on the solution, And click on Add -> Existing Project...
|
1. Verify LMS is running and accessible at the configured URL
|
||||||
2. Locate Jellyfin executable in your installation folder and click on 'Open'. It is called `Jellyfin.exe`. Now The solution will have a new "Project" called Jellyfin. This is the executable, not the source code of Jellyfin.
|
2. Check that the JSON-RPC endpoint responds: `curl http://localhost:9000/jsonrpc.js`
|
||||||
3. Right-click on this new project and click on 'Set up as Startup Project'
|
3. Ensure no firewall is blocking connections between Jellyfin and LMS
|
||||||
4. Right-click on this new project and click on 'Properties'
|
|
||||||
5. Make sure that the 'Attach' parameter is set to 'No'
|
|
||||||
|
|
||||||
From now on, everytime you click on start from Visual Studio, it will start Jellyfin attached to the debugger!
|
### Players not appearing
|
||||||
|
|
||||||
The only thing left to do is to compile the project as it is specified a few lines above and you are done.
|
1. Ensure players are powered on and connected to LMS
|
||||||
|
2. Click "Discover Players" to refresh the player list
|
||||||
|
3. Check LMS web interface to verify players are visible there
|
||||||
|
|
||||||
### 6.b Automate the Setup on Visual Studio Code
|
### Audio not playing
|
||||||
|
|
||||||
Visual Studio Code allows developers to automate the process of starting all necessary dependencies to start debugging the plugin. This guide assumes the reader is familiar with the [documentation on debugging in Visual Studio Code](https://code.visualstudio.com/docs/editor/debugging) and has read the documentation in this file. It is assumed that the Jellyfin Server has already been compiled once. However, should one desire to automatically compile the server before the start of the debugging session, this can be easily implemented, but is not further discussed here.
|
1. Verify Jellyfin server URL is accessible from LMS server
|
||||||
|
2. Check that audio files are in a format supported by your LMS players
|
||||||
|
3. Ensure players are powered on (plugin can auto-power-on if configured)
|
||||||
|
|
||||||
A full example, which aims to be portable may be found in this repo's `.vscode` folder.
|
## Known Limitations
|
||||||
|
|
||||||
This example expects you to clone `jellyfin`, `jellyfin-web` and `jellyfin-plugin-template` under the same parent directory, though you can customize this in `settings.json`
|
### Seeking with HTTP Streaming
|
||||||
|
|
||||||
1. Create a `settings.json` file inside your `.vscode` folder, to specify common options specific to your local setup.
|
When using HTTP streaming (the default), LMS cannot seek within audio streams. To work around this, when you seek or cast from a specific position, JellyLMS restarts playback with a new transcoded stream that begins at the requested position. This means:
|
||||||
```jsonc
|
|
||||||
{
|
|
||||||
// jellyfinDir : The directory of the cloned jellyfin server project
|
|
||||||
// This needs to be built once before it can be used
|
|
||||||
"jellyfinDir" : "${workspaceFolder}/../jellyfin/Jellyfin.Server",
|
|
||||||
// jellyfinWebDir : The directory of the cloned jellyfin-web project
|
|
||||||
// This needs to be built once before it can be used
|
|
||||||
"jellyfinWebDir" : "${workspaceFolder}/../jellyfin-web",
|
|
||||||
// jellyfinDataDir : the root data directory for a running jellyfin instance
|
|
||||||
// This is where jellyfin stores its configs, plugins, metadata etc
|
|
||||||
// This is platform specific by default, but on Windows defaults to
|
|
||||||
// ${env:LOCALAPPDATA}/jellyfin
|
|
||||||
"jellyfinDataDir" : "${env:LOCALAPPDATA}/jellyfin",
|
|
||||||
// The name of the plugin
|
|
||||||
"pluginName" : "Jellyfin.Plugin.Template",
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
1. To automate the launch process, create a new `launch.json` file for C# projects inside the `.vscode` folder. The example below shows only the relevant parts of the file. Adjustments to your specific setup and operating system may be required.
|
- **Seeking triggers a brief audio restart** rather than a smooth jump
|
||||||
|
- **Starting playback mid-track** uses transcoding (MP3 320kbps) instead of direct streaming
|
||||||
|
- **Playback from the beginning** uses direct/static streaming for best quality
|
||||||
|
|
||||||
```jsonc
|
This is a fundamental limitation of how LMS handles HTTP streams.
|
||||||
{
|
|
||||||
// Paths and plugin names are configured in settings.json
|
|
||||||
"version": "0.2.0",
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"type": "coreclr",
|
|
||||||
"name": "Launch",
|
|
||||||
"request": "launch",
|
|
||||||
"preLaunchTask": "build-and-copy",
|
|
||||||
"program": "${config:jellyfinDir}/bin/Debug/net6.0/jellyfin.dll",
|
|
||||||
"args": [
|
|
||||||
//"--nowebclient"
|
|
||||||
"--webdir",
|
|
||||||
"${config:jellyfinWebDir}/dist/"
|
|
||||||
],
|
|
||||||
"cwd": "${config:jellyfinDir}",
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
```
|
### Solution: Direct File Access
|
||||||
|
|
||||||
The `request` type is specified as `launch`, as this `launch.json` file will start the Jellyfin Server process. The `preLaunchTask` defines a task that will run before the Jellyfin Server starts. More on this later. It is important to set the `program` path to the Jellyin Server program and set the current working directory (`cwd`) to the working directory of the Jellyfin Server.
|
If your Jellyfin and LMS servers can both access the same storage (e.g., a NAS), you can enable **Direct File Access** mode in the plugin settings. This allows LMS to read files directly from disk, enabling:
|
||||||
The `args` option allows to specify arguments to be passed to the server, e.g. whether Jellyfin should start with the web-client or without it.
|
|
||||||
|
|
||||||
2. Create a `tasks.json` file inside your `.vscode` folder and specify a `build-and-copy` task that will run in `sequence` order. This tasks depends on multiple other tasks and all of those other tasks can be defined as simple `shell` tasks that run commands like the `cp` command to copy a file. The sequence to run those tasks in is given below. Please note that it might be necessary to adjust the examples for your specific setup and operating system.
|
- **Native smooth seeking** - no audio restart when scrubbing
|
||||||
|
- **Full quality playback** - no transcoding needed
|
||||||
|
- **Better performance** - no HTTP overhead
|
||||||
|
|
||||||
The full file is shown here - Specific sections will be discussed in depth
|
To configure, set the path mappings in the plugin settings:
|
||||||
```jsonc
|
- **Jellyfin Media Path**: The path prefix as Jellyfin sees your library (e.g., `/media/music`)
|
||||||
{
|
- **LMS Media Path**: The same location as LMS sees it (e.g., `/mnt/music` or `//nas/music`)
|
||||||
// Paths and plugin name are configured in settings.json
|
|
||||||
"version": "2.0.0",
|
|
||||||
"tasks": [
|
|
||||||
{
|
|
||||||
// A chain task - build the plugin, then copy it to your
|
|
||||||
// jellyfin server's plugin directory
|
|
||||||
"label": "build-and-copy",
|
|
||||||
"dependsOrder": "sequence",
|
|
||||||
"dependsOn": ["build", "make-plugin-dir", "copy-dll"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// Build the plugin
|
|
||||||
"label": "build",
|
|
||||||
"command": "dotnet",
|
|
||||||
"type": "shell",
|
|
||||||
"args": [
|
|
||||||
"publish",
|
|
||||||
"${workspaceFolder}/${config:pluginName}.sln",
|
|
||||||
"/property:GenerateFullPaths=true",
|
|
||||||
"/consoleloggerparameters:NoSummary"
|
|
||||||
],
|
|
||||||
"group": "build",
|
|
||||||
"presentation": {
|
|
||||||
"reveal": "silent"
|
|
||||||
},
|
|
||||||
"problemMatcher": "$msCompile"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// Ensure the plugin directory exists before trying to use it
|
|
||||||
"label": "make-plugin-dir",
|
|
||||||
"type": "shell",
|
|
||||||
"command": "mkdir",
|
|
||||||
"args": [
|
|
||||||
"-Force",
|
|
||||||
"-Path",
|
|
||||||
"${config:jellyfinDataDir}/plugins/${config:pluginName}/"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// Copy the plugin dll to the jellyfin plugin install path
|
|
||||||
// This command copies every .dll from the build directory to the plugin dir
|
|
||||||
// Usually, you probablly only need ${config:pluginName}.dll
|
|
||||||
// But some plugins may bundle extra requirements
|
|
||||||
"label": "copy-dll",
|
|
||||||
"type": "shell",
|
|
||||||
"command": "cp",
|
|
||||||
"args": [
|
|
||||||
"./${config:pluginName}/bin/Debug/net6.0/publish/*",
|
|
||||||
"${config:jellyfinDataDir}/plugins/${config:pluginName}/"
|
|
||||||
]
|
|
||||||
|
|
||||||
},
|
## Development
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
```
|
### Project Structure
|
||||||
1. The "build-and-copy" task which triggers all of the other tasks
|
|
||||||
```jsonc
|
|
||||||
{
|
|
||||||
// A chain task - build the plugin, then copy it to your
|
|
||||||
// jellyfin server's plugin directory
|
|
||||||
"label": "build-and-copy",
|
|
||||||
"dependsOrder": "sequence",
|
|
||||||
"dependsOn": ["build", "make-plugin-dir", "copy-dll"]
|
|
||||||
},
|
|
||||||
```
|
|
||||||
2. A build task. This task builds the plugin without generating summary, but with full paths for file names enabled.
|
|
||||||
|
|
||||||
```jsonc
|
```
|
||||||
{
|
Jellyfin.Plugin.JellyLMS/
|
||||||
// Build the plugin
|
├── Plugin.cs # Main plugin entry point
|
||||||
"label": "build",
|
├── PluginServiceRegistrator.cs # DI service registration
|
||||||
"command": "dotnet",
|
├── Configuration/
|
||||||
"type": "shell",
|
│ ├── PluginConfiguration.cs # Plugin settings
|
||||||
"args": [
|
│ └── configPage.html # Dashboard configuration UI
|
||||||
"publish",
|
├── Api/
|
||||||
"${workspaceFolder}/${config:pluginName}.sln",
|
│ └── JellyLmsController.cs # REST API endpoints
|
||||||
"/property:GenerateFullPaths=true",
|
├── Services/
|
||||||
"/consoleloggerparameters:NoSummary"
|
│ ├── ILmsApiClient.cs # LMS API interface
|
||||||
],
|
│ ├── LmsApiClient.cs # LMS JSON-RPC client
|
||||||
"group": "build",
|
│ ├── LmsPlayerManager.cs # Player discovery & sync
|
||||||
"presentation": {
|
│ └── LmsSessionManager.cs # Playback session management
|
||||||
"reveal": "silent"
|
└── Models/
|
||||||
},
|
├── LmsPlayer.cs # Player model
|
||||||
"problemMatcher": "$msCompile"
|
├── LmsPlaybackSession.cs # Session state model
|
||||||
},
|
└── LmsApiModels.cs # JSON-RPC DTOs
|
||||||
```
|
```
|
||||||
|
|
||||||
3. A tasks which creates the necessary plugin directory and a sub-folder for the specific plugin. The plugin directory is located below the [data directory](https://jellyfin.org/docs/general/administration/configuration.html) of the Jellyfin Server. As an example, the following path can be used for the bookshelf plugin: `$HOME/.local/share/jellyfin/plugins/Bookshelf/`
|
### Building for Development
|
||||||
```jsonc
|
|
||||||
{
|
|
||||||
// Ensure the plugin directory exists before trying to use it
|
|
||||||
"label": "make-plugin-dir",
|
|
||||||
"type": "shell",
|
|
||||||
"command": "mkdir",
|
|
||||||
"args": [
|
|
||||||
"-Force",
|
|
||||||
"-Path",
|
|
||||||
"${config:jellyfinDataDir}/plugins/${config:pluginName}/"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
```
|
|
||||||
|
|
||||||
4. A tasks which copies the plugin dll which has been built in step 2.1. The file is copied into it's specific plugin directory within the server's plugin directory.
|
```bash
|
||||||
|
# Build in debug mode
|
||||||
|
dotnet build Jellyfin.Plugin.JellyLMS.sln
|
||||||
|
|
||||||
```jsonc
|
# Copy to Jellyfin plugins directory
|
||||||
{
|
cp Jellyfin.Plugin.JellyLMS/bin/Debug/net8.0/Jellyfin.Plugin.JellyLMS.dll \
|
||||||
// Copy the plugin dll to the jellyfin plugin install path
|
~/.local/share/jellyfin/plugins/JellyLMS/
|
||||||
// This command copies every .dll from the build directory to the plugin dir
|
|
||||||
// Usually, you probablly only need ${config:pluginName}.dll
|
|
||||||
// But some plugins may bundle extra requirements
|
|
||||||
"label": "copy-dll",
|
|
||||||
"type": "shell",
|
|
||||||
"command": "cp",
|
|
||||||
"args": [
|
|
||||||
"./${config:pluginName}/bin/Debug/net6.0/publish/*",
|
|
||||||
"${config:jellyfinDataDir}/plugins/${config:pluginName}/"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
```
|
|
||||||
|
|
||||||
## Licensing
|
# Restart Jellyfin to load the plugin
|
||||||
|
```
|
||||||
|
|
||||||
Licensing is a complex topic. This repository features a GPLv3 license template that can be used to provide a good default license for your plugin. You may alter this if you like, but if you do a permissive license must be chosen.
|
## License
|
||||||
|
|
||||||
Due to how plugins in Jellyfin work, when your plugin is compiled into a binary, it will link against the various Jellyfin binary NuGet packages. These packages are licensed under the GPLv3. Thus, due to the nature and restrictions of the GPL, the binary plugin you get will also be licensed under the GPLv3.
|
This plugin is licensed under the GPLv3. See [LICENSE](LICENSE) for details.
|
||||||
|
|
||||||
If you accept the default GPLv3 license from this template, all will be good. However if you choose a different license, please keep this fact in mind, as it might not always be obvious that an, e.g. MIT-licensed plugin would become GPLv3 when compiled.
|
Due to how Jellyfin plugins work, when compiled into a binary, it links against Jellyfin's GPLv3-licensed NuGet packages, making the resulting binary GPLv3 licensed.
|
||||||
|
|
||||||
Please note that this also means making "proprietary", source-unavailable, or otherwise "hidden" plugins for public consumption is not permitted. To build a Jellyfin plugin for distribution to others, it must be under the GPLv3 or a permissive open-source license that can be linked against the GPLv3.
|
## Contributing
|
||||||
|
|
||||||
|
Contributions are welcome! Please open an issue or submit a pull request.
|
||||||
|
|
||||||
|
## Acknowledgments
|
||||||
|
|
||||||
|
- [Jellyfin](https://jellyfin.org/) - The Free Software Media System
|
||||||
|
- [Logitech Media Server](https://github.com/Logitech/slimserver) - Open source server for Squeezebox players
|
||||||
|
|||||||
+12
-10
@@ -1,16 +1,18 @@
|
|||||||
---
|
---
|
||||||
name: "Template"
|
name: "JellyLMS"
|
||||||
guid: "eb5d7894-8eef-4b36-aa6f-5d124e828ce1"
|
guid: "a5b8c9d0-1e2f-3a4b-5c6d-7e8f9a0b1c2d"
|
||||||
version: "1.0.0.0"
|
version: "1.0.0.0"
|
||||||
targetAbi: "10.8.0.0"
|
targetAbi: "10.11.0.0"
|
||||||
framework: "net6.0"
|
framework: "net9.0"
|
||||||
overview: "Short description about your plugin"
|
overview: "Bridge plugin to stream Jellyfin audio to Logitech Media Server (LMS) players"
|
||||||
description: >
|
description: >
|
||||||
This is a longer description that can span more than one
|
JellyLMS enables Jellyfin to stream audio to LMS (Logitech Media Server) for
|
||||||
line and include details about your plugin.
|
multi-room synchronized playback. Jellyfin owns the library, queue, and playback
|
||||||
category: "General"
|
intent while LMS handles synchronized audio delivery to Squeezebox players,
|
||||||
|
piCorePlayer devices, and other LMS-compatible endpoints.
|
||||||
|
category: "Music"
|
||||||
owner: "jellyfin"
|
owner: "jellyfin"
|
||||||
artifacts:
|
artifacts:
|
||||||
- "Jellyfin.Plugin.Template.dll"
|
- "Jellyfin.Plugin.JellyLMS.dll"
|
||||||
changelog: >
|
changelog: >
|
||||||
changelog
|
Initial release with LMS integration for multi-room audio playback.
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 84 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 127 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 62 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 50 KiB |
+21
-2
@@ -38,8 +38,8 @@
|
|||||||
</Rules>
|
</Rules>
|
||||||
|
|
||||||
<Rules AnalyzerId="Microsoft.CodeAnalysis.NetAnalyzers" RuleNamespace="Microsoft.Design">
|
<Rules AnalyzerId="Microsoft.CodeAnalysis.NetAnalyzers" RuleNamespace="Microsoft.Design">
|
||||||
<!-- error on CA1305: Specify IFormatProvider -->
|
<!-- warning on CA1305: Specify IFormatProvider (changed from Error for locale-independent conversions) -->
|
||||||
<Rule Id="CA1305" Action="Error" />
|
<Rule Id="CA1305" Action="Warning" />
|
||||||
<!-- error on CA1725: Parameter names should match base declaration -->
|
<!-- error on CA1725: Parameter names should match base declaration -->
|
||||||
<Rule Id="CA1725" Action="Error" />
|
<Rule Id="CA1725" Action="Error" />
|
||||||
<!-- error on CA1725: Call async methods when in an async method -->
|
<!-- error on CA1725: Call async methods when in an async method -->
|
||||||
@@ -104,5 +104,24 @@
|
|||||||
<Rule Id="CA2101" Action="None" />
|
<Rule Id="CA2101" Action="None" />
|
||||||
<!-- disable warning CA2234: Pass System.Uri objects instead of strings -->
|
<!-- disable warning CA2234: Pass System.Uri objects instead of strings -->
|
||||||
<Rule Id="CA2234" Action="None" />
|
<Rule Id="CA2234" Action="None" />
|
||||||
|
<!-- disable warning CA1002: Do not expose generic lists (common in DTOs/API models) -->
|
||||||
|
<Rule Id="CA1002" Action="None" />
|
||||||
|
<!-- disable warning CA2227: Collection properties should be read only (needed for deserialization) -->
|
||||||
|
<Rule Id="CA2227" Action="None" />
|
||||||
|
<!-- disable warning CA1819: Properties should not return arrays (needed for JSON-RPC params) -->
|
||||||
|
<Rule Id="CA1819" Action="None" />
|
||||||
|
<!-- disable warning CA1836: Prefer IsEmpty over Count (ConcurrentDictionary doesn't have IsEmpty) -->
|
||||||
|
<Rule Id="CA1836" Action="None" />
|
||||||
|
</Rules>
|
||||||
|
|
||||||
|
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
|
||||||
|
<!-- disable warning SA1402: File may only contain a single type (needed for DTO grouping) -->
|
||||||
|
<Rule Id="SA1402" Action="None" />
|
||||||
|
<!-- disable warning SA1214: Readonly fields should appear before non-readonly fields -->
|
||||||
|
<Rule Id="SA1214" Action="None" />
|
||||||
|
<!-- disable warning SA1649: File name should match first type name (DTOs grouped in single file) -->
|
||||||
|
<Rule Id="SA1649" Action="None" />
|
||||||
|
<!-- disable warning SA1623: Property documentation prefix (too strict for simple properties) -->
|
||||||
|
<Rule Id="SA1623" Action="None" />
|
||||||
</Rules>
|
</Rules>
|
||||||
</RuleSet>
|
</RuleSet>
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"guid": "a5b8c9d0-1e2f-3a4b-5c6d-7e8f9a0b1c2d",
|
||||||
|
"name": "JellyLMS",
|
||||||
|
"description": "Stream Jellyfin audio to Logitech Media Server (LMS) for multi-room playback",
|
||||||
|
"overview": "Bridges Jellyfin audio playback to LMS for synchronized multi-room playback across Squeezebox players",
|
||||||
|
"owner": "dtourolle",
|
||||||
|
"category": "Music",
|
||||||
|
"versions": []
|
||||||
|
}
|
||||||
|
]
|
||||||
Reference in New Issue
Block a user