Skip to content

Commit

Permalink
add sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
vanchaxy committed Dec 4, 2024
1 parent 52c210a commit e91903d
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 14 deletions.
2 changes: 1 addition & 1 deletion fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ app = 'plexio'
primary_region = 'iad'

[build]
image = 'ghcr.io/vanchaxy/plexio:0.1.6'
image = 'ghcr.io/vanchaxy/plexio:0.1.7'

[env]
CACHE_TYPE = 'redis'
Expand Down
4 changes: 2 additions & 2 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "frontend",
"private": true,
"version": "0.1.6",
"version": "0.1.7",
"type": "module",
"scripts": {
"dev": "vite --host",
Expand Down
2 changes: 1 addition & 1 deletion plexio/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1.6'
__version__ = '0.1.7'
35 changes: 35 additions & 0 deletions plexio/plex/media_server_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,38 @@
from plexio.plex.utils import get_json
from plexio.settings import settings

SORT_OPTIONS = {
'Title': 'title',
'Title (desc)': 'title:desc',
'Year': 'year',
'Year (desc)': 'year:desc',
'Release Date': 'originallyAvailableAt',
'Release Date (desc)': 'originallyAvailableAt:desc',
'Critic Rating': 'rating',
'Critic Rating (desc)': 'rating:desc',
'Audience Rating': 'audienceRating',
'Audience Rating (desc)': 'audienceRating:desc',
'Rating': 'userRating',
'Rating (desc)': 'userRating:desc',
'Content Rating': 'contentRating',
'Content Rating (desc)': 'contentRating:desc',
'Duration': 'duration',
'Duration (desc)': 'duration:desc',
'Progress': 'viewOffset',
'Progress (desc)': 'viewOffset:desc',
'Plays': 'viewCount',
'Plays (desc)': 'viewCount:desc',
'Date Added': 'addedAt',
'Date Added (desc)': 'addedAt:desc',
'Date Viewed': 'lastViewedAt',
'Date Viewed (desc)': 'lastViewedAt:desc',
'ResolutionSelected': 'mediaHeight',
'ResolutionSelected (desc)': 'mediaHeight:desc',
'Bitrate': 'mediaBitrate',
'Bitrate (desc)': 'mediaBitrate:desc',
'Randomly': 'random',
}


async def check_server_connection(
*,
Expand Down Expand Up @@ -41,6 +73,7 @@ async def get_section_media(
section_id: str,
skip: int,
search: str,
sort: str,
) -> list[PlexMediaMeta]:
params = {
'includeGuids': 1,
Expand All @@ -50,6 +83,8 @@ async def get_section_media(
}
if search:
params['title'] = search
if sort:
params['sort'] = SORT_OPTIONS[sort]
json = await get_json(
client=client,
url=url / 'library/sections' / section_id / 'all',
Expand Down
17 changes: 8 additions & 9 deletions plexio/routers/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
)
from plexio.models.utils import plexio_id_to_guid
from plexio.plex.media_server_api import (
SORT_OPTIONS,
get_all_episodes,
get_media,
get_section_media,
Expand Down Expand Up @@ -59,6 +60,7 @@ async def get_manifest(
extra=[
{'name': 'skip', 'isRequired': False},
{'name': 'search', 'isRequired': False},
{'name': 'sort', 'options': list(SORT_OPTIONS.keys())},
],
),
)
Expand Down Expand Up @@ -96,28 +98,25 @@ async def get_manifest(
response_model_exclude_none=True,
)
@router.get(
'/{installation_id}/{base64_cfg}/catalog/{stremio_type}/{catalog_id}/skip={skip}.json',
response_model_exclude_none=True,
)
@router.get(
'/{installation_id}/{base64_cfg}/catalog/{stremio_type}/{catalog_id}/search={search}.json',
'/{installation_id}/{base64_cfg}/catalog/{stremio_type}/{catalog_id}/{extra}.json',
response_model_exclude_none=True,
)
async def get_catalog(
http: Annotated[ClientSession, Depends(get_http_client)],
configuration: Annotated[AddonConfiguration, Depends(get_addon_configuration)],
stremio_type: StremioMediaType,
catalog_id: str,
skip: int = 0,
search: str = '',
extra: str = '',
) -> StremioCatalog:
extras = dict(e.split('=') for e in extra.split('&') if e)
media = await get_section_media(
client=http,
url=configuration.discovery_url,
token=configuration.access_token,
section_id=catalog_id,
search=search,
skip=skip,
search=extras.get('search', ''),
skip=extras.get('skip', 0),
sort=extras.get('sort', 'Title'),
)
return StremioCatalog(
metas=[m.to_stremio_meta_review(configuration) for m in media],
Expand Down

0 comments on commit e91903d

Please sign in to comment.