Merge pull request #222 from ulovecode/fix/include-spisodes
fix(tv): include episodes in video content filtering
This commit is contained in:
@@ -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? ?? '',
|
||||
|
||||
@@ -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;
|
||||
})
|
||||
.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');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user