Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API methods + Small Fixes #49

Merged
merged 6 commits into from
Sep 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 86 additions & 2 deletions jellyfin_apiclient_python/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,31 @@ def refresh_library(self):
"""
return self._post("Library/Refresh")

def add_media_library(self, name, collectionType, paths, refreshLibrary=True):
"""
Create a new media library.

Args:
name (str): name of the new library

collectionType (str): one of "movies" "tvshows" "music" "musicvideos"
"homevideos" "boxsets" "books" "mixed"

paths (List[str]):
paths on the server to use in the media library

References:
.. [AddVirtualFolder] https://api.jellyfin.org/#tag/LibraryStructure/operation/AddVirtualFolder
"""
params = {
'name': name,
'collectionType': collectionType,
'paths': paths,
'refreshLibrary': refreshLibrary,

}
return self.virtual_folders('POST', params=params)

def items(self, handler="", action="GET", params=None, json=None):
if action == "POST":
return self._post("Items%s" % handler, json, params)
Expand Down Expand Up @@ -547,6 +572,34 @@ def favorite(self, item_id, option=True):
def get_system_info(self):
return self._get("System/Configuration")

def get_server_logs(self):
"""
Returns:
List[Dict] - list of information about available log files

References:
.. [GetServerLogs] https://api.jellyfin.org/#tag/System/operation/GetServerLogs
"""
return self._get("System/Logs")

def get_log_entries(self, startIndex=None, limit=None, minDate=None, hasUserId=None):
"""
Returns a list of recent log entries

Returns:
Dict: with main key "Items"
"""
params = {}
if limit is not None:
params['limit'] = limit
if startIndex is not None:
params['startIndex'] = startIndex
if minDate is not None:
params['minDate'] = minDate
if hasUserId is not None:
params['hasUserId'] = hasUserId
return self._get("System/ActivityLog/Entries", params=params)

def post_capabilities(self, data):
return self.sessions("/Capabilities/Full", "POST", json=data)

Expand Down Expand Up @@ -634,19 +687,24 @@ def get_sync_queue(self, date, filters=None):
def get_server_time(self):
return self._get("Jellyfin.Plugin.KodiSyncQueue/GetServerDateTime")

def get_play_info(self, item_id, profile, aid=None, sid=None, start_time_ticks=None, is_playback=True):
def get_play_info(self, item_id, profile=None, aid=None, sid=None, start_time_ticks=None, is_playback=True):
args = {
'UserId': "{UserId}",
'DeviceProfile': profile,
'AutoOpenLiveStream': is_playback,
'IsPlayback': is_playback
}
if profile is None:
args['DeviceProfile'] = profile
if sid:
args['SubtitleStreamIndex'] = sid
if aid:
args['AudioStreamIndex'] = aid
if start_time_ticks:
args['StartTimeTicks'] = start_time_ticks
# TODO:
# Should this be a get?
# https://api.jellyfin.org/#tag/MediaInfo
# https://api.jellyfin.org/#tag/MediaInfo/operation/GetPostedPlaybackInfo
return self.items("/%s/PlaybackInfo" % item_id, "POST", json=args)

def get_live_stream(self, item_id, play_id, token, profile):
Expand Down Expand Up @@ -899,6 +957,32 @@ def identify(client, item_id, provider_ids):
body = {'ProviderIds': provider_ids}
return client.jellyfin.items('/RemoteSearch/Apply/' + item_id, action='POST', params=None, json=body)

def get_now_playing(self, session_id):
"""
Simplified API to get now playing information for a session including the
play state.

References:
https://github.com/jellyfin/jellyfin/issues/9665
"""
resp = self.sessions(params={
'Id': session_id,
'fields': ['PlayState']
})
found = None
for item in resp:
if item['Id'] == session_id:
found = item
if not found:
raise KeyError(f'No session_id={session_id}')
play_state = found['PlayState']
now_playing = found.get('NowPlayingItem', None)
if now_playing is None:
# handle case if nothing is playing
now_playing = {'Name': None}
now_playing['PlayState'] = play_state
return now_playing


class CollectionAPIMixin:
"""
Expand Down
Loading