updating using index and code refactoring.

This commit is contained in:
CronyAkatsuki 2022-02-03 19:23:43 +01:00
parent 32833aee89
commit 4933308af4

73
adl.py
View File

@ -77,22 +77,23 @@ def check_title(title):
title = title.decode('utf-8') title = title.decode('utf-8')
return title return title
# get your title # get chosen anime info
def get_title(choice): def get_info(choice):
choice = choice[9:-19] # get index
choice = choice.rstrip(".") index = int(choice[4:7])
title = check_title(choice)
return title
# get episode # get title
def get_episode(choice): title = choice[9:-19]
choice = choice[-19:-15] title = title.rstrip(".")
return int(choice) title = check_title(title)
# get score # get episode
def get_score(choice): episode = int(choice[-19:-15])
choice = choice[-10:-5]
return choice # get score
score = int(choice[-10:-5])
return index, title, episode, score
# watch animes # watch animes
def watch(title, episode, download, provider, download_location): def watch(title, episode, download, provider, download_location):
@ -170,37 +171,37 @@ def custom_episode(title, msg, download,provider, download_location):
watch(title, episode, download, provider, download_location) watch(title, episode, download, provider, download_location)
# update title # update title
def update_title(title, episode, account): def update_title(index, title, episode, account):
color_print(f"Current episode for {title} is {str(episode)}") color_print(f"Current episode for {title} is {str(episode)}")
custom = color_prommpt("Enter updated episode number: ") custom = color_prommpt("Enter updated episode number: ")
if custom != "": if custom != "":
subprocess.call(f'trackma -a {account} update "{title}" {custom}') subprocess.call(f'trackma -a {account} update "{index}" {custom}')
subprocess.call(f'trackma -a {account} send') subprocess.call(f'trackma -a {account} send')
retrieve_list_update(account) retrieve_list_update(account)
else: else:
color_print("Skipping updating...") color_print("Skipping updating...")
# update score # update score
def update_score(title, score, account): def update_score(index, title, score, account):
color_print(f"Current score for {title} is {score}") color_print(f"Current score for {title} is {score}")
custom = color_prommpt("Enter updated score: ") custom = color_prommpt("Enter updated score: ")
if custom != "": if custom != "":
subprocess.call(f'trackma -a {account} score "{title}" {custom}') subprocess.call(f'trackma -a {account} score "{index}" {custom}')
subprocess.call(f'trackma -a {account} send') subprocess.call(f'trackma -a {account} send')
retrieve_list_update(account) retrieve_list_update(account)
else: else:
color_print("Skipping updating...") color_print("Skipping updating...")
# update question # update question
def update_question(title, episode, score, account): def update_question(index, title, episode, score, account):
while True: while True:
color_print("Skipping watching episodes. Modifing entry.") color_print("Skipping watching episodes. Modifing entry.")
choice = color_prommpt("Update episode number or update score [E/s]: ") choice = color_prommpt("Update episode number or update score [E/s]: ")
if choice == "e" or choice == "E" or choice == "": if choice == "e" or choice == "E" or choice == "":
update_title(title, episode, account) update_title(index, title, episode, account)
break break
elif choice == "s" or choice == "S": elif choice == "s" or choice == "S":
update_score(title, score, account) update_score(index, title, score, account)
break break
# ask if you wanna continus watching # ask if you wanna continus watching
@ -216,15 +217,15 @@ def wanna_continu_watch(download):
return False return False
# ask if you wanna update title meta after watch # ask if you wanna update title meta after watch
def wanna_update_title_after_watch(title, episode, score, download, account): def wanna_update_title_after_watch(index, title, episode, score, download, account):
if not download: if not download:
while True: while True:
yn = color_prommpt("Wanna update episode number or update score of watched anime? [N/e/s]: ") yn = color_prommpt("Wanna update episode number or update score of watched anime? [N/e/s]: ")
if yn == "E" or yn == "e": if yn == "E" or yn == "e":
update_title(title, episode, account) update_title(index, title, episode, account)
break break
elif yn == "S" or yn == "s": elif yn == "S" or yn == "s":
update_score(title, score, account) update_score(index, title, score, account)
break break
elif yn == "N" or yn == "n" or yn == "": elif yn == "N" or yn == "n" or yn == "":
break break
@ -399,12 +400,8 @@ def main_loop(retrieve, account, msg, download,provider, download_location):
choice = subprocess.getoutput(f'{PRINT_FZF_PATH} | fzf --ansi --unicode --reverse --prompt "Choose anime to watch: "') choice = subprocess.getoutput(f'{PRINT_FZF_PATH} | fzf --ansi --unicode --reverse --prompt "Choose anime to watch: "')
if choice: if choice:
# get the title # get needed info
title = get_title(choice) index, title, episode, score = get_info(choice)
# get current episode
episode = get_episode(choice)
# get current score
score = get_score(choice)
# the watch loop # the watch loop
while True: while True:
@ -413,19 +410,19 @@ def main_loop(retrieve, account, msg, download,provider, download_location):
# watch next episode # watch next episode
if action == "n" or action == "N" or action == "": if action == "n" or action == "N" or action == "":
next_episode(title, episode, msg, download,provider, download_location) next_episode(title, episode, msg, download,provider, download_location)
wanna_update_title_after_watch(title, episode, score, download, account) wanna_update_title_after_watch(index, title, episode, score, download, account)
exit_ask() exit_ask()
break break
# watch all left episodes # watch all left episodes
elif action == "l" or action == "L": elif action == "l" or action == "L":
all_from_last(title, episode, msg, download,provider, download_location) all_from_last(title, episode, msg, download,provider, download_location)
wanna_update_title_after_watch(title, episode, score, download, account) wanna_update_title_after_watch(index, title, episode, score, download, account)
exit_ask() exit_ask()
break break
# watch every episode available # watch every episode available
elif action == "a" or action == "A": elif action == "a" or action == "A":
all_episodes(title, msg, download,provider, download_location) all_episodes(title, msg, download,provider, download_location)
wanna_update_title_after_watch(title, episode, score, download, account) wanna_update_title_after_watch(index, title, episode, score, download, account)
exit_ask() exit_ask()
break break
# custom range of episodes # custom range of episodes
@ -434,7 +431,7 @@ def main_loop(retrieve, account, msg, download,provider, download_location):
if wanna_continu_watch(download): if wanna_continu_watch(download):
continue continue
else: else:
wanna_update_title_after_watch(title, episode, score, download, account) wanna_update_title_after_watch(index, title, episode, score, download, account)
exit_ask() exit_ask()
break break
# something? # something?
@ -443,7 +440,7 @@ def main_loop(retrieve, account, msg, download,provider, download_location):
if wanna_continu_watch(download): if wanna_continu_watch(download):
continue continue
else: else:
wanna_update_title_after_watch(title, episode, score, download, account) wanna_update_title_after_watch(index, title, episode, score, download, account)
exit_ask() exit_ask()
break break
# rewatch current episode # rewatch current episode
@ -452,7 +449,7 @@ def main_loop(retrieve, account, msg, download,provider, download_location):
if wanna_continu_watch(download): if wanna_continu_watch(download):
continue continue
else: else:
wanna_update_title_after_watch(title, episode, score, download, account) wanna_update_title_after_watch(index, title, episode, score, download, account)
exit_ask() exit_ask()
break break
# watch custom episode # watch custom episode
@ -461,12 +458,12 @@ def main_loop(retrieve, account, msg, download,provider, download_location):
if wanna_continu_watch(download): if wanna_continu_watch(download):
continue continue
else: else:
wanna_update_title_after_watch(title, episode, score, download, account) wanna_update_title_after_watch(index, title, episode, score, download, account)
exit_ask() exit_ask()
break break
# update anime meta # update anime meta
elif action == "u" or action == "U": elif action == "u" or action == "U":
update_question(title, episode, score, account) update_question(index, title, episode, score, account)
exit_ask() exit_ask()
break break
# skip the anime # skip the anime