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

Commit

Permalink
fix(collections): use library language in tmdb query (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher authored Mar 18, 2024
1 parent f1a3948 commit 19573c1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 7 additions & 1 deletion Contents/Code/plex_api_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,13 @@ def get_database_info(item):
else:
database = 'themoviedb'
database_type = 'movie_collections'
database_id = tmdb_helper.get_tmdb_id_from_collection(search_query=item.title)

# we need to get the library language for the library that this item belongs to
library_language = plex.library.sectionByID(item.librarySectionID).language

database_id = tmdb_helper.get_tmdb_id_from_collection(
search_query='{}&language={}'.format(item.title, library_language)
)

Log.Debug('Database info for item: {}, database_info: {}'.format(
item.title, (database_type, database, agent, database_id)))
Expand Down
7 changes: 4 additions & 3 deletions Contents/Code/tmdb_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ def get_tmdb_id_from_collection(search_query):
"""
# /search/collection?query=James%20Bond%20Collection&include_adult=false&language=en-US&page=1"
query_url = 'search/collection?query={}'
query_item = search_query.split('&', 1)[0]

# Plex returns 500 error if spaces are in collection query, same with `_`, `+`, and `%20`... so use `-`
url = '{}/{}'.format(tmdb_base_url, query_url.format(String.Quote(
s=search_query.replace(' ', '-'), usePlus=True)))
s=search_query.replace(' ', '-'), usePlus=False)))
try:
tmdb_data = JSON.ObjectFromURL(
url=url, sleep=2.0, headers=dict(Accept='application/json'), cacheTime=CACHE_1DAY, errors='strict')
Expand All @@ -119,8 +120,8 @@ def get_tmdb_id_from_collection(search_query):
end_string = 'Collection' # collection names on themoviedb end with 'Collection'
try:
for result in tmdb_data['results']:
if result['name'].lower() == search_query.lower() or \
'{} {}'.format(search_query.lower(), end_string).lower() == result['name'].lower():
if result['name'].lower() == query_item.lower() or \
'{} {}'.format(query_item.lower(), end_string).lower() == result['name'].lower():
collection_id = int(result['id'])
except (IndexError, KeyError, ValueError):
Log.Debug('Error searching for collection {}: {}'.format(search_query, tmdb_data))
Expand Down

0 comments on commit 19573c1

Please sign in to comment.