Skip to content

Commit ec6a95f

Browse files
committed
Extra check to filter out wrong results
1 parent 506136e commit ec6a95f

File tree

1 file changed

+28
-4
lines changed
  • StreamingCommunity/Api/Service/discoveryeu

1 file changed

+28
-4
lines changed

StreamingCommunity/Api/Service/discoveryeu/site.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,28 @@
2020
table_show_manager = TVShowManager()
2121

2222

23+
def determine_type(attributes: dict)-> str:
24+
"""
25+
Determines the item type
26+
27+
Parameters:
28+
attributes (dict): Dictionary with item info
29+
30+
Returns:
31+
str: Type of the item
32+
"""
33+
episode_count = attributes.get('episodeCount', 0)
34+
video_count = attributes.get('videoCount', 0)
35+
if episode_count == 0 and video_count > 1000:
36+
return 'channel'
37+
elif episode_count > 0:
38+
return 'show'
39+
elif video_count == 1 and episode_count == 0:
40+
return 'movie'
41+
else:
42+
return "unknown"
43+
44+
2345
def title_search(query: str) -> int:
2446
"""
2547
Search for titles on Discovery+
@@ -58,11 +80,13 @@ def title_search(query: str) -> int:
5880
data = response.json()
5981
for element in data.get('included', []):
6082
element_type = element.get('type')
61-
83+
attributes = element.get('attributes', {})
84+
type_element = determine_type(attributes)
85+
86+
if element_type != type_element:
87+
continue
6288
# Handle both shows and movies
6389
if element_type in ['show', 'movie']:
64-
attributes = element.get('attributes', {})
65-
6690
if 'name' in attributes:
6791
if element_type == 'show':
6892
date = attributes.get('newestEpisodeDate', '').split("T")[0]
@@ -77,5 +101,5 @@ def title_search(query: str) -> int:
77101
'image': None,
78102
'date': date
79103
})
80-
104+
81105
return media_search_manager.get_length()

0 commit comments

Comments
 (0)