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

Collection api #41

Merged
merged 1 commit 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
83 changes: 82 additions & 1 deletion jellyfin_apiclient_python/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,8 +854,89 @@ def identify(client, item_id, provider_ids):
return client.jellyfin.items('/RemoteSearch/Apply/' + item_id, action='POST', params=None, json=body)


class CollectionAPIMixin:
"""
Methods for creating and modifying collections.

Note: there does not seem to be an API endpoint for removing a collection.
"""

def new_collection(self, name, item_ids=None, parent_id=None, is_locked=False):
"""
Create a new collection, or search for a collection with a given name.

Args:
name (str):
Name of the collection to create or lookup

item_ids (List[str] | None):
List of item ids to initialize the collection with.

parent_id (str | None):
Create the collection within a specific folder.

is_locked (str | None):
Whether or not to lock the new collection.

Returns:
Dict:
with one entry: "Id", which contains the id of the new or found
collection.

References:
.. [CreateCollection] https://api.jellyfin.org/#tag/Collection/operation/CreateCollection
"""
params = {}
params['name'] = name
params['isLocked'] = is_locked
json = {}
if parent_id is not None:
params['parentId'] = parent_id
if item_ids is not None:
params['ids'] = item_ids
return self._post("Collections", json, params)

def add_collection_items(self, collection_id, item_ids):
"""
Adds items to a collection.

Args:
collection_id (str):
Id of the collection to add items to.

item_ids (List[str]):
List of item ids to add to the collection.

References:
.. [AddToCollection] https://api.jellyfin.org/#tag/Collection/operation/AddToCollection
"""
params = {}
json = {}
params['ids'] = ','.join(item_ids)
return self._post(f"Collections/{collection_id}/Items", json, params)

def remove_collection_items(self, collection_id, item_ids=None):
"""
Removes items from a collection.

Args:
collection_id (str):
Id of the collection to remove items from.

item_ids (List[str]):
List of item ids to remove from the collection.

References:
.. [RemoveFromCollection] https://api.jellyfin.org/#tag/Collection/operation/RemoveFromCollection
"""
params = {}
json = {}
params['ids'] = ','.join(item_ids)
return self._delete(f"Collections/{collection_id}/Items", json, params)


class API(InternalAPIMixin, BiggerAPIMixin, GranularAPIMixin,
SyncPlayAPIMixin, ExperimentalAPIMixin):
SyncPlayAPIMixin, ExperimentalAPIMixin, CollectionAPIMixin):
"""
The Jellyfin Python API client containing all api calls to the server.

Expand Down