-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- User feedback on tracking of anime through subtitle listings.
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
Showing
1 changed file
with
22 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
@@ -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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
SageTendo
Author
Owner
|
||
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): | ||
|
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