added get_item to jellyfin-client

This commit is contained in:
Kamil
2024-12-03 12:45:13 +00:00
parent 2b3c400c10
commit 883294d74e

View File

@@ -315,6 +315,18 @@ class JellyfinClient:
return {"status": "success", "message": "Playlist removed successfully"} return {"status": "success", "message": "Playlist removed successfully"}
else: else:
raise Exception(f"Failed to remove playlist: {response.content}") raise Exception(f"Failed to remove playlist: {response.content}")
def get_item(self, session_token: str, item_id: str):
url = f'{self.base_url}/Items/{item_id}'
self.logger.debug(f"Url={url}")
response = requests.get(url, headers=self._get_headers(session_token=session_token), timeout = self.timeout)
self.logger.debug(f"Response = {response.status_code}")
if response.status_code == 200:
return response.json()
else:
raise Exception(f"Failed to get item: {response.content}")
def remove_user_from_playlist(self, session_token: str, playlist_id: str, user_id: str): def remove_user_from_playlist(self, session_token: str, playlist_id: str, user_id: str):
""" """
@@ -341,7 +353,7 @@ class JellyfinClient:
raise Exception(f"Failed to remove user from playlist: {response.content}") raise Exception(f"Failed to remove user from playlist: {response.content}")
def set_playlist_cover_image(self, session_token: str, playlist_id: str, spotify_image_url: str): def set_playlist_cover_image(self, session_token: str, playlist_id: str, provider_image_url: str):
""" """
Set the cover image of a playlist in Jellyfin using an image URL from Spotify. Set the cover image of a playlist in Jellyfin using an image URL from Spotify.
@@ -351,7 +363,7 @@ class JellyfinClient:
:return: Success message or raises an exception on failure. :return: Success message or raises an exception on failure.
""" """
# Step 1: Download the image from the Spotify URL # Step 1: Download the image from the Spotify URL
response = requests.get(spotify_image_url, timeout = self.timeout) response = requests.get(provider_image_url, timeout = self.timeout)
if response.status_code != 200: if response.status_code != 200:
raise Exception(f"Failed to download image from Spotify: {response.content}") raise Exception(f"Failed to download image from Spotify: {response.content}")
@@ -444,7 +456,6 @@ class JellyfinClient:
return response.json() return response.json()
def search_track_in_jellyfin(self, session_token: str, preview_url: str, song_name: str, artist_names: list): def search_track_in_jellyfin(self, session_token: str, preview_url: str, song_name: str, artist_names: list):
""" """
Search for a track in Jellyfin by comparing the preview audio to tracks in the library. Search for a track in Jellyfin by comparing the preview audio to tracks in the library.
@@ -546,8 +557,6 @@ class JellyfinClient:
print(f"Error in search_track_in_jellyfin: {str(e)}") print(f"Error in search_track_in_jellyfin: {str(e)}")
return False, None return False, None
# Helper methods used in search_track_in_jellyfin # Helper methods used in search_track_in_jellyfin
def download_preview_to_tempfile(self, preview_url): def download_preview_to_tempfile(self, preview_url):
try: try: