feat(emby): add Emby as a MediaBrowser backend alongside Jellyfin

Emby is Jellyfin's upstream ancestor and speaks a near-identical MediaBrowser
API, so the existing Jellyfin stack is parameterised by a `MediaBrowserDialect`
rather than forked. `JellyfinClient`, its auth service, endpoint discovery, LAN
discovery, and the add/edit connection screens all take the dialect and keep one
implementation; `MediaBackend.emby` and `ConnectionKind.emby` carry it through
the neutral models, the Drift `kind` discriminator, downloads, and caches.

Every divergence below was measured against a live Emby 4.9.5 server, not
inferred from documentation, and each is documented at its capability getter.
Jellyfin's request strings stay byte-identical so nothing about its behaviour
changes.

Routes and auth
- Emby only accepts the pre-10.9 user-scoped item routes (`/Users/{id}/Items/…`,
  `/Users/{id}/PlayedItems/…`, `/Users/{id}/FavoriteItems/…`); the unprefixed
  forms Jellyfin 10.11 added return 404.
- The API is also served under a legacy `/emby` prefix, and both dialects accept
  the token as `X-Emby-Token` or `api_key=`.
- Emby answers only its own LAN discovery datagram ("who is EmbyServer?") and
  ignores Jellyfin's; its default HTTPS port is 8920.
- No `/QuickConnect` route exists, so Quick Connect stays Jellyfin-only.

Row fields Emby withholds
- `ProductionYear`, `OfficialRating`, `PremiereDate` and `DateCreated` are absent
  from list rows unless named in `Fields`, which would otherwise strip the year
  and age-rating badge from every card in the app.
- `UserData.LastPlayedDate` never appears on a list row under `Fields=UserData`,
  `EnableUserData=true` or the user-scoped `Ids=` form — only on the single-item
  detail route, or when the Emby-specific `UserDataLastPlayedDate` token is
  requested. Without it every recency-ordered surface silently degrades to
  library-add time, and `JellyfinApiCache.applyWatchState` stamps
  `DateTime.now()` on watched rows, so an offline watch-state pull would rewrite
  the cached play time of everything it walked.

Continue Watching and Next Up
- Emby computes Next Up per series only: the library-wide `/Shows/NextUp` query
  returns nothing under every parameter combination tried. The shelf is
  therefore reconstructed from a played-episode recency scan plus one
  `/Shows/NextUp?SeriesId=` per distinct series, bounded by a shared wall clock
  that covers the scan as well — per-request timeouts cannot bound the pass
  because `MediaServerHttpClient` times the connect and receive phases
  independently. Rows are stamped with their series' newest play from the same
  response that ordered them, so no per-series enrichment request is needed.
- `/Shows/NextUp` ignores `NextUpDateCutoff`, and no server-side played-date
  filter exists to delegate to (`MinDatePlayed` and `MinDateLastPlayed` are
  ignored; `MinDateLastSaved`, `MinDateCreated` and `MinPremiereDate` filter
  unrelated dates), so the 365-day window is applied to the scanned dates.
- The resume route returns items with no saved position, including plain next
  episodes, so the Emby resume leg reads from `/Items?Filters=IsResumable`.
- Emby is ahead of Jellyfin in one place: `/Users/{id}/Items/{id}/HideFromResume`
  makes Continue Watching removal a real capability.

Everything else
- `/Sessions/Playing` and `/Sessions/Playing/Progress` reject a body with no
  `PlaySessionId` (HTTP 400), so playback reporting always sends one.
- Passing any `MediaTypes` value to the playlist query returns an empty list.
- There is no aggregate `/Items/Filters` route; the four filter facets are
  reassembled from `/Genres`, `/OfficialRatings`, `/Studios` and `/Tags`.
- Metadata writes take name-pair lists (`Genres: [{'Name': 'Action'}]`); the
  plain string array is accepted and then silently discarded.
- Custom artwork uploads must be base64 text, not raw bytes — which was broken
  for Jellyfin too and is fixed for both.
- Trickplay, media segments and lyrics 404 on Emby, so scrub previews are absent
  and intro/credit markers fall back to chapter names.

Verified against a local Emby 4.9.5 and a Jellyfin 10.11.11 control server:
onboarding, browse, detail, playable stream URLs serving real bytes, subtitle
sidecars, watch-state write and restore, hubs, cross-server aggregation and
search across both backends simultaneously.
This commit is contained in:
edde746
2026-08-05 06:09:26 +02:00
parent f36e20bcad
commit 05fd622968
128 changed files with 4917 additions and 1429 deletions
+40 -40
View File
@@ -136,8 +136,8 @@ class Translations$auth$en {
/// en: 'or'
String get or => 'or';
/// en: 'Connect to Jellyfin'
String get connectToJellyfin => 'Connect to Jellyfin';
/// en: 'Connect to ${product}'
String connectToMediaBrowser({required Object product}) => 'Connect to ${product}';
/// en: 'Use Quick Connect'
String get useQuickConnect => 'Use Quick Connect';
@@ -2413,8 +2413,8 @@ class Translations$profiles$en {
/// en: 'Nothing to borrow yet.'
String get borrowEmpty => 'Nothing to borrow yet.';
/// en: 'Connect Plex or Jellyfin to another profile first.'
String get borrowEmptySubtitle => 'Connect Plex or Jellyfin to another profile first.';
/// en: 'Connect Plex, Jellyfin, or Emby to another profile first.'
String get borrowEmptySubtitle => 'Connect Plex, Jellyfin, or Emby to another profile first.';
/// en: 'Available connections could not be loaded. Try again.'
String get borrowLoadFailed => 'Available connections could not be loaded. Try again.';
@@ -2476,11 +2476,11 @@ class Translations$connections$en {
/// en: 'Add connection'
String get addConnection => 'Add connection';
/// en: 'Sign in with Plex or connect a Jellyfin server'
String get addConnectionSubtitleNoProfile => 'Sign in with Plex or connect a Jellyfin server';
/// en: 'Sign in with Plex or connect a Jellyfin or Emby server'
String get addConnectionSubtitleNoProfile => 'Sign in with Plex or connect a Jellyfin or Emby server';
/// en: 'Add to ${displayName}: Plex, Jellyfin, or another profile connection'
String addConnectionSubtitleScoped({required Object displayName}) => 'Add to ${displayName}: Plex, Jellyfin, or another profile connection';
/// en: 'Add to ${displayName}: Plex, Jellyfin, Emby, or another profile connection'
String addConnectionSubtitleScoped({required Object displayName}) => 'Add to ${displayName}: Plex, Jellyfin, Emby, or another profile connection';
/// en: 'Session expired for ${name}'
String sessionExpiredOne({required Object name}) => 'Session expired for ${name}';
@@ -2491,11 +2491,11 @@ class Translations$connections$en {
/// en: 'Sign in again'
String get signInAgain => 'Sign in again';
/// en: 'Edit Jellyfin connection'
String get editJellyfinTitle => 'Edit Jellyfin connection';
/// en: 'Edit ${product} connection'
String editMediaBrowserTitle({required Object product}) => 'Edit ${product} connection';
/// en: 'Add or remove URLs for ${serverName}. Plezy will use the reachable URL with the lowest latency.'
String editJellyfinIntro({required Object serverName}) => 'Add or remove URLs for ${serverName}. Plezy will use the reachable URL with the lowest latency.';
String editMediaBrowserIntro({required Object serverName}) => 'Add or remove URLs for ${serverName}. Plezy will use the reachable URL with the lowest latency.';
}
// Path: discover
@@ -2778,8 +2778,8 @@ class Translations$about$en {
/// en: 'Version ${version}'
String versionLabel({required Object version}) => 'Version ${version}';
/// en: 'A beautiful Plex and Jellyfin client for Flutter'
String get appDescription => 'A beautiful Plex and Jellyfin client for Flutter';
/// en: 'A beautiful Plex, Jellyfin, and Emby client for Flutter'
String get appDescription => 'A beautiful Plex, Jellyfin, and Emby client for Flutter';
/// en: 'View licenses of third-party libraries'
String get viewLicensesDescription => 'View licenses of third-party libraries';
@@ -4747,8 +4747,8 @@ class Translations$addServer$en {
// Translations
/// en: 'Add Jellyfin server'
String get addJellyfinTitle => 'Add Jellyfin server';
/// en: 'Add ${product} server'
String addMediaBrowserTitle({required Object product}) => 'Add ${product} server';
/// en: 'Server URLs'
String get serverUrls => 'Server URLs';
@@ -4759,11 +4759,11 @@ class Translations$addServer$en {
/// en: 'Find server'
String get findServer => 'Find server';
/// en: 'Looking for local Jellyfin servers...'
String get searchingLocalServers => 'Looking for local Jellyfin servers...';
/// en: 'Looking for local ${product} servers...'
String searchingLocalMediaBrowserServers({required Object product}) => 'Looking for local ${product} servers...';
/// en: 'Local Jellyfin servers'
String get localServers => 'Local Jellyfin servers';
/// en: 'Local ${product} servers'
String localMediaBrowserServers({required Object product}) => 'Local ${product} servers';
/// en: 'Username'
String get username => 'Username';
@@ -4798,8 +4798,8 @@ class Translations$addServer$en {
/// en: 'Failed to register account: ${error}'
String failedToRegisterAccount({required Object error}) => 'Failed to register account: ${error}';
/// en: 'Enter your Jellyfin server URL'
String get enterJellyfinUrlError => 'Enter your Jellyfin server URL';
/// en: 'Enter your ${product} server URL'
String enterMediaBrowserUrlError({required Object product}) => 'Enter your ${product} server URL';
/// en: 'Add connection'
String get addConnectionTitle => 'Add connection';
@@ -4816,14 +4816,14 @@ class Translations$addServer$en {
/// en: 'Authorize a Plex account. Home users become profiles.'
String get signInWithPlexCardSubtitleScoped => 'Authorize a Plex account. Home users become profiles.';
/// en: 'Connect to Jellyfin'
String get connectToJellyfinCard => 'Connect to Jellyfin';
/// en: 'Connect to ${product}'
String connectToMediaBrowserCard({required Object product}) => 'Connect to ${product}';
/// en: 'Enter your server URL, username, and password.'
String get connectToJellyfinCardSubtitle => 'Enter your server URL, username, and password.';
String get connectToMediaBrowserCardSubtitle => 'Enter your server URL, username, and password.';
/// en: 'Sign in to a Jellyfin server. Binds to ${name}.'
String connectToJellyfinCardSubtitleScoped({required Object name}) => 'Sign in to a Jellyfin server. Binds to ${name}.';
/// en: 'Sign in to your ${product} server. Binds to ${name}.'
String connectToMediaBrowserCardSubtitleScoped({required Object product, required Object name}) => 'Sign in to your ${product} server. Binds to ${name}.';
/// en: 'Borrow from another profile'
String get borrowFromAnotherProfile => 'Borrow from another profile';
@@ -6043,7 +6043,7 @@ extension on Translations {
'auth.waitingForAuth' => 'Waiting for authentication...\nSign in from your browser.',
'auth.useBrowser' => 'Use browser',
'auth.or' => 'or',
'auth.connectToJellyfin' => 'Connect to Jellyfin',
'auth.connectToMediaBrowser' => ({required Object product}) => 'Connect to ${product}',
'auth.useQuickConnect' => 'Use Quick Connect',
'auth.quickConnectInstructions' => 'Open Quick Connect in Jellyfin and enter this code.',
'auth.quickConnectWaiting' => 'Waiting for approval…',
@@ -6790,7 +6790,7 @@ extension on Translations {
'profiles.borrowAddTo' => ({required Object displayName}) => 'Add to ${displayName}',
'profiles.borrowExplain' => 'Borrow another profile\'s connection. PIN-protected profiles require a PIN.',
'profiles.borrowEmpty' => 'Nothing to borrow yet.',
'profiles.borrowEmptySubtitle' => 'Connect Plex or Jellyfin to another profile first.',
'profiles.borrowEmptySubtitle' => 'Connect Plex, Jellyfin, or Emby to another profile first.',
'profiles.borrowLoadFailed' => 'Available connections could not be loaded. Try again.',
'profiles.borrowFromProfile' => ({required Object displayName}) => 'From ${displayName}',
'profiles.borrowConnectionBorrowed' => 'Connection borrowed.',
@@ -6808,13 +6808,13 @@ extension on Translations {
'profiles.pinsDontMatch' => 'PINs don\'t match',
'connections.sectionTitle' => 'Connections',
'connections.addConnection' => 'Add connection',
'connections.addConnectionSubtitleNoProfile' => 'Sign in with Plex or connect a Jellyfin server',
'connections.addConnectionSubtitleScoped' => ({required Object displayName}) => 'Add to ${displayName}: Plex, Jellyfin, or another profile connection',
'connections.addConnectionSubtitleNoProfile' => 'Sign in with Plex or connect a Jellyfin or Emby server',
'connections.addConnectionSubtitleScoped' => ({required Object displayName}) => 'Add to ${displayName}: Plex, Jellyfin, Emby, or another profile connection',
'connections.sessionExpiredOne' => ({required Object name}) => 'Session expired for ${name}',
'connections.sessionExpiredMany' => ({required Object count}) => 'Session expired for ${count} servers',
'connections.signInAgain' => 'Sign in again',
'connections.editJellyfinTitle' => 'Edit Jellyfin connection',
'connections.editJellyfinIntro' => ({required Object serverName}) => 'Add or remove URLs for ${serverName}. Plezy will use the reachable URL with the lowest latency.',
'connections.editMediaBrowserTitle' => ({required Object product}) => 'Edit ${product} connection',
'connections.editMediaBrowserIntro' => ({required Object serverName}) => 'Add or remove URLs for ${serverName}. Plezy will use the reachable URL with the lowest latency.',
'discover.title' => 'Discover',
'discover.noContentAvailable' => 'No content available',
'discover.addMediaToLibraries' => 'Add some media to your libraries',
@@ -6936,7 +6936,7 @@ extension on Translations {
'about.title' => 'About',
'about.openSourceLicenses' => 'Open Source Licenses',
'about.versionLabel' => ({required Object version}) => 'Version ${version}',
'about.appDescription' => 'A beautiful Plex and Jellyfin client for Flutter',
'about.appDescription' => 'A beautiful Plex, Jellyfin, and Emby client for Flutter',
'about.viewLicensesDescription' => 'View licenses of third-party libraries',
'serverSelection.noServersFoundForAccount' => ({required Object username, required Object email}) => 'No servers found for ${username} (${email})',
'serverSelection.failedToLoadServers' => ({required Object error}) => 'Failed to load servers: ${error}',
@@ -7744,12 +7744,12 @@ extension on Translations {
'services.libraryFilter.modeHintWhitelist' => 'Sync only the libraries checked below.',
'services.libraryFilter.libraries' => 'Libraries',
'services.libraryFilter.noLibraries' => 'No libraries available',
'addServer.addJellyfinTitle' => 'Add Jellyfin server',
'addServer.addMediaBrowserTitle' => ({required Object product}) => 'Add ${product} server',
'addServer.serverUrls' => 'Server URLs',
'addServer.serverUrlsHelper' => 'Multiple URLs allowed, separated by commas.',
'addServer.findServer' => 'Find server',
'addServer.searchingLocalServers' => 'Looking for local Jellyfin servers...',
'addServer.localServers' => 'Local Jellyfin servers',
'addServer.searchingLocalMediaBrowserServers' => ({required Object product}) => 'Looking for local ${product} servers...',
'addServer.localMediaBrowserServers' => ({required Object product}) => 'Local ${product} servers',
'addServer.username' => 'Username',
'addServer.password' => 'Password',
'addServer.signIn' => 'Sign in',
@@ -7761,15 +7761,15 @@ extension on Translations {
'addServer.addPlexTitle' => 'Sign in with Plex',
'addServer.pinExpired' => 'PIN expired before sign-in. Please try again.',
'addServer.failedToRegisterAccount' => ({required Object error}) => 'Failed to register account: ${error}',
'addServer.enterJellyfinUrlError' => 'Enter your Jellyfin server URL',
'addServer.enterMediaBrowserUrlError' => ({required Object product}) => 'Enter your ${product} server URL',
'addServer.addConnectionTitle' => 'Add connection',
'addServer.addConnectionTitleScoped' => ({required Object name}) => 'Add to ${name}',
'addServer.signInWithPlexCard' => 'Sign in with Plex',
'addServer.signInWithPlexCardSubtitle' => 'Authorize this device. Shared servers are added.',
'addServer.signInWithPlexCardSubtitleScoped' => 'Authorize a Plex account. Home users become profiles.',
'addServer.connectToJellyfinCard' => 'Connect to Jellyfin',
'addServer.connectToJellyfinCardSubtitle' => 'Enter your server URL, username, and password.',
'addServer.connectToJellyfinCardSubtitleScoped' => ({required Object name}) => 'Sign in to a Jellyfin server. Binds to ${name}.',
'addServer.connectToMediaBrowserCard' => ({required Object product}) => 'Connect to ${product}',
'addServer.connectToMediaBrowserCardSubtitle' => 'Enter your server URL, username, and password.',
'addServer.connectToMediaBrowserCardSubtitleScoped' => ({required Object product, required Object name}) => 'Sign in to your ${product} server. Binds to ${name}.',
'addServer.borrowFromAnotherProfile' => 'Borrow from another profile',
'addServer.borrowFromAnotherProfileSubtitle' => 'Reuse another profile\'s connection. PIN-protected profiles require a PIN.',
_ => null,