Skip to content
This repository has been archived by the owner on Oct 13, 2024. It is now read-only.

Commit

Permalink
feat: add support for tv shows (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher authored Jan 13, 2024
1 parent b2487ce commit 4545942
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ LizardByte has the full documentation hosted on `Read the Docs <http://themerr-k

About
-----
Themerr-kodi is an add-on for Kodi. The add-on plays theme music while browsing movies in your library.
Themerr-kodi is an add-on for Kodi. The add-on plays theme music while browsing movies and tv shows in your library.

Integrations
------------
Expand Down
34 changes: 28 additions & 6 deletions src/themerr/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def __init__(self, player_instance=None):
self.current_selected_item_id = None
self.last_selected_item_id = None
self.uuid_mapping = {}
self.last_selected_show_id = None

self._kodi_db_map = {
'tmdb': 'themoviedb',
Expand All @@ -106,6 +107,7 @@ def __init__(self, player_instance=None):
'game_franchises': ['igdb'],
'movies': ['themoviedb', 'imdb'],
'movie_collections': ['themoviedb'],
'tv_shows': ['themoviedb'],
}
self._dbs = (
'tmdb',
Expand All @@ -129,19 +131,29 @@ def window_watcher(self):
sleep_time = 50 # 50ms

while not self.monitor.abortRequested():
# put timeout_factor within the loop so we can update it if the user changes the setting
# put timeout_factor within the loop, so we can update it if the user changes the setting
timeout_factor = settings.settings.theme_timeout()
timeout = timeout_factor * (1000 / sleep_time)

selected_title = xbmc.getInfoLabel("ListItem.Label") # this is only used for logging

kodi_id = None

for db in self._dbs:
db_id = xbmc.getInfoLabel(f'ListItem.UniqueID({db})')
if db_id:
kodi_id = f"{db}_{db_id}"
break # break on the first supported db
if self.is_seasons() or self.is_episodes():
kodi_id = self.last_selected_show_id

if not kodi_id:
for db in self._dbs:
db_id = xbmc.getInfoLabel(f'ListItem.UniqueID({db})')
if db_id:
kodi_id = f"{db}_{db_id}"

if self.is_tv_shows():
# TheMovieDB TV Shows addon does not set uniqueID properly for seasons and episodes.
# So we will use the last selected TV show ID instead.
# See: https://github.com/xbmc/metadata.tvshows.themoviedb.org.python/issues/119
self.last_selected_show_id = kodi_id
break # break on the first supported db

# prefetch the YouTube url (if not already cached or cache is greater than 1 hour)
if kodi_id and (kodi_id not in list(self.uuid_mapping.keys())
Expand Down Expand Up @@ -250,6 +262,12 @@ def process_kodi_id(self, kodi_id: str) -> Optional[str]:
database_type = 'movies'
elif self.is_movie_set():
database_type = 'movie_collections'
elif self.is_tv_shows():
database_type = 'tv_shows'
elif self.is_episodes():
database_type = 'tv_shows'
elif self.is_seasons():
database_type = 'tv_shows'

if database_type:
youtube_url = self.find_youtube_url(
Expand Down Expand Up @@ -284,6 +302,10 @@ def find_youtube_url(self, kodi_id: str, db_type: str) -> Optional[str]:
"""
split_id = kodi_id.split('_')
db = self._kodi_db_map[split_id[0]]

if db_type not in self._supported_dbs.keys() or db not in self._supported_dbs[db_type]:
return None

db_id = split_id[1]

self.log.debug(f"{db.upper()}_ID: {db_id}")
Expand Down
35 changes: 17 additions & 18 deletions tests/unit/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,18 @@
@pytest.fixture(
scope='function',
params=[
'tmdb_10378',
# (kodi_id, db_type, condition)
('tmdb_9761', 'movies', 'Container.Content(movies)'), # Elephants Dream
('tmdb_20529', 'movies', 'Container.Content(movies)'), # Sita Sings the Blues
('tmdb_10378', 'movies', 'Container.Content(movies)'), # Big Buck Bunny
('tmdb_45745', 'movies', 'Container.Content(movies)'), # Sintel
('tmdb_645', 'movie_collections', 'ListItem.IsCollection'), # James Bond Collection
('tmdb_1399', 'tv_shows', 'Container.Content(tvshows)'), # Game of Thrones
('tmdb_48866', 'tv_shows', 'Container.Content(tvshows)'), # The 100
('tmdb_1399', 'tv_shows', 'Container.Content(Seasons)'), # Game of Thrones
('tmdb_48866', 'tv_shows', 'Container.Content(Seasons)'), # The 100
('tmdb_1399', 'tv_shows', 'Container.Content(Episodes)'), # Game of Thrones
('tmdb_48866', 'tv_shows', 'Container.Content(Episodes)'), # The 100
],
)
def kodi_id(request):
Expand Down Expand Up @@ -77,33 +88,21 @@ def test_pre_checks_all_passing(window_obj):
assert window_obj.pre_checks() is True


def test_process_kodi_id_movies(kodi_id, mock_xbmc_get_cond_visibility, window_obj):
condition = 'Container.Content(movies)'
env_var = f'_KODI_GET_COND_VISIBILITY_{condition}'
os.environ[env_var] = '1'

youtube_url = window_obj.process_kodi_id(kodi_id=kodi_id)
assert youtube_url

del os.environ[env_var]


def test_process_kodi_id_movie_collection(mock_xbmc_get_cond_visibility, window_obj):
_kodi_id = 'tmdb_645'
condition = 'ListItem.IsCollection'
def test_process_kodi_id(kodi_id, mock_xbmc_get_cond_visibility, window_obj):
condition = kodi_id[2]
env_var = f'_KODI_GET_COND_VISIBILITY_{condition}'
os.environ[env_var] = '1'

youtube_url = window_obj.process_kodi_id(kodi_id=_kodi_id)
youtube_url = window_obj.process_kodi_id(kodi_id=kodi_id[0])
assert youtube_url

del os.environ[env_var]


def test_find_youtube_url(kodi_id, window_obj):
youtube_url = window_obj.find_youtube_url(
kodi_id=kodi_id,
db_type='movies',
kodi_id=kodi_id[0],
db_type=kodi_id[1],
)

assert youtube_url
Expand Down

0 comments on commit 4545942

Please sign in to comment.