feat(plex): improve video content filtering and directory parsing

This commit is contained in:
zhubowen
2026-01-07 19:59:57 +08:00
parent da1a4e7aa8
commit 570f1fdc58
2 changed files with 16 additions and 11 deletions
+10 -3
View File
@@ -30,11 +30,18 @@ class PlexHub {
final metadataList = <PlexMetadata>[];
// Helper function to parse entries from a JSON list
void parseEntries(List? entries) {
void parseEntries(List? entries, {bool isDirectory = false}) {
if (entries == null) return;
for (final item in entries) {
try {
metadataList.add(PlexMetadata.fromJson(item));
if (isDirectory && item is Map && !item.containsKey('type')) {
// Directory items often represent shows but might miss the type field
// Default to 'show' if it looks like a show (has leafCount or childCount)
// or 'folder' as a safe default
final String type = (item.containsKey('leafCount') || item.containsKey('childCount')) ? 'show' : 'folder';
item['type'] = type;
}
metadataList.add(PlexMetadata.fromJson(item as Map<String, dynamic>));
} catch (e) {
// Skip items that fail to parse
}
@@ -43,7 +50,7 @@ class PlexHub {
// Hubs can contain either Metadata or Directory entries
parseEntries(json['Metadata'] as List?);
parseEntries(json['Directory'] as List?);
parseEntries(json['Directory'] as List?, isDirectory: true);
return PlexHub(
hubKey: json['key'] as String? ?? '',
+6 -8
View File
@@ -1213,11 +1213,9 @@ class PlexClient {
final hub = PlexHub.fromJson(hubJson);
// Only include hubs that have items and are movie/show content
if (hub.items.isNotEmpty) {
// Filter out non-video content types and tag with server info
// Filter to only video content (movies, shows, seasons, episodes) and tag with server info
final videoItems = hub.items
.where((item) {
return item.isMovie || item.isShow || item.isEpisode;
})
.where((item) => item.isVideoContent)
.map((item) => item.copyWith(serverId: serverId, serverName: serverName))
.toList();
@@ -1267,9 +1265,9 @@ class PlexClient {
final hub = PlexHub.fromJson(hubJson);
if (hub.items.isEmpty) continue;
// Filter to only video content (movies, shows, episodes) and tag with server info
// Filter to only video content (movies, shows, seasons, episodes) and tag with server info
final videoItems = hub.items
.where((item) => item.isMovie || item.isShow || item.isEpisode)
.where((item) => item.isVideoContent)
.map((item) => item.copyWith(serverId: serverId, serverName: serverName))
.toList();
@@ -1305,9 +1303,9 @@ class PlexClient {
Future<List<PlexMetadata>> getHubContent(String hubKey) async {
return _wrapListApiCall<PlexMetadata>(() => _dio.get(hubKey), (response) {
final allItems = _extractMetadataList(response);
// Filter out non-video content types
// Filter to only video content (movies, shows, seasons, episodes)
return allItems.where((item) {
return item.isMovie || item.isShow;
return item.isVideoContent;
}).toList();
}, 'Failed to get hub content');
}