From 5740d93a35f73461b2874b42a3f9816db86475eb Mon Sep 17 00:00:00 2001 From: edde746 <86283021+edde746@users.noreply.github.com> Date: Thu, 26 Feb 2026 03:41:27 +0100 Subject: [PATCH] fix: download from homepage failing --- lib/providers/download_provider.dart | 21 ++++++++++----------- lib/services/download_manager_service.dart | 12 ++++++++++-- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/lib/providers/download_provider.dart b/lib/providers/download_provider.dart index 577d0f23..dafe0c3a 100644 --- a/lib/providers/download_provider.dart +++ b/lib/providers/download_provider.dart @@ -656,19 +656,18 @@ class DownloadProvider extends ChangeNotifier { } } - // Fetch full metadata to get year, summary, clearLogo - // The metadata from getChildren() is summarized and missing these fields. - // If metadata already has summary, it's already full (e.g., from detail screen). + // Always fetch full metadata before downloading. + // Hub items may have summary but the cache at /library/metadata/$ratingKey + // won't have the full API response (with Media/Part data needed for video URL) + // unless getMetadataWithImages has been called. PlexMetadata metadataToStore = metadata; - if (metadata.summary == null) { - try { - final fullMetadata = await client.getMetadataWithImages(metadata.ratingKey); - if (fullMetadata != null) { - metadataToStore = fullMetadata.copyWith(serverId: metadata.serverId, serverName: metadata.serverName); - } - } catch (e) { - appLogger.w('Failed to fetch full metadata for ${metadata.ratingKey}, using partial', error: e); + try { + final fullMetadata = await client.getMetadataWithImages(metadata.ratingKey); + if (fullMetadata != null) { + metadataToStore = fullMetadata.copyWith(serverId: metadata.serverId, serverName: metadata.serverName); } + } catch (e) { + appLogger.w('Failed to fetch full metadata for ${metadata.ratingKey}, using partial', error: e); } // For episodes, also fetch and store show and season metadata for offline display diff --git a/lib/services/download_manager_service.dart b/lib/services/download_manager_service.dart index d4779c15..e0119170 100644 --- a/lib/services/download_manager_service.dart +++ b/lib/services/download_manager_service.dart @@ -522,8 +522,16 @@ class DownloadManagerService { } } - final playbackData = await client.getVideoPlaybackData(metadata.ratingKey); - if (playbackData.videoUrl == null) throw Exception('Could not get video URL'); + var playbackData = await client.getVideoPlaybackData(metadata.ratingKey); + if (playbackData.videoUrl == null) { + // Cache may contain a synthetic entry (from _cacheMetadataForOffline) without + // Media/Part data. Force a fresh network fetch to populate the cache properly. + appLogger.w('No video URL from cache for $globalKey, retrying via network'); + final fetched = await client.getMetadataWithImages(ratingKey); + if (fetched != null) metadata = fetched.copyWith(serverId: serverId); + playbackData = await client.getVideoPlaybackData(metadata.ratingKey); + if (playbackData.videoUrl == null) throw Exception('Could not get video URL for $globalKey'); + } final ext = _getExtensionFromUrl(playbackData.videoUrl!) ?? 'mp4';