-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switched to using youtube video trailers instead of the native plex t…
…railers for consistency with other UMC-compatible integrations
- Loading branch information
Showing
3 changed files
with
49 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import aiohttp | ||
|
||
TMDB_API_KEY = '1f7708bb9a218ab891a5d438b1b63992' | ||
TMDB_SEARCH_URL = 'https://api.themoviedb.org/3/search/{media_type}?api_key={api_key}&query={query}' | ||
TMDB_DETAILS_URL = 'https://api.themoviedb.org/3/{media_type}/{tmdb_id}?api_key={api_key}&append_to_response=videos' | ||
|
||
async def get_tmdb_trailer_url(hass, title, media_type): | ||
if media_type == 'show': | ||
media_type = 'tv' | ||
elif media_type == 'movie': | ||
media_type = 'movie' | ||
else: | ||
return None | ||
|
||
async with aiohttp.ClientSession() as session: | ||
# Search for the movie or TV show | ||
search_url = TMDB_SEARCH_URL.format(media_type=media_type, api_key=TMDB_API_KEY, query=title) | ||
async with session.get(search_url) as response: | ||
search_data = await response.json() | ||
if not search_data.get('results'): | ||
return None | ||
|
||
tmdb_id = search_data['results'][0]['id'] | ||
|
||
# Get details including videos | ||
details_url = TMDB_DETAILS_URL.format(media_type=media_type, tmdb_id=tmdb_id, api_key=TMDB_API_KEY) | ||
async with session.get(details_url) as response: | ||
details_data = await response.json() | ||
|
||
videos = details_data.get('videos', {}).get('results', []) | ||
for video in videos: | ||
if video['type'] == 'Trailer' and video['site'] == 'YouTube': | ||
return f'https://www.youtube.com/watch?v={video["key"]}' | ||
|
||
return None |