Skip to content

Commit

Permalink
tmdb: search on showtitle if showid is -1
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroquinc committed Sep 29, 2024
1 parent 94da3d7 commit f0f129b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ def update_rpc(info, start_time, end_time, image_url, imdb_url, tmdb_url, trakt_
"state": str(info['title']) if (media_type == 'channel' and info['title']) else ("Playing" if is_playing else "Paused"),
"large_image": image_url,
"large_text": large_text_map.get(media_type.lower(), "Default Large Text"),
"small_image": 'play' if is_playing else 'pause',
"small_text": 'Playing' if is_playing else 'Paused'
#"small_image": 'play' if is_playing else 'pause',
#"small_text": 'Playing' if is_playing else 'Paused'
}

if buttons:
Expand Down
26 changes: 25 additions & 1 deletion src/tmdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,37 @@ def get_tmdb_id_tmdb(info, media_type):

def get_tmdb_id_for_tv_show(info):
tv_show_id = info.get('tvshowid', -1)
return get_tmdb_id_from_tv_show_details(tv_show_id) if tv_show_id != -1 else None
show_title = info.get('showtitle') # Get show title from info

# If tv_show_id is -1, search for the TMDb ID using show_title
if tv_show_id == -1 and show_title:
return search_tmdb_by_title(show_title)

# If tv_show_id is valid, get TMDb ID from the details
return get_tmdb_id_from_tv_show_details(tv_show_id)

def make_api_request(url):
response = requests.get(url).json()
logger.debug(f"API Response: {response}")
return response

def search_tmdb_by_title(show_title):
search_url = f"https://api.themoviedb.org/3/search/tv?api_key={TMDB_API_KEY}&query={show_title}"
response = make_api_request(search_url)

# Log the search response
logger.debug(f"Search Response for title '{show_title}': {response}")

if response.get('results'):
# Assuming you want the first result
show_info = response['results'][0]
tmdb_id = show_info.get('id')
logger.debug(f"Found TMDb ID for title '{show_title}': {tmdb_id}")
return tmdb_id

logger.debug(f"No results found for title '{show_title}'")
return None

def get_tmdb_id_from_tv_show_details(tv_show_id):
tv_show_url = f"http://localhost:{port}/jsonrpc?request={{%22jsonrpc%22:%222.0%22,%22method%22:%22VideoLibrary.GetTVShowDetails%22,%22params%22:{{%22tvshowid%22:{tv_show_id},%22properties%22:[%22uniqueid%22]}},%22id%22:%22libTvShow%22}}"
response = make_api_request(tv_show_url)
Expand Down

0 comments on commit f0f129b

Please sign in to comment.