From c1d6c1e082a6ec76a28286bf2fb38a5a52bdcf0a Mon Sep 17 00:00:00 2001 From: RaitaroHikami <19552720+RaitaroH@users.noreply.github.com> Date: Wed, 4 Jan 2023 14:50:35 +0000 Subject: [PATCH 01/10] list shows without formatting for issue https://github.com/z411/trackma/issues/660 --- trackma/ui/cli.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/trackma/ui/cli.py b/trackma/ui/cli.py index db7e91a8..663b546e 100644 --- a/trackma/ui/cli.py +++ b/trackma/ui/cli.py @@ -362,6 +362,13 @@ def do_list(self, args): # Show the list in memory self._make_list(self.sortedlist) + def do_list_raw(self, args): + """ + Similar to list except remove formatting. + : name list_raw + """ + self._make_list_raw(self.sortedlist) + def do_info(self, args): """ Gets detailed information about a local show. @@ -945,6 +952,26 @@ def _make_list(self, showlist): print('%d results' % len(showlist)) print() + def _make_list_raw(self, showlist): + """ + Helper function for printing a non-formatted show list + """ + altnames = self.engine.altnames() + + # List shows + for index, show in showlist: + if self.engine.mediainfo['has_progress']: + episodes_str = "{0}\t{1}".format( + show['my_progress'], show['total'] or '?') + else: + episodes_str = "-" + + # Get title (and alt. title) and if need be, truncate it + title_str = show['title'] + if altnames.get(show['id']): + title_str += " [{}]".format(altnames.get(show['id'])) + + print(index,title_str, episodes_str,show['my_score'],sep='\t') class Trackma_accounts(AccountManager): def _get_id(self, index): From 0b1137e3c9d63df663e07a9ea65f855cfc853cec Mon Sep 17 00:00:00 2001 From: RaitaroHikami <19552720+RaitaroH@users.noreply.github.com> Date: Wed, 4 Jan 2023 15:36:12 +0000 Subject: [PATCH 02/10] print name of show only faster than info --- trackma/ui/cli.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/trackma/ui/cli.py b/trackma/ui/cli.py index 663b546e..369bc443 100644 --- a/trackma/ui/cli.py +++ b/trackma/ui/cli.py @@ -74,6 +74,7 @@ class Trackma_cmd(command.Cmd): 'sort': 1, 'mediatype': (0, 1), 'info': 1, + 'name': 1, 'search': 1, 'add': 1, 'del': 1, @@ -369,6 +370,22 @@ def do_list_raw(self, args): """ self._make_list_raw(self.sortedlist) + def do_name(self, args): + """ + Print title name for given index. + + :param show Show index. + :usage name + """ + try: + show = self._get_show(args[0]) + details = self.engine.get_show_details(show) + except utils.TrackmaError as e: + self.display_error(e) + return + + print(show['title']) + def do_info(self, args): """ Gets detailed information about a local show. From c5483bc38dfe6c9f745a70b9f1667c71d3ca198d Mon Sep 17 00:00:00 2001 From: RaitaroHikami <19552720+RaitaroH@users.noreply.github.com> Date: Fri, 13 Jan 2023 17:05:01 +0000 Subject: [PATCH 03/10] print json format --- trackma/ui/cli.py | 66 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 16 deletions(-) diff --git a/trackma/ui/cli.py b/trackma/ui/cli.py index 369bc443..9255ed0e 100644 --- a/trackma/ui/cli.py +++ b/trackma/ui/cli.py @@ -22,6 +22,7 @@ import subprocess import sys import textwrap +import json from operator import itemgetter # Used for sorting list from trackma import messenger @@ -76,6 +77,7 @@ class Trackma_cmd(command.Cmd): 'info': 1, 'name': 1, 'search': 1, + 'list_json': (0, 1), 'add': 1, 'del': 1, 'delete': 1, @@ -363,12 +365,23 @@ def do_list(self, args): # Show the list in memory self._make_list(self.sortedlist) - def do_list_raw(self, args): + def do_list_json(self, args): """ - Similar to list except remove formatting. - : name list_raw + Print list of shows in json format. + Use the command `filter` without arguments to see the available statuses. + + :name list_json + :usage list_json """ - self._make_list_raw(self.sortedlist) + if args: + try: + self.filter_num = self._guess_status(args[0].lower()) + self._load_list() + except KeyError: + print("Invalid filter.") + return + + self._make_list_json(self.sortedlist) def do_name(self, args): """ @@ -379,7 +392,6 @@ def do_name(self, args): """ try: show = self._get_show(args[0]) - details = self.engine.get_show_details(show) except utils.TrackmaError as e: self.display_error(e) return @@ -969,26 +981,48 @@ def _make_list(self, showlist): print('%d results' % len(showlist)) print() - def _make_list_raw(self, showlist): + def _make_list_json(self, showlist): """ - Helper function for printing a non-formatted show list + helper function for printing a json formatted show list """ altnames = self.engine.altnames() - # List shows + episode_str_current = "" + episode_str_last = "" + # list shows for index, show in showlist: if self.engine.mediainfo['has_progress']: - episodes_str = "{0}\t{1}".format( - show['my_progress'], show['total'] or '?') - else: - episodes_str = "-" + episode_str_current = "{0}".format(show['my_progress'] or '0') + episode_str_last = "{0}".format(show['total'] or '?') - # Get title (and alt. title) and if need be, truncate it + # get title (and alt. title) and if need be, truncate it title_str = show['title'] if altnames.get(show['id']): title_str += " [{}]".format(altnames.get(show['id'])) - print(index,title_str, episodes_str,show['my_score'],sep='\t') + # ensure score is string; anilist can have string scores such as stars or smiles + score = "{0}".format(show['my_score']) + + # json dictionary + j = { + "title": title_str, + "current_episode": episode_str_current, + "final_episode": episode_str_last, + "score": score + } + + # Color title according to status + if show['status'] == utils.Status.AIRING: + estimate = utils.estimate_aired_episodes(show) + if estimate and show['my_progress'] < estimate: + # User is behind the (estimated) aired episode + j["color"] = _COLOR_BEHIND + else: + j["color"] = _COLOR_AIRING + else: + j["color"] = _COLOR_RESET + + print(json.dumps(j)) class Trackma_accounts(AccountManager): def _get_id(self, index): @@ -1027,12 +1061,12 @@ def select_account(self, bypass): password = getpass.getpass('Enter password (no echo): ') elif selected_api[2] in [utils.Login.OAUTH, utils.Login.OAUTH_PKCE]: username = input('Enter account name: ') - + auth_url = selected_api[3] if selected_api[2] == utils.Login.OAUTH_PKCE: extra['code_verifier'] = utils.oauth_generate_pkce() auth_url = auth_url % extra['code_verifier'] - + print('OAuth Authentication') print('--------------------') print('This website requires OAuth authentication.') From 95da16025575087110087b3441fd9153ceeb3dac Mon Sep 17 00:00:00 2001 From: RaitaroHikami <19552720+RaitaroH@users.noreply.github.com> Date: Sat, 14 Jan 2023 11:38:47 +0000 Subject: [PATCH 04/10] remove name funciton reverts 0b1137e3c9d63df663e07a9ea65f855cfc853cec --- trackma/ui/cli.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/trackma/ui/cli.py b/trackma/ui/cli.py index 9255ed0e..a4818a94 100644 --- a/trackma/ui/cli.py +++ b/trackma/ui/cli.py @@ -75,7 +75,6 @@ class Trackma_cmd(command.Cmd): 'sort': 1, 'mediatype': (0, 1), 'info': 1, - 'name': 1, 'search': 1, 'list_json': (0, 1), 'add': 1, @@ -383,21 +382,6 @@ def do_list_json(self, args): self._make_list_json(self.sortedlist) - def do_name(self, args): - """ - Print title name for given index. - - :param show Show index. - :usage name - """ - try: - show = self._get_show(args[0]) - except utils.TrackmaError as e: - self.display_error(e) - return - - print(show['title']) - def do_info(self, args): """ Gets detailed information about a local show. From 27a07c0e8cc41de5207174d53b337089b5c63902 Mon Sep 17 00:00:00 2001 From: RaitaroHikami <19552720+RaitaroH@users.noreply.github.com> Date: Sat, 14 Jan 2023 11:58:50 +0000 Subject: [PATCH 05/10] total_episodes key Co-authored-by: FichteFoll --- trackma/ui/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trackma/ui/cli.py b/trackma/ui/cli.py index a4818a94..226e58a4 100644 --- a/trackma/ui/cli.py +++ b/trackma/ui/cli.py @@ -991,7 +991,7 @@ def _make_list_json(self, showlist): j = { "title": title_str, "current_episode": episode_str_current, - "final_episode": episode_str_last, + "total_episodes": episode_str_last, "score": score } From dbd4a221c80bb50680c4db02ff71585c79a06d37 Mon Sep 17 00:00:00 2001 From: RaitaroHikami <19552720+RaitaroH@users.noreply.github.com> Date: Sat, 14 Jan 2023 12:17:20 +0000 Subject: [PATCH 06/10] ignore altnames --- trackma/ui/cli.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/trackma/ui/cli.py b/trackma/ui/cli.py index 226e58a4..bf8e0add 100644 --- a/trackma/ui/cli.py +++ b/trackma/ui/cli.py @@ -979,10 +979,8 @@ def _make_list_json(self, showlist): episode_str_current = "{0}".format(show['my_progress'] or '0') episode_str_last = "{0}".format(show['total'] or '?') - # get title (and alt. title) and if need be, truncate it + # get title title_str = show['title'] - if altnames.get(show['id']): - title_str += " [{}]".format(altnames.get(show['id'])) # ensure score is string; anilist can have string scores such as stars or smiles score = "{0}".format(show['my_score']) From b4ae65b5bf567d596c20e09684e71b714e7ddf11 Mon Sep 17 00:00:00 2001 From: RaitaroHikami <19552720+RaitaroH@users.noreply.github.com> Date: Sat, 14 Jan 2023 12:28:30 +0000 Subject: [PATCH 07/10] airing and behind status --- trackma/ui/cli.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/trackma/ui/cli.py b/trackma/ui/cli.py index bf8e0add..5abb8680 100644 --- a/trackma/ui/cli.py +++ b/trackma/ui/cli.py @@ -990,19 +990,20 @@ def _make_list_json(self, showlist): "title": title_str, "current_episode": episode_str_current, "total_episodes": episode_str_last, - "score": score + "score": score, + "airing_status": False, + "behind_status": False } - # Color title according to status + # Check if show is airing and if user is behind if show['status'] == utils.Status.AIRING: estimate = utils.estimate_aired_episodes(show) if estimate and show['my_progress'] < estimate: # User is behind the (estimated) aired episode - j["color"] = _COLOR_BEHIND + j["airing_status"] = True; + j["behind_status"] = True; else: - j["color"] = _COLOR_AIRING - else: - j["color"] = _COLOR_RESET + j["airing_status"] = True; print(json.dumps(j)) From 108fbf2d4c97d3246f33004bfa361a6da058dcc1 Mon Sep 17 00:00:00 2001 From: RaitaroHikami <19552720+RaitaroH@users.noreply.github.com> Date: Sat, 14 Jan 2023 15:30:34 +0000 Subject: [PATCH 08/10] Update cli.py --- trackma/ui/cli.py | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/trackma/ui/cli.py b/trackma/ui/cli.py index 5abb8680..b540d9a2 100644 --- a/trackma/ui/cli.py +++ b/trackma/ui/cli.py @@ -969,41 +969,29 @@ def _make_list_json(self, showlist): """ helper function for printing a json formatted show list """ - altnames = self.engine.altnames() - episode_str_current = "" - episode_str_last = "" # list shows for index, show in showlist: if self.engine.mediainfo['has_progress']: episode_str_current = "{0}".format(show['my_progress'] or '0') episode_str_last = "{0}".format(show['total'] or '?') - # get title - title_str = show['title'] - # ensure score is string; anilist can have string scores such as stars or smiles score = "{0}".format(show['my_score']) # json dictionary j = { - "title": title_str, + "title": show['title'], "current_episode": episode_str_current, "total_episodes": episode_str_last, "score": score, - "airing_status": False, - "behind_status": False + "status": show['status'].value } - # Check if show is airing and if user is behind + # Check if show is airing and get estimated aired episode if show['status'] == utils.Status.AIRING: estimate = utils.estimate_aired_episodes(show) - if estimate and show['my_progress'] < estimate: - # User is behind the (estimated) aired episode - j["airing_status"] = True; - j["behind_status"] = True; - else: - j["airing_status"] = True; + j["estimated_aired_episode"] = estimate print(json.dumps(j)) From 5a200d9df7eb8ffa83c01bfee0ca42e436a0116a Mon Sep 17 00:00:00 2001 From: RaitaroHikami <19552720+RaitaroH@users.noreply.github.com> Date: Sun, 15 Jan 2023 07:08:37 +0000 Subject: [PATCH 09/10] estimate episode as string --- trackma/ui/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trackma/ui/cli.py b/trackma/ui/cli.py index b540d9a2..397f1116 100644 --- a/trackma/ui/cli.py +++ b/trackma/ui/cli.py @@ -991,7 +991,7 @@ def _make_list_json(self, showlist): # Check if show is airing and get estimated aired episode if show['status'] == utils.Status.AIRING: estimate = utils.estimate_aired_episodes(show) - j["estimated_aired_episode"] = estimate + j["estimated_aired_episode"] = "{0}".format(estimate) print(json.dumps(j)) From 2b681baf39eec41f9fd3e40b3b16c1e30a1ef2b7 Mon Sep 17 00:00:00 2001 From: RaitaroHikami <19552720+RaitaroH@users.noreply.github.com> Date: Sun, 15 Jan 2023 18:05:48 +0000 Subject: [PATCH 10/10] also print cover image this should be useful in my adl script --- trackma/ui/cli.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/trackma/ui/cli.py b/trackma/ui/cli.py index 397f1116..6ecd1c6b 100644 --- a/trackma/ui/cli.py +++ b/trackma/ui/cli.py @@ -993,6 +993,9 @@ def _make_list_json(self, showlist): estimate = utils.estimate_aired_episodes(show) j["estimated_aired_episode"] = "{0}".format(estimate) + # cover image url + j["image"] = show['image'] + print(json.dumps(j)) class Trackma_accounts(AccountManager):