Skip to content

Commit

Permalink
- User feedback on tracking of anime through subtitle listings.
Browse files Browse the repository at this point in the history
When a show is wathed, the subtitle is named according to the update status (OK, NO_UPDATE, SKIPPED, INVALID_ID, NOT_LISTED, FAIL)
  • Loading branch information
SageTendo committed Dec 17, 2024
1 parent 91a952c commit 0d170c5
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions app/routes/content_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
content_sync_bp = Blueprint('content_sync', __name__)


class UpdateStatus:
"""Enumeration for update status"""
OK = "MAL=OK"
NO_UPDATE = "MAL=NO_UPDATE"
SKIP = "MAL=SKIPPED"
INVALID_ID = "MAL=INVALID_ID"
NOT_IN_LIST = "MAL=NOT_LISTED"
FAIL = "MAL=FAIL"


def _handle_content_id(content_id):
"""
Extract the ID of the content and the current episode.
Expand Down Expand Up @@ -49,32 +59,38 @@ def addon_content_sync(user_id: str, content_type: str, content_id: str, video_h
"""
content_id = urllib.parse.unquote(content_id)
if (IMDB_ID_PREFIX in content_id) or (content_type not in MANIFEST['types']):
return respond_with({'subtitles': []})

This comment has been minimized.

Copy link
@Pigamer37

Pigamer37 Dec 20, 2024

We came to the same conclusion about user feedback! Yours is more granular, but we even put about:blank as the url! Great minds think alike I guess hahaha

This comment has been minimized.

Copy link
@SageTendo

SageTendo Dec 20, 2024

Author Owner

Honestly, it was more your great mind at work! I saw your mention of how you implemented it, and thought it was a smart approach! :)

return respond_with({'subtitles': [{'id': 1, 'url': 'about:blank', 'lang': UpdateStatus.SKIP}]})

mal_id, current_episode = _handle_content_id(content_id)
if not mal_id:
return respond_with({'subtitles': [], 'message': 'Invalid content ID'})
return respond_with({'subtitles': [{'id': 1, 'url': 'about:blank', 'lang': UpdateStatus.INVALID_ID}],
'message': 'Invalid content ID'})

token = get_token(user_id)
resp = mal_client.get_anime_details(token, mal_id, fields='num_episodes my_list_status')
total_episodes = resp.get('num_episodes', 0)

list_status = resp.get('my_list_status', None)
if not list_status:
return respond_with({'subtitles': [], 'message': 'Nothing to update'})
return respond_with(
{'subtitles': [{'id': 1, 'url': 'about:blank', 'lang': UpdateStatus.NOT_IN_LIST}],
'message': 'Nothing to update'})

try:
current_status = list_status.get('status', None)
watched_episodes = list_status.get('num_episodes_watched', 0)

status, episode = handle_current_status(current_status, current_episode, watched_episodes, total_episodes)
if status is None:
return respond_with({'subtitles': [], 'message': 'Nothing to update'})
return respond_with({'subtitles': [{'id': 1, 'url': 'about:blank', 'lang': UpdateStatus.NO_UPDATE}],
'message': 'Nothing to update'})
mal_client.update_watched_status(token, mal_id, current_episode, status)
except HTTPError as err:
log_error(err)
return respond_with({'subtitles': [], 'message': 'Failed to update watched status'})
return respond_with({'subtitles': [], 'message': 'Updated watched status'})
return respond_with({'subtitles': [{'id': 1, 'url': 'about:blank', 'lang': UpdateStatus.FAIL}],
'message': 'Failed to update watched status'})
return respond_with(
{'subtitles': [{'id': 1, 'url': 'about:blank', 'lang': UpdateStatus.OK}], 'message': 'Updated watched status'})


def handle_current_status(status, current_episode, watched_episodes, total_episodes) -> (str, int):
Expand Down

0 comments on commit 0d170c5

Please sign in to comment.