anidl/adl.py

233 lines
7.7 KiB
Python
Raw Normal View History

2021-06-27 16:24:51 +02:00
import os, subprocess, sys
2021-06-28 15:10:52 +02:00
from symbol import continue_stmt
2021-06-27 16:24:51 +02:00
from iterfzf import iterfzf
from time import sleep
# global variables
account = "0" # choose an account
episode = "" # specific episode
retrieve = True # retrieve new list
player = "mpv" # specific player
# colored print
2021-06-27 16:24:51 +02:00
def color_print(text):
print("\033[0;36m" + text + " \033[0m")
# colored watch primpt
2021-06-27 21:28:26 +02:00
def watch_prompt(title, episode):
print("Now watching \033[0;34m" + title + "\033[0m, episode \033[0;34m" + str(episode) + " \033[0m")
# colored input
2021-06-27 16:24:51 +02:00
def color_prommpt(text):
return input("\033[0;34m" + text + "\033[0m")
# 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)
# retrieve new list
2021-06-27 16:24:51 +02:00
def retrieve_list(account):
color_print ("Running trackma retrieve for account " + account + "...")
os.system("trackma -a " + account + " retrieve")
os.system("cls")
# load list
2021-06-27 16:24:51 +02:00
def load_list(account):
alist = subprocess.getoutput("trackma -a " + account + " list").splitlines()
alist.pop(0)
alist.pop()
return alist
# 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 21:28:26 +02:00
# get your title
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
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
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-06-27 16:24:51 +02:00
def next_episode(title,episode,player):
2021-06-27 21:28:26 +02:00
watch_prompt(title, str(episode))
2021-06-27 16:24:51 +02:00
os.system('anime dl "' + title + '" --episodes ' + str(episode + 1) + ' --play ' + player)
2021-06-27 21:28:26 +02:00
# all from last watched
def all_from_last(title,episode, player):
watch_prompt(title, str(episode) + " all left episodes")
os.system('anime dl "' + title + '" --episodes ' + str(episode + 1) + ': --play' + player)
2021-06-27 21:28:26 +02:00
# all episode
def all_episodes(title, player):
watch_prompt(title, "all")
os.system('anime dl "' + title + '" --episodes 1: --play ' + player)
# watch from custom range
def custom_episode_range(title, player):
begginig = color_prommpt("Beggining of interval?: ")
end = color_prommpt("End of interval?: ")
watch_prompt(title, begginig + " to " + end)
os.system('anime dl "' + title + '" --episodes ' + begginig + ':' + end +' --play ' + player)
# add to last watched m
def next_plus_n(title, episode, player, action):
watch_prompt(title, str(episode + int(action)))
os.system('anime dl "' + title + '" --episodes ' + str(episode + int(action)) + ' --play ' + player)
# rewatch current episode
def rewatch_episode(title, episode, player):
watch_prompt(title, str(episode))
os.system('anime dl "' + title + '" --episodes ' + str(episode) + ' --play ' + player)
# watch custom episode
def custom_episode(title, player):
episode = color_prommpt("Enter custom episode: ")
watch_prompt(title, episode)
os.system('anime dl "' + title + '" --episodes ' + episode + ' --play ' + player)
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)
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)
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:
yn = color_prommpt("Wanna continus watching?: ")
if yn == "y" or yn == "Y":
return True
elif yn == "n" or yn == "N":
return False
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]: ")
while True:
if retrieve:
retrieve_list(account)
retrieve = False
alist = load_list(account)
choice = iterfzf(iter_list(alist))
if choice:
full_choice = "".join(choice)
title = get_title(full_choice)
episode = get_episode(full_choice)
2021-06-27 21:28:26 +02:00
last_episode = get_all_episodes(full_choice)
2021-06-27 21:58:43 +02:00
score = get_score(full_choice)
2021-06-28 15:10:52 +02:00
watching = True
2021-06-27 16:24:51 +02:00
while True:
2021-06-28 15:10:52 +02:00
action = choose_episode(watching)
2021-06-27 16:24:51 +02:00
if action == "":
next_episode(title, episode, player)
2021-06-28 15:10:52 +02:00
if wanna_continu_watch():
continue
else:
break
2021-06-27 16:24:51 +02:00
elif action == "n" or action == "N":
next_episode(title, episode, player)
2021-06-28 15:10:52 +02:00
if wanna_continu_watch():
continue
else:
break
2021-06-27 16:24:51 +02:00
elif action == "l" or action == "L":
2021-06-27 21:28:26 +02:00
all_from_last(title, episode,last_episode, player)
2021-06-27 16:24:51 +02:00
break
elif action == "a" or action == "A":
2021-06-27 21:28:26 +02:00
all_episodes(title, player)
break
elif action == "i" or action == "I":
custom_episode_range(title, player)
2021-06-28 15:10:52 +02:00
if wanna_continu_watch():
continue
else:
break
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":
next_plus_n(title, episode, player, action)
2021-06-28 15:10:52 +02:00
if wanna_continu_watch():
continue
else:
break
2021-06-27 16:24:51 +02:00
elif action == "r" or action == "R":
2021-06-27 21:28:26 +02:00
rewatch_episode(title, episode, player)
2021-06-28 15:10:52 +02:00
if wanna_continu_watch():
continue
else:
break
2021-06-27 16:24:51 +02:00
elif action == "c" or action == "C":
2021-06-27 21:28:26 +02:00
custom_episode(title, player)
2021-06-28 15:10:52 +02:00
if wanna_continu_watch():
continue
else:
break
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
elif action == "s" or action == "S":
break
else:
exit_ask()