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 get/update item metadata methods #42

Merged
merged 3 commits into from
Feb 15, 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
45 changes: 44 additions & 1 deletion jellyfin_apiclient_python/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,57 @@ def get_media_folders(self, fields=None):
return self.users("/Items", params=params)

def get_item(self, item_id):
return self.users("/Items/%s" % item_id)
"""
Lookup metadata for an item.

Args:
item_id (str): item uuid to lookup metadata for

Returns:
Dict[str, Any]: metadata keys and values for the queried item.
"""
return self.users("/Items/%s" % item_id, params={
'Fields': info()
})

def get_items(self, item_ids):
"""
Lookup metadata for multiple items.

Args:
item_ids (List[str]): item uuids to lookup metadata for

Returns:
Dict[str, Any]: A result dictionary where the info from each
item is stored in the "Items" list.
"""
return self.users("/Items", params={
'Ids': ','.join(str(x) for x in item_ids),
'Fields': info()
})

def update_item(self, item_id, data):
"""
Updates the metadata for an item.

Requires a user with elevated permissions [UpdateItem]_.

Args:
item_id (str): item uuid to update metadata for

data (Dict): the new information to add to this item.
Note: any specified items are completely overwritten.

References:
.. [UpdateItem] https://api.jellyfin.org/#tag/ItemUpdate/operation/UpdateItem
"""
# Force us to get the entire original item, we need to pass
# all information, otherwise all info is overwritten
body = self.get_item(item_id)
body.update(data)
assert body['Id'] == item_id
return self.items('/' + item_id, action='POST', params=None, json=body)

def get_sessions(self):
return self.sessions(params={'ControllableByUserId': "{UserId}"})

Expand Down