2021-07-03 15:05:12 +02:00
|
|
|
import os, subprocess, sys, argparse
|
2021-06-27 16:24:51 +02:00
|
|
|
from iterfzf import iterfzf
|
|
|
|
from time import sleep
|
|
|
|
|
2021-06-27 20:48:43 +02:00
|
|
|
# global variables
|
2021-07-03 15:05:12 +02:00
|
|
|
account = "0" # trackma account
|
2021-06-27 20:48:43 +02:00
|
|
|
retrieve = True # retrieve new list
|
|
|
|
player = "mpv" # specific player
|
2021-07-01 18:51:32 +02:00
|
|
|
download = False # specify whether to download or not
|
2021-07-03 15:05:12 +02:00
|
|
|
msg = "watching"
|
2021-06-27 20:48:43 +02:00
|
|
|
|
2021-07-03 15:05:12 +02:00
|
|
|
ap = argparse.ArgumentParser()
|
|
|
|
|
|
|
|
ap.add_argument("-a", "--account", required=False,
|
|
|
|
help="By default trackma will use account 1. Use '-a 2' for example to change trackma account")
|
|
|
|
ap.add_argument("-p", "--player", required=False,
|
|
|
|
help="Define player used for streaming. Ex: \033[0;36mpyadl -p mpv\033[0m")
|
|
|
|
ap.add_argument("-d", "--download", required=False, type=bool, nargs='?', const=True, default=False,
|
|
|
|
help="Download instead of streaming")
|
|
|
|
ap.add_argument("-v", "--version", required=False,
|
|
|
|
help="Display version and exit")
|
|
|
|
|
|
|
|
args = vars(ap.parse_args())
|
|
|
|
|
|
|
|
if args['account']:
|
|
|
|
account = str(int(args["account"]) - 1)
|
|
|
|
|
|
|
|
if args["player"]:
|
|
|
|
player = str(args["player"])
|
|
|
|
|
|
|
|
if args["download"]:
|
|
|
|
download = True
|
|
|
|
msg = "downloading"
|
|
|
|
|
|
|
|
if args["version"]:
|
|
|
|
print("version: 0.1")
|
|
|
|
sys.exit()
|
|
|
|
|
2021-06-27 20:48:43 +02:00
|
|
|
# colored print
|
2021-06-27 16:24:51 +02:00
|
|
|
def color_print(text):
|
|
|
|
print("\033[0;36m" + text + " \033[0m")
|
|
|
|
|
2021-06-27 20:48:43 +02:00
|
|
|
# colored watch primpt
|
2021-06-27 21:28:26 +02:00
|
|
|
def watch_prompt(title, episode):
|
2021-07-03 15:05:12 +02:00
|
|
|
print("Now " + msg + " \033[0;34m" + title + "\033[0m, episode \033[0;34m" + str(episode) + " \033[0m")
|
2021-06-27 20:48:43 +02:00
|
|
|
|
|
|
|
# colored input
|
2021-06-27 16:24:51 +02:00
|
|
|
def color_prommpt(text):
|
|
|
|
return input("\033[0;34m" + text + "\033[0m")
|
|
|
|
|
2021-06-27 20:48:43 +02:00
|
|
|
# iter the list
|
2021-06-27 16:24:51 +02:00
|
|
|
def iter_list(alist):
|
|
|
|
for anime in alist:
|
|
|
|
yield anime.strip()
|
|
|
|
sleep(0.01)
|
|
|
|
|
2021-06-27 20:48:43 +02:00
|
|
|
# retrieve new list
|
2021-07-03 15:05:12 +02:00
|
|
|
def retrieve_list():
|
2021-06-27 16:24:51 +02:00
|
|
|
color_print ("Running trackma retrieve for account " + account + "...")
|
|
|
|
os.system("trackma -a " + account + " retrieve")
|
|
|
|
os.system("cls")
|
2021-07-03 12:00:03 +02:00
|
|
|
|
|
|
|
# retrieve updated list
|
|
|
|
def retrieve_list_update(account):
|
|
|
|
color_print("Running trackma retrieve for account " + account + " to get the updated list...")
|
|
|
|
os.system("trackma -a " + account + " retrieve")
|
|
|
|
os.system("cls")
|
2021-06-27 16:24:51 +02:00
|
|
|
|
2021-06-27 20:48:43 +02:00
|
|
|
# load list
|
2021-07-03 15:05:12 +02:00
|
|
|
def load_list():
|
2021-06-27 16:24:51 +02:00
|
|
|
alist = subprocess.getoutput("trackma -a " + account + " list").splitlines()
|
|
|
|
alist.pop(0)
|
|
|
|
alist.pop()
|
|
|
|
return alist
|
|
|
|
|
2021-06-27 20:48:43 +02:00
|
|
|
# exit prompt
|
2021-06-27 16:24:51 +02:00
|
|
|
def exit_ask():
|
|
|
|
while True:
|
|
|
|
os.system("cls")
|
|
|
|
choice = color_prommpt("Want to watch another anime? [Y/n]: ")
|
|
|
|
if choice == "":
|
|
|
|
sys.exit()
|
|
|
|
elif choice == "N" or choice == "n":
|
|
|
|
sys.exit()
|
|
|
|
elif choice == "Y" or choice == "y":
|
|
|
|
return
|
2021-06-27 20:48:43 +02:00
|
|
|
|
2021-06-27 21:28:26 +02:00
|
|
|
# get your title
|
2021-06-27 20:48:43 +02:00
|
|
|
def get_title(full_choice):
|
2021-06-27 16:24:51 +02:00
|
|
|
full_choice = full_choice[9:55]
|
|
|
|
full_choice = full_choice.rstrip(".")
|
|
|
|
return full_choice
|
|
|
|
|
2021-06-27 21:28:26 +02:00
|
|
|
# get episode
|
2021-06-27 20:48:43 +02:00
|
|
|
def get_episode(full_choice):
|
2021-06-27 16:24:51 +02:00
|
|
|
full_choice = full_choice[58:60]
|
|
|
|
return int(full_choice)
|
|
|
|
|
2021-06-27 21:28:26 +02:00
|
|
|
# get all episodes
|
2021-06-27 20:48:43 +02:00
|
|
|
def get_all_episodes(full_choice):
|
2021-06-27 16:24:51 +02:00
|
|
|
full_choice = full_choice[63:65]
|
|
|
|
return full_choice
|
|
|
|
|
2021-06-27 21:58:43 +02:00
|
|
|
# get score
|
|
|
|
def get_score(full_choice):
|
|
|
|
full_choice = full_choice[68:71]
|
|
|
|
return full_choice
|
|
|
|
|
2021-06-27 21:28:26 +02:00
|
|
|
# next episode
|
2021-07-03 15:05:12 +02:00
|
|
|
def next_episode(title,episode):
|
|
|
|
if not download:
|
|
|
|
watch_next = True
|
|
|
|
while watch_next:
|
|
|
|
episode = episode + 1
|
|
|
|
watch_prompt(title, str(episode))
|
|
|
|
os.system('anime dl "' + title + '" --episodes ' + str(episode) + ' --play ' + player)
|
|
|
|
while True:
|
|
|
|
color_print("Current watched episode: " + str(episode))
|
|
|
|
yn = color_prommpt("Wanna watch next episode? [Y/n]: ")
|
|
|
|
if yn == "Y" or yn == "y":
|
|
|
|
break
|
|
|
|
elif yn == "N" or yn == "n":
|
|
|
|
watch_next = False
|
|
|
|
break
|
|
|
|
else:
|
2021-07-03 11:43:36 +02:00
|
|
|
episode = episode + 1
|
|
|
|
watch_prompt(title, str(episode))
|
2021-07-03 15:05:12 +02:00
|
|
|
os.system('anime dl "' + title + '" --episodes ' + str(episode))
|
2021-06-27 16:24:51 +02:00
|
|
|
|
2021-06-27 21:28:26 +02:00
|
|
|
# all from last watched
|
2021-07-03 15:05:12 +02:00
|
|
|
def all_from_last(title,episode):
|
2021-06-27 21:28:26 +02:00
|
|
|
watch_prompt(title, str(episode) + " all left episodes")
|
2021-07-03 15:05:12 +02:00
|
|
|
if not download:
|
|
|
|
os.system('anime dl "' + title + '" --episodes ' + str(episode + 1) + ': --play' + player)
|
|
|
|
else:
|
|
|
|
os.system('anime dl "' + title + '" --episodes ' + str(episode + 1) + ':')
|
2021-06-27 20:48:43 +02:00
|
|
|
|
2021-06-27 21:28:26 +02:00
|
|
|
# all episode
|
2021-07-03 15:05:12 +02:00
|
|
|
def all_episodes(title):
|
2021-06-27 21:28:26 +02:00
|
|
|
watch_prompt(title, "all")
|
2021-07-03 15:05:12 +02:00
|
|
|
if not download:
|
|
|
|
os.system('anime dl "' + title + '" --episodes 1: --play ' + player)
|
|
|
|
else:
|
|
|
|
os.system('anime dl "' + title + '" --episodes 1:')
|
2021-06-27 21:28:26 +02:00
|
|
|
|
|
|
|
# watch from custom range
|
2021-07-03 15:05:12 +02:00
|
|
|
def custom_episode_range(title):
|
2021-06-27 21:28:26 +02:00
|
|
|
begginig = color_prommpt("Beggining of interval?: ")
|
|
|
|
end = color_prommpt("End of interval?: ")
|
|
|
|
watch_prompt(title, begginig + " to " + end)
|
2021-07-03 15:05:12 +02:00
|
|
|
if not download:
|
|
|
|
os.system('anime dl "' + title + '" --episodes ' + begginig + ':' + end +' --play ' + player)
|
|
|
|
else:
|
|
|
|
os.system('anime dl "' + title + '" --episodes ' + begginig + ':' + end)
|
2021-06-27 21:28:26 +02:00
|
|
|
|
|
|
|
# add to last watched m
|
2021-07-03 15:05:12 +02:00
|
|
|
def next_plus_n(title, episode, action):
|
2021-06-27 21:28:26 +02:00
|
|
|
watch_prompt(title, str(episode + int(action)))
|
2021-07-03 15:05:12 +02:00
|
|
|
if not download:
|
|
|
|
os.system('anime dl "' + title + '" --episodes ' + str(episode + int(action)) + ' --play ' + player)
|
|
|
|
else:
|
|
|
|
os.system('anime dl "' + title + '" --episodes ' + str(episode + int(action)))
|
2021-06-27 21:28:26 +02:00
|
|
|
|
|
|
|
# rewatch current episode
|
2021-07-03 15:05:12 +02:00
|
|
|
def rewatch_episode(title, episode):
|
2021-06-27 21:28:26 +02:00
|
|
|
watch_prompt(title, str(episode))
|
2021-07-03 15:05:12 +02:00
|
|
|
if not download:
|
|
|
|
os.system('anime dl "' + title + '" --episodes ' + str(episode) + ' --play ' + player)
|
|
|
|
else:
|
|
|
|
os.system('anime dl "' + title + '" --episodes ' + str(episode))
|
2021-06-27 21:28:26 +02:00
|
|
|
|
|
|
|
# watch custom episode
|
2021-07-03 15:05:12 +02:00
|
|
|
def custom_episode(title):
|
2021-06-27 21:28:26 +02:00
|
|
|
episode = color_prommpt("Enter custom episode: ")
|
|
|
|
watch_prompt(title, episode)
|
2021-07-03 15:05:12 +02:00
|
|
|
if not download:
|
|
|
|
os.system('anime dl "' + title + '" --episodes ' + episode + ' --play ' + player)
|
|
|
|
else:
|
|
|
|
os.system('anime dl "' + title + '" --episodes ' + episode)
|
2021-06-27 21:58:43 +02:00
|
|
|
|
|
|
|
# update title
|
|
|
|
def update_title(title, episode):
|
|
|
|
color_print("Current episode for " + title + " is " + str(episode))
|
|
|
|
custom = color_prommpt("Enter updated episode number: ")
|
|
|
|
if custom != "":
|
|
|
|
os.system('trackma -a ' + account + ' update "' + title + '" ' + custom)
|
2021-07-03 11:07:57 +02:00
|
|
|
os.system('trackma -a' + account + 'send')
|
2021-07-03 12:00:03 +02:00
|
|
|
retrieve_list_update(account)
|
2021-06-27 21:58:43 +02:00
|
|
|
else:
|
|
|
|
color_print("Skipping updating...")
|
|
|
|
|
|
|
|
# update score
|
|
|
|
def update_score(title, score):
|
|
|
|
color_print("Current score for " + title + " is " + score)
|
|
|
|
custom = color_prommpt("Enter updated score: ")
|
|
|
|
if custom != "":
|
|
|
|
os.system('trackma -a ' + account + ' score "' + title + '" ' + custom)
|
2021-07-03 11:07:57 +02:00
|
|
|
os.system('trackma -a' + account + 'send')
|
2021-07-03 12:00:03 +02:00
|
|
|
retrieve_list_update(account)
|
2021-06-27 21:58:43 +02:00
|
|
|
else:
|
|
|
|
color_print("Skipping updating...")
|
|
|
|
|
|
|
|
# update question
|
|
|
|
def update_question(title, episode, score):
|
|
|
|
while True:
|
|
|
|
color_print("Skipping watching episodes. Modifing entry.")
|
|
|
|
choice = color_prommpt("Update episode number or update score [E/s]: ")
|
|
|
|
if choice == "e" or choice == "E":
|
|
|
|
update_title(title, episode)
|
|
|
|
break
|
|
|
|
elif choice == "s" or choice == "S":
|
|
|
|
update_score(title, score)
|
|
|
|
break
|
2021-06-27 21:28:26 +02:00
|
|
|
|
2021-06-28 15:10:52 +02:00
|
|
|
# ask if you wanna continus watching
|
|
|
|
def wanna_continu_watch():
|
|
|
|
while True:
|
2021-07-01 18:51:32 +02:00
|
|
|
yn = color_prommpt("Wanna continue watching? [Y/n]: ")
|
2021-06-28 15:10:52 +02:00
|
|
|
if yn == "y" or yn == "Y":
|
|
|
|
return True
|
|
|
|
elif yn == "n" or yn == "N":
|
|
|
|
return False
|
|
|
|
|
2021-07-03 12:00:03 +02:00
|
|
|
# ask if you wanna update title meta after watch
|
2021-07-01 18:51:32 +02:00
|
|
|
def wanna_update_title_after_watch(title, episode, score):
|
|
|
|
while True:
|
2021-07-03 11:43:36 +02:00
|
|
|
yn = color_prommpt("Wanna update episode number or update score of watched anime? [N/e/s]: ")
|
2021-07-01 18:51:32 +02:00
|
|
|
if yn == "E" or yn == "e":
|
|
|
|
update_title(title, episode)
|
|
|
|
break
|
|
|
|
elif yn == "S" or yn == "s":
|
|
|
|
update_score(title, score)
|
|
|
|
break
|
2021-07-03 11:43:36 +02:00
|
|
|
elif yn == "N" or yn == "n":
|
|
|
|
break
|
2021-07-01 18:51:32 +02:00
|
|
|
|
2021-06-27 21:28:26 +02:00
|
|
|
# choose what to do with episode
|
2021-06-27 16:24:51 +02:00
|
|
|
def choose_episode():
|
|
|
|
os.system("cls")
|
|
|
|
color_print("Enter lowercase or uppercase to issue command:")
|
|
|
|
color_print(" N - Next episode (default, press <ENTER>)")
|
|
|
|
color_print(" L - from current to Last known:")
|
|
|
|
color_print(" A - All available, from episode 1")
|
|
|
|
color_print(" I - custom Interval (range) of episodes")
|
|
|
|
color_print(" 0-9 - Plus n episodes relative to last seen (type number)")
|
|
|
|
color_print(" R - Rewatch/redownload current episode in list")
|
|
|
|
color_print(" C - Custom episode")
|
|
|
|
color_print(" U - Update entry chosen instead of streaming")
|
|
|
|
color_print(" S - Skip. Choose another show.")
|
|
|
|
return color_prommpt("Your choice? [N/l/a/i/0-9/r/c/u/s]: ")
|
|
|
|
|
2021-07-03 12:32:35 +02:00
|
|
|
# main loop
|
2021-06-27 16:24:51 +02:00
|
|
|
while True:
|
2021-07-03 12:32:35 +02:00
|
|
|
# retrieving the list on start
|
2021-06-27 16:24:51 +02:00
|
|
|
if retrieve:
|
2021-07-03 15:05:12 +02:00
|
|
|
retrieve_list()
|
2021-06-27 16:24:51 +02:00
|
|
|
retrieve = False
|
|
|
|
|
2021-07-03 12:32:35 +02:00
|
|
|
# get the list of anime
|
2021-07-03 15:05:12 +02:00
|
|
|
alist = load_list()
|
2021-07-03 12:32:35 +02:00
|
|
|
# choose an anime from the list
|
2021-06-27 16:24:51 +02:00
|
|
|
choice = iterfzf(iter_list(alist))
|
|
|
|
|
|
|
|
if choice:
|
2021-07-03 12:32:35 +02:00
|
|
|
# get the whole choice into a string
|
2021-06-27 20:48:43 +02:00
|
|
|
full_choice = "".join(choice)
|
2021-07-03 12:32:35 +02:00
|
|
|
# get the title
|
2021-06-27 20:48:43 +02:00
|
|
|
title = get_title(full_choice)
|
2021-07-03 12:32:35 +02:00
|
|
|
# get current episode
|
2021-06-27 20:48:43 +02:00
|
|
|
episode = get_episode(full_choice)
|
2021-07-03 12:32:35 +02:00
|
|
|
# get latest episode
|
2021-06-27 21:28:26 +02:00
|
|
|
last_episode = get_all_episodes(full_choice)
|
2021-07-03 12:32:35 +02:00
|
|
|
# get current score
|
2021-06-27 21:58:43 +02:00
|
|
|
score = get_score(full_choice)
|
2021-07-03 12:32:35 +02:00
|
|
|
|
|
|
|
# the watch loop
|
2021-06-27 16:24:51 +02:00
|
|
|
while True:
|
2021-07-03 12:32:35 +02:00
|
|
|
# choose what to do with the choosen anime
|
2021-07-01 18:51:32 +02:00
|
|
|
action = choose_episode()
|
2021-07-03 12:32:35 +02:00
|
|
|
# watch next episode
|
2021-06-27 16:24:51 +02:00
|
|
|
if action == "":
|
2021-07-03 15:05:12 +02:00
|
|
|
next_episode(title, episode)
|
2021-07-03 11:43:36 +02:00
|
|
|
wanna_update_title_after_watch(title, episode, score)
|
|
|
|
break
|
2021-07-03 12:32:35 +02:00
|
|
|
# same
|
2021-06-27 16:24:51 +02:00
|
|
|
elif action == "n" or action == "N":
|
2021-07-03 15:05:12 +02:00
|
|
|
next_episode(title, episode)
|
2021-07-03 11:43:36 +02:00
|
|
|
wanna_update_title_after_watch(title, episode, score)
|
|
|
|
break
|
2021-07-03 12:32:35 +02:00
|
|
|
# watch all left episodes
|
2021-06-27 16:24:51 +02:00
|
|
|
elif action == "l" or action == "L":
|
2021-07-03 15:05:12 +02:00
|
|
|
all_from_last(title, episode,last_episode)
|
2021-07-01 18:51:32 +02:00
|
|
|
wanna_update_title_after_watch(title, episode, score)
|
2021-06-27 16:24:51 +02:00
|
|
|
break
|
2021-07-03 12:32:35 +02:00
|
|
|
# watch every episode available
|
2021-06-27 16:24:51 +02:00
|
|
|
elif action == "a" or action == "A":
|
2021-07-03 15:05:12 +02:00
|
|
|
all_episodes(title)
|
2021-07-01 18:51:32 +02:00
|
|
|
wanna_update_title_after_watch(title, episode, score)
|
2021-06-27 21:28:26 +02:00
|
|
|
break
|
2021-07-03 12:32:35 +02:00
|
|
|
# custom range of episodes
|
2021-06-27 21:28:26 +02:00
|
|
|
elif action == "i" or action == "I":
|
2021-07-03 15:05:12 +02:00
|
|
|
custom_episode_range(title)
|
2021-06-28 15:10:52 +02:00
|
|
|
if wanna_continu_watch():
|
|
|
|
continue
|
|
|
|
else:
|
2021-07-01 18:51:32 +02:00
|
|
|
wanna_update_title_after_watch(title, episode, score)
|
2021-06-28 15:10:52 +02:00
|
|
|
break
|
2021-07-03 12:32:35 +02:00
|
|
|
# something?
|
2021-06-27 21:28:26 +02:00
|
|
|
elif action == "1" or action == "2" or action == "3" or action == "4" or action == "5" or action == "6" or action == "7" or action == "8" or action == "9":
|
2021-07-03 15:05:12 +02:00
|
|
|
next_plus_n(title, episode, action)
|
2021-06-28 15:10:52 +02:00
|
|
|
if wanna_continu_watch():
|
|
|
|
continue
|
|
|
|
else:
|
2021-07-01 18:51:32 +02:00
|
|
|
wanna_update_title_after_watch(title, episode, score)
|
2021-06-28 15:10:52 +02:00
|
|
|
break
|
2021-07-03 12:32:35 +02:00
|
|
|
# rewatch current episode
|
2021-06-27 16:24:51 +02:00
|
|
|
elif action == "r" or action == "R":
|
2021-07-03 15:05:12 +02:00
|
|
|
rewatch_episode(title, episode)
|
2021-06-28 15:10:52 +02:00
|
|
|
if wanna_continu_watch():
|
|
|
|
continue
|
|
|
|
else:
|
2021-07-01 18:51:32 +02:00
|
|
|
wanna_update_title_after_watch(title, episode, score)
|
2021-06-28 15:10:52 +02:00
|
|
|
break
|
2021-07-03 12:32:35 +02:00
|
|
|
# watch custom episode
|
2021-06-27 16:24:51 +02:00
|
|
|
elif action == "c" or action == "C":
|
2021-07-03 15:05:12 +02:00
|
|
|
custom_episode(title)
|
2021-06-28 15:10:52 +02:00
|
|
|
if wanna_continu_watch():
|
|
|
|
continue
|
|
|
|
else:
|
2021-07-01 18:51:32 +02:00
|
|
|
wanna_update_title_after_watch(title, episode, score)
|
2021-06-28 15:10:52 +02:00
|
|
|
break
|
2021-07-03 12:32:35 +02:00
|
|
|
# update anime meta
|
2021-06-27 16:24:51 +02:00
|
|
|
elif action == "u" or action == "U":
|
2021-06-27 21:58:43 +02:00
|
|
|
update_question(title, episode, score)
|
2021-06-27 16:24:51 +02:00
|
|
|
break
|
2021-07-03 12:32:35 +02:00
|
|
|
# skip the anime
|
2021-06-27 16:24:51 +02:00
|
|
|
elif action == "s" or action == "S":
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
exit_ask()
|