Added linux support, removed addition files, using subprocces correctly now, ...
This commit is contained in:
parent
4933308af4
commit
d155058130
997
adl.py
997
adl.py
@ -1,502 +1,495 @@
|
|||||||
from base64 import encode
|
#! /usr/bin/env python3
|
||||||
import os, subprocess, sys, argparse, signal
|
|
||||||
|
import os, subprocess, sys, argparse, signal
|
||||||
# required files
|
|
||||||
DN = os.path.dirname(os.path.realpath(__file__)) # get current directory of the script
|
# required files
|
||||||
GOOD_TITLES = open(DN + "/good_title.txt", encoding='utf-8').readlines() # the list of good titles
|
CURRENT_DIR = os.getcwd()
|
||||||
PROBLEMATIC_TITLES = open(DN + "/problem_title.txt", encoding='utf-8').readlines() # list of problematic titles
|
|
||||||
FZF_FILE = open(DN + "/fzf.txt", "w+") # temp file for fzf
|
if sys.platform == "win32":
|
||||||
FZF_FILE_PATH = DN +"/fzf.txt" # path of the temp file
|
CONFIG_FILE_PATH = os.path.join('C:\\', 'Users', str(os.getlogin()), 'Documents', 'Adl', 'config.json')
|
||||||
PRINT_FZF_PATH = "python " + DN + "/print_fzf.py" # print the fzf file
|
DEFAULT_DOWNLOAD_LOCATION = os.path.join('C:\\', 'Users', str(os.getlogin()), 'Videos', 'Anime')
|
||||||
CONFIG_FILE_PATH = os.path.join('C:\\', 'Users', str(os.getlogin()), 'Documents', 'Adl', 'config.json')
|
CLEAR = 'cls'
|
||||||
DEFAULT_DOWNLOAD_LOCATION = os.path.join('C:\\', 'Users', str(os.getlogin()), 'Videos', 'Anime')
|
else:
|
||||||
CURRENT_DIR = os.getcwd()
|
CONFIG_FILE_PATH = os.path.join('home', str(os.getlogin()), '.config', 'adl', 'config.json')
|
||||||
|
DEFAULT_DOWNLOAD_LOCATION = os.path.join('home', str(os.getlogin()), 'Videos', 'Anime')
|
||||||
# exit function
|
CLEAR = 'clear'
|
||||||
def exit_adl():
|
|
||||||
FZF_FILE.close()
|
PROBLEMATIC_TITLES = ['Komi-san wa, Komyushou desu ',
|
||||||
os.remove(FZF_FILE_PATH)
|
'SK∞']
|
||||||
sys.exit()
|
GOOD_TITLES = ['Komi-san wa, Komyushou desu.',
|
||||||
|
'SK∞']
|
||||||
def interupt_command(signum, frame):
|
|
||||||
exit_adl()
|
# exit function
|
||||||
|
def exit_adl():
|
||||||
# colored print
|
sys.exit()
|
||||||
def color_print(text):
|
|
||||||
print(f"\033[0;36m{text } \033[0m")
|
#
|
||||||
|
def interupt_command(signum, frame):
|
||||||
# colored watch primpt
|
exit_adl()
|
||||||
def watch_prompt(title, episode, msg):
|
|
||||||
print(f"Now {msg} \033[0;34m{title}\033[0m, episode \033[0;34m{str(episode)} \033[0m")
|
# colored print
|
||||||
|
def color_print(text):
|
||||||
# colored input
|
print(f"\033[0;36m{text } \033[0m")
|
||||||
def color_prommpt(text):
|
|
||||||
return input(f"\033[0;34m{text}\033[0m")
|
# colored watch primpt
|
||||||
|
def watch_prompt(title, episode, msg):
|
||||||
# retrieve new list
|
print(f"Now {msg} \033[0;34m{title}\033[0m, episode \033[0;34m{str(episode)} \033[0m")
|
||||||
def retrieve_list(account):
|
|
||||||
color_print (f"Running trackma retrieve for account {account}...")
|
# colored input
|
||||||
subprocess.call(f"trackma -a {account} retrieve")
|
def color_prommpt(text):
|
||||||
subprocess.call("cls", shell=True)
|
return input(f"\033[0;34m{text}\033[0m")
|
||||||
|
|
||||||
# retrieve updated list
|
# retrieve new list
|
||||||
def retrieve_list_update(account):
|
def retrieve_list(account):
|
||||||
color_print(f"Running trackma retrieve for account {account} to get the updated list...")
|
color_print (f"Running trackma retrieve for account {account}...")
|
||||||
subprocess.call(f"trackma -a {account} retrieve")
|
subprocess.run(["trackma", "-a", account, "retrieve"])
|
||||||
subprocess.call("cls", shell=True)
|
subprocess.run(CLEAR)
|
||||||
|
|
||||||
# load list
|
# retrieve updated list
|
||||||
def load_list(account):
|
def retrieve_list_update(account):
|
||||||
alist = subprocess.getoutput(f"trackma -a {account} list").splitlines()
|
color_print(f"Running trackma retrieve for account {account} to get the updated list...")
|
||||||
alist.pop(0)
|
subprocess.run(["trackma", "-a", account, "retrieve"])
|
||||||
alist.pop()
|
subprocess.run(CLEAR)
|
||||||
return alist
|
|
||||||
|
# load list
|
||||||
# write list to a file
|
def load_list(account):
|
||||||
def list2file(list, file):
|
alist = subprocess.run(["trackma", "-a", account, "list"], stdout=subprocess.PIPE).stdout.decode('utf-8').splitlines()
|
||||||
for line in list:
|
alist.pop(0)
|
||||||
file.write(line)
|
alist = alist[: len(alist) - 3]
|
||||||
if not list.index(line) == len(list) - 1 :
|
alist = "\n".join(alist)
|
||||||
file.write("\n")
|
return alist
|
||||||
|
|
||||||
# exit prompt
|
# exit prompt
|
||||||
def exit_ask():
|
def exit_ask():
|
||||||
while True:
|
while True:
|
||||||
subprocess.call("cls", shell=True)
|
subprocess.run(CLEAR)
|
||||||
choice = color_prommpt("Want to watch another anime? [Y/n]: ")
|
choice = color_prommpt("Want to watch another anime? [Y/n]: ")
|
||||||
if choice == "N" or choice == "n":
|
if choice == "N" or choice == "n":
|
||||||
exit_adl()
|
exit_adl()
|
||||||
elif choice == "Y" or choice == "y" or choice == "":
|
elif choice == "Y" or choice == "y" or choice == "":
|
||||||
return
|
return
|
||||||
|
|
||||||
# check for problematic title
|
# check for problematic title
|
||||||
def check_title(title):
|
def check_title(title):
|
||||||
for problem in PROBLEMATIC_TITLES:
|
for problem in PROBLEMATIC_TITLES:
|
||||||
if problem == title:
|
if problem == title:
|
||||||
title = GOOD_TITLES[PROBLEMATIC_TITLES.index(problem)].encode('utf-8')
|
title = GOOD_TITLES[PROBLEMATIC_TITLES.index(problem)].encode('utf-8')
|
||||||
title = title.decode('utf-8')
|
title = title.decode('utf-8')
|
||||||
return title
|
return title
|
||||||
|
|
||||||
# get chosen anime info
|
# get chosen anime info
|
||||||
def get_info(choice):
|
def get_info(choice):
|
||||||
# get index
|
# get index
|
||||||
index = int(choice[4:7])
|
index = int(choice[4:7])
|
||||||
|
|
||||||
# get title
|
# get title
|
||||||
title = choice[9:-19]
|
title = str(choice[9:-19])
|
||||||
title = title.rstrip(".")
|
title = title.replace('.','')
|
||||||
title = check_title(title)
|
title = check_title(title)
|
||||||
|
|
||||||
# get episode
|
# get episode
|
||||||
episode = int(choice[-19:-15])
|
episode = int(choice[-19:-15])
|
||||||
|
|
||||||
# get score
|
# get score
|
||||||
score = int(choice[-10:-5])
|
score = int(choice[-10:-5])
|
||||||
|
|
||||||
return index, title, episode, score
|
# print(f'/{title}/')
|
||||||
|
# exit_adl()
|
||||||
# watch animes
|
|
||||||
def watch(title, episode, download, provider, download_location):
|
return index, title, episode, score
|
||||||
cmd = f'animdl'
|
|
||||||
|
# watch animes
|
||||||
if download:
|
def watch(title, episode, download, provider, download_location):
|
||||||
cmd += f' download '
|
cmd = ['animdl']
|
||||||
if os.path.isdir(download_location):
|
|
||||||
os.chdir(download_location)
|
if download:
|
||||||
else:
|
cmd.append('download')
|
||||||
os.mkdir(download_location)
|
if os.path.isdir(download_location):
|
||||||
os.chdir(download_location)
|
os.chdir(download_location)
|
||||||
else:
|
else:
|
||||||
cmd += f' stream '
|
os.mkdir(download_location)
|
||||||
|
os.chdir(download_location)
|
||||||
cmd += f'"{provider}:{title}" -r {episode}'
|
else:
|
||||||
|
cmd.append('stream')
|
||||||
subprocess.run(cmd)
|
|
||||||
|
cmd.append(f'"{provider}:{title}"')
|
||||||
if download:
|
cmd.append('-r')
|
||||||
os.chdir(CURRENT_DIR)
|
cmd.append(episode)
|
||||||
|
|
||||||
# next episode
|
subprocess.run(cmd)
|
||||||
def next_episode(title,episode, msg, download, provider, download_location):
|
|
||||||
if not download:
|
if download:
|
||||||
watch_next = True
|
os.chdir(CURRENT_DIR)
|
||||||
while watch_next:
|
|
||||||
episode = episode + 1
|
# next episode
|
||||||
watch_prompt(title, str(episode), msg)
|
def next_episode(title,episode, msg, download, provider, download_location):
|
||||||
watch(title, str(episode), download, provider, download_location)
|
if not download:
|
||||||
while True:
|
watch_next = True
|
||||||
color_print(f"Current watched episode: {str(episode)}")
|
while watch_next:
|
||||||
yn = color_prommpt("Wanna watch next episode? [Y/n]: ")
|
episode = episode + 1
|
||||||
if yn == "Y" or yn == "y" or yn == "":
|
watch_prompt(title, str(episode), msg)
|
||||||
break
|
watch(title, str(episode), download, provider, download_location)
|
||||||
elif yn == "N" or yn == "n":
|
while True:
|
||||||
watch_next = False
|
color_print(f"Current watched episode: {str(episode)}")
|
||||||
break
|
yn = color_prommpt("Wanna watch next episode? [Y/n]: ")
|
||||||
else:
|
if yn == "Y" or yn == "y" or yn == "":
|
||||||
episode = episode + 1
|
break
|
||||||
watch_prompt(title, str(episode), msg)
|
elif yn == "N" or yn == "n":
|
||||||
watch(title, str(episode), download, provider, download_location)
|
watch_next = False
|
||||||
|
break
|
||||||
# all from last watched
|
else:
|
||||||
def all_from_last(title,episode, msg, download, provider, download_location):
|
episode = episode + 1
|
||||||
watch_prompt(title, f"{str(episode)} all left episodes", msg)
|
watch_prompt(title, str(episode), msg)
|
||||||
watch(title, f'{str(episode + 1)}:', download, provider, download_location)
|
watch(title, str(episode), download, provider, download_location)
|
||||||
|
|
||||||
# all episode
|
# all from last watched
|
||||||
def all_episodes(title, msg, download, provider, download_location):
|
def all_from_last(title,episode, msg, download, provider, download_location):
|
||||||
watch_prompt(title, "all", msg)
|
watch_prompt(title, f"{str(episode)} all left episodes", msg)
|
||||||
watch(title, '1:', download, provider, download_location)
|
watch(title, f'{str(episode + 1)}:', download, provider, download_location)
|
||||||
|
|
||||||
# watch from custom range
|
# all episode
|
||||||
def custom_episode_range(title, msg, download, provider, download_location):
|
def all_episodes(title, msg, download, provider, download_location):
|
||||||
begginig = color_prommpt("Beggining of interval?: ")
|
watch_prompt(title, "all", msg)
|
||||||
end = color_prommpt("End of interval?: ")
|
watch(title, '1:', download, provider, download_location)
|
||||||
watch_prompt(title, f"{begginig} to {end}", msg)
|
|
||||||
watch(title, f"{begginig}:{end}", download, provider, download_location)
|
# watch from custom range
|
||||||
|
def custom_episode_range(title, msg, download, provider, download_location):
|
||||||
# add to last watched m
|
begginig = color_prommpt("Beggining of interval?: ")
|
||||||
def next_plus_n(title, episode, action, msg, download, provider, download_location):
|
end = color_prommpt("End of interval?: ")
|
||||||
watch_prompt(title, str(episode + int(action)), msg)
|
watch_prompt(title, f"{begginig} to {end}", msg)
|
||||||
watch(title, str(episode + int(action)), download, provider, download_location)
|
watch(title, f"{begginig}:{end}", download, provider, download_location)
|
||||||
|
|
||||||
# rewatch current episode
|
# add to last watched m
|
||||||
def rewatch_episode(title, episode, msg, download, provider, download_location):
|
def next_plus_n(title, episode, action, msg, download, provider, download_location):
|
||||||
watch_prompt(title, str(episode), msg)
|
watch_prompt(title, str(episode + int(action)), msg)
|
||||||
watch(title, str(episode), download, provider, download_location)
|
watch(title, str(episode + int(action)), download, provider, download_location)
|
||||||
|
|
||||||
# watch custom episode
|
# rewatch current episode
|
||||||
def custom_episode(title, msg, download,provider, download_location):
|
def rewatch_episode(title, episode, msg, download, provider, download_location):
|
||||||
episode = color_prommpt("Enter custom episode: ")
|
watch_prompt(title, str(episode), msg)
|
||||||
watch_prompt(title, episode, msg)
|
watch(title, str(episode), download, provider, download_location)
|
||||||
watch(title, episode, download, provider, download_location)
|
|
||||||
|
# watch custom episode
|
||||||
# update title
|
def custom_episode(title, msg, download,provider, download_location):
|
||||||
def update_title(index, title, episode, account):
|
episode = color_prommpt("Enter custom episode: ")
|
||||||
color_print(f"Current episode for {title} is {str(episode)}")
|
watch_prompt(title, episode, msg)
|
||||||
custom = color_prommpt("Enter updated episode number: ")
|
watch(title, episode, download, provider, download_location)
|
||||||
if custom != "":
|
|
||||||
subprocess.call(f'trackma -a {account} update "{index}" {custom}')
|
# update title
|
||||||
subprocess.call(f'trackma -a {account} send')
|
def update_title(index, title, episode, account):
|
||||||
retrieve_list_update(account)
|
color_print(f"Current episode for {title} is {str(episode)}")
|
||||||
else:
|
custom = color_prommpt("Enter updated episode number: ")
|
||||||
color_print("Skipping updating...")
|
if custom != "":
|
||||||
|
subprocess.run(['trackma', '-a', account, 'update', str(index), custom])
|
||||||
# update score
|
subprocess.run(['trackma', '-a', account, 'send'])
|
||||||
def update_score(index, title, score, account):
|
retrieve_list_update(account)
|
||||||
color_print(f"Current score for {title} is {score}")
|
else:
|
||||||
custom = color_prommpt("Enter updated score: ")
|
color_print("Skipping updating...")
|
||||||
if custom != "":
|
|
||||||
subprocess.call(f'trackma -a {account} score "{index}" {custom}')
|
# update score
|
||||||
subprocess.call(f'trackma -a {account} send')
|
def update_score(index, title, score, account):
|
||||||
retrieve_list_update(account)
|
color_print(f"Current score for {title} is {score}")
|
||||||
else:
|
custom = color_prommpt("Enter updated score: ")
|
||||||
color_print("Skipping updating...")
|
if custom != "":
|
||||||
|
subprocess.run(['trackma', '-a', account, 'score', str(index), custom])
|
||||||
# update question
|
subprocess.run(['trackma', '-a', account, 'send'])
|
||||||
def update_question(index, title, episode, score, account):
|
retrieve_list_update(account)
|
||||||
while True:
|
else:
|
||||||
color_print("Skipping watching episodes. Modifing entry.")
|
color_print("Skipping updating...")
|
||||||
choice = color_prommpt("Update episode number or update score [E/s]: ")
|
|
||||||
if choice == "e" or choice == "E" or choice == "":
|
# update question
|
||||||
update_title(index, title, episode, account)
|
def update_question(index, title, episode, score, account):
|
||||||
break
|
while True:
|
||||||
elif choice == "s" or choice == "S":
|
color_print("Skipping watching episodes. Modifing entry.")
|
||||||
update_score(index, title, score, account)
|
choice = color_prommpt("Update episode number or update score [E/s]: ")
|
||||||
break
|
if choice == "e" or choice == "E" or choice == "":
|
||||||
|
update_title(index, title, episode, account)
|
||||||
# ask if you wanna continus watching
|
break
|
||||||
def wanna_continu_watch(download):
|
elif choice == "s" or choice == "S":
|
||||||
while True:
|
update_score(index, title, score, account)
|
||||||
if not download:
|
break
|
||||||
yn = color_prommpt("Wanna continue watching? [Y/n]: ")
|
|
||||||
else:
|
# ask if you wanna continus watching
|
||||||
yn = color_prommpt("Wanna continue downloading? [Y/n]: ")
|
def wanna_continu_watch(download):
|
||||||
if yn == "y" or yn == "Y" or yn == "":
|
while True:
|
||||||
return True
|
if not download:
|
||||||
elif yn == "n" or yn == "N":
|
yn = color_prommpt("Wanna continue watching? [Y/n]: ")
|
||||||
return False
|
else:
|
||||||
|
yn = color_prommpt("Wanna continue downloading? [Y/n]: ")
|
||||||
# ask if you wanna update title meta after watch
|
if yn == "y" or yn == "Y" or yn == "":
|
||||||
def wanna_update_title_after_watch(index, title, episode, score, download, account):
|
return True
|
||||||
if not download:
|
elif yn == "n" or yn == "N":
|
||||||
while True:
|
return False
|
||||||
yn = color_prommpt("Wanna update episode number or update score of watched anime? [N/e/s]: ")
|
|
||||||
if yn == "E" or yn == "e":
|
# ask if you wanna update title meta after watch
|
||||||
update_title(index, title, episode, account)
|
def wanna_update_title_after_watch(index, title, episode, score, download, account):
|
||||||
break
|
if not download:
|
||||||
elif yn == "S" or yn == "s":
|
while True:
|
||||||
update_score(index, title, score, account)
|
yn = color_prommpt("Wanna update episode number or update score of watched anime? [N/e/s]: ")
|
||||||
break
|
if yn == "E" or yn == "e":
|
||||||
elif yn == "N" or yn == "n" or yn == "":
|
update_title(index, title, episode, account)
|
||||||
break
|
break
|
||||||
|
elif yn == "S" or yn == "s":
|
||||||
# choose what to do with episode
|
update_score(index, title, score, account)
|
||||||
def choose_episode():
|
break
|
||||||
subprocess.call("cls", shell=True)
|
elif yn == "N" or yn == "n" or yn == "":
|
||||||
color_print("Enter lowercase or uppercase to issue command:")
|
break
|
||||||
color_print(" N - Next episode (default, press <ENTER>)")
|
|
||||||
color_print(" L - from current to Last known:")
|
# choose what to do with episode
|
||||||
color_print(" A - All available, from episode 1")
|
def choose_episode():
|
||||||
color_print(" I - custom Interval (range) of episodes")
|
subprocess.run(CLEAR)
|
||||||
color_print(" 0-9 - Plus n episodes relative to last seen (type number)")
|
color_print("Enter lowercase or uppercase to issue command:")
|
||||||
color_print(" R - Rewatch/redownload current episode in list")
|
color_print(" N - Next episode (default, press <ENTER>)")
|
||||||
color_print(" C - Custom episode")
|
color_print(" L - from current to Last known:")
|
||||||
color_print(" U - Update entry chosen instead of streaming")
|
color_print(" A - All available, from episode 1")
|
||||||
color_print(" S - Skip. Choose another show.")
|
color_print(" I - custom Interval (range) of episodes")
|
||||||
return color_prommpt("Your choice? [N/l/a/i/0-9/r/c/u/s]: ")
|
color_print(" 0-9 - Plus n episodes relative to last seen (type number)")
|
||||||
|
color_print(" R - Rewatch/redownload current episode in list")
|
||||||
def choose_episode_specific_show():
|
color_print(" C - Custom episode")
|
||||||
subprocess.call("cls", shell=True)
|
color_print(" U - Update entry chosen instead of streaming")
|
||||||
color_print("Enter lowercase or uppercase to issue command:")
|
color_print(" S - Skip. Choose another show.")
|
||||||
color_print(" A - All available, from episode 1")
|
return color_prommpt("Your choice? [N/l/a/i/0-9/r/c/u/s]: ")
|
||||||
color_print(" I - custom Interval (range) of episodes")
|
|
||||||
color_print(" C - Custom episode")
|
def choose_episode_specific_show():
|
||||||
color_print(" S - Skip. Exit adl.")
|
subprocess.run(CLEAR)
|
||||||
return color_prommpt("Your choice? [A/i/c/s]: ")
|
color_print("Enter lowercase or uppercase to issue command:")
|
||||||
|
color_print(" A - All available, from episode 1")
|
||||||
def argument_and_config_parser():
|
color_print(" I - custom Interval (range) of episodes")
|
||||||
# config
|
color_print(" C - Custom episode")
|
||||||
config = {}
|
color_print(" S - Skip. Exit adl.")
|
||||||
ConfigExists = False
|
return color_prommpt("Your choice? [A/i/c/s]: ")
|
||||||
if os.path.exists(CONFIG_FILE_PATH):
|
|
||||||
config_content = open(CONFIG_FILE_PATH, encoding='utf-8-sig').read()
|
def argument_and_config_parser():
|
||||||
config = eval(config_content)
|
# config
|
||||||
ConfigExists = True
|
config = {}
|
||||||
|
ConfigExists = False
|
||||||
# argument parser
|
if os.path.exists(CONFIG_FILE_PATH):
|
||||||
ap = argparse.ArgumentParser()
|
config_content = open(CONFIG_FILE_PATH, encoding='utf-8-sig').read()
|
||||||
|
config = eval(config_content)
|
||||||
ap.add_argument("-p", "--provider", required=False,
|
ConfigExists = True
|
||||||
help="Define provider used for streaming (check \033[0;36m$anime dl --help\033[0m for providers list)")
|
|
||||||
ap.add_argument("-s", "--show", required=False,
|
# argument parser
|
||||||
help='Watch custom show. Ep nr optional, careful with the quotes. Ex: \033[0;36m$adl -s "gegege 2018"\033[0m')
|
ap = argparse.ArgumentParser()
|
||||||
ap.add_argument("-n", "--number", required=False,
|
|
||||||
help='Specify episode number that will be used with "-s / --show" option. Ex: \033[0;36m$adl -s "gegege 2018" -n "4"\033[0m')
|
ap.add_argument("-p", "--provider", required=False,
|
||||||
ap.add_argument("-a", "--account", required=False,
|
help="Define provider used for streaming (check \033[0;36m$anime dl --help\033[0m for providers list)")
|
||||||
help="By default trackma will use account 1. Use '-a 2' for example to change trackma account")
|
ap.add_argument("-s", "--show", required=False,
|
||||||
ap.add_argument("-d", "--download", required=False, type=bool, nargs='?', const=True, default=False,
|
help='Watch custom show. Ep nr optional, careful with the quotes. Ex: \033[0;36m$adl -s "gegege 2018"\033[0m')
|
||||||
help="Download instead of streaming")
|
ap.add_argument("-n", "--number", required=False,
|
||||||
ap.add_argument("-l", "--download-location", required=False,
|
help='Specify episode number that will be used with "-s / --show" option. Ex: \033[0;36m$adl -s "gegege 2018" -n "4"\033[0m')
|
||||||
help="Define downloads location, Default location is in 'User folder/Videos/Anime'")
|
ap.add_argument("-a", "--account", required=False,
|
||||||
ap.add_argument("-t", "--test-providers", required=False, type=bool, nargs='?', const=True, default=False,
|
help="By default trackma will use account 1. Use '-a 2' for example to change trackma account")
|
||||||
help="Check the state of possible providers")
|
ap.add_argument("-d", "--download", required=False, type=bool, nargs='?', const=True, default=False,
|
||||||
ap.add_argument("-c", "--check-show", required=False,
|
help="Download instead of streaming")
|
||||||
help="Check what provider has that one anime you wan't to watch. Ex: \033[0;36m$adl -c 'gegege 2018' -n \033[0m")
|
ap.add_argument("-l", "--download-location", required=False,
|
||||||
ap.add_argument("-v", "--version", required=False, nargs='?', const=True,
|
help="Define downloads location, Default location is in 'User folder/Videos/Anime'")
|
||||||
help="Display version and exit")
|
ap.add_argument("-t", "--test-providers", required=False, type=bool, nargs='?', const=True, default=False,
|
||||||
|
help="Check the state of possible providers")
|
||||||
args = vars(ap.parse_args())
|
ap.add_argument("-v", "--version", required=False, nargs='?', const=True,
|
||||||
|
help="Display version and exit")
|
||||||
# print the version
|
|
||||||
if args["version"]:
|
args = vars(ap.parse_args())
|
||||||
print("Py-adl version 1.1")
|
|
||||||
sys.exit()
|
# print the version
|
||||||
|
if args["version"]:
|
||||||
# check if providers are working
|
print("Py-adl version 1.1")
|
||||||
if args["test_providers"]:
|
sys.exit()
|
||||||
subprocess.run("anime test")
|
|
||||||
sys.exit()
|
# check if providers are working
|
||||||
|
if args["test_providers"]:
|
||||||
# check if anime exists in any of the providers
|
subprocess.run(["animdl", "test"])
|
||||||
if args["check_show"]:
|
sys.exit()
|
||||||
subprocess.run(f"anime test '{str(args['check_show'])}'")
|
|
||||||
sys.exit()
|
# get provider
|
||||||
|
if args['provider']:
|
||||||
# get provider
|
provider = str(args["provider"])
|
||||||
if args['provider']:
|
elif ConfigExists and 'provider' in config and config['provider']:
|
||||||
provider = str(args["provider"])
|
provider = str(config["provider"])
|
||||||
elif ConfigExists and 'provider' in config and config['provider']:
|
else:
|
||||||
provider = str(config["provider"])
|
provider = "zoro"
|
||||||
else:
|
|
||||||
provider = "zoro"
|
# get show
|
||||||
|
if args['show']:
|
||||||
# get show
|
show = str(args["show"])
|
||||||
if args['show']:
|
else:
|
||||||
show = str(args["show"])
|
show = ""
|
||||||
else:
|
|
||||||
show = ""
|
# get episode
|
||||||
|
if args['number']:
|
||||||
# get episode
|
if args['number'] and args['show']:
|
||||||
if args['number']:
|
episode = int(args['number'])
|
||||||
if args['number'] and args['show']:
|
else:
|
||||||
episode = int(args['number'])
|
print("You need to also specify a show name to use this option")
|
||||||
else:
|
sys.exit()
|
||||||
print("You need to also specify a show name to use this option")
|
else:
|
||||||
sys.exit()
|
episode = 0
|
||||||
else:
|
|
||||||
episode = 0
|
# get account
|
||||||
|
if args['account']:
|
||||||
# get account
|
account = str(int(args["account"]) - 1) # take the account from input
|
||||||
if args['account']:
|
elif ConfigExists and 'account' in config and config["account"]:
|
||||||
account = str(int(args["account"]) - 1) # take the account from input
|
account = str(int(config["account"]) - 1) # take the account from config
|
||||||
elif ConfigExists and 'account' in config and config["account"]:
|
else:
|
||||||
account = str(int(config["account"]) - 1) # take the account from config
|
account = "0" # default account
|
||||||
else:
|
|
||||||
account = "0" # default account
|
# enable downloading
|
||||||
|
if args["download"]:
|
||||||
# enable downloading
|
download = True # enable downloading
|
||||||
if args["download"]:
|
msg = "downloading" # download message
|
||||||
download = True # enable downloading
|
else:
|
||||||
msg = "downloading" # download message
|
download = False # specify whether to download or not
|
||||||
else:
|
msg = "watching" # msg for the watch prompt
|
||||||
download = False # specify whether to download or not
|
|
||||||
msg = "watching" # msg for the watch prompt
|
|
||||||
|
if not download and args["download_location"]:
|
||||||
|
color_print("You need to be downloading to use this option!")
|
||||||
if not download and args["download_location"]:
|
exit_adl()
|
||||||
color_print("You need to be downloading to use this option!")
|
elif download and args["download_location"]:
|
||||||
exit_adl()
|
download_location = str(args["download_location"])
|
||||||
elif download and args["download_location"]:
|
else:
|
||||||
download_location = str(args["download_location"])
|
download_location = DEFAULT_DOWNLOAD_LOCATION
|
||||||
else:
|
|
||||||
download_location = DEFAULT_DOWNLOAD_LOCATION
|
|
||||||
|
return (provider, show, episode, account, download, msg, download_location)
|
||||||
|
|
||||||
return (provider, show, episode, account, download, msg, download_location)
|
def specific_show_loop(show, msg, download, provider, download_location):
|
||||||
|
while True:
|
||||||
def specific_show_loop(show, msg, download, provider, download_location):
|
# choose what to do with the choosen anime
|
||||||
while True:
|
action = choose_episode_specific_show()
|
||||||
# choose what to do with the choosen anime
|
if action == "a" or action == "A" or action == "":
|
||||||
action = choose_episode_specific_show()
|
all_episodes(show, msg, download, provider, download_location)
|
||||||
if action == "a" or action == "A" or action == "":
|
exit_adl()
|
||||||
all_episodes(show, msg, download, provider, download_location)
|
# custom range of episodes
|
||||||
exit_adl()
|
elif action == "i" or action == "I":
|
||||||
# custom range of episodes
|
custom_episode_range(show, msg, download, provider, download_location)
|
||||||
elif action == "i" or action == "I":
|
if wanna_continu_watch(download):
|
||||||
custom_episode_range(show, msg, download, provider, download_location)
|
continue
|
||||||
if wanna_continu_watch(download):
|
else:
|
||||||
continue
|
exit_adl()
|
||||||
else:
|
# watch custom episode
|
||||||
exit_adl()
|
elif action == "c" or action == "C":
|
||||||
# watch custom episode
|
custom_episode(show, msg, download, provider, download_location)
|
||||||
elif action == "c" or action == "C":
|
if wanna_continu_watch(download):
|
||||||
custom_episode(show, msg, download, provider, download_location)
|
continue
|
||||||
if wanna_continu_watch(download):
|
else:
|
||||||
continue
|
exit_adl()
|
||||||
else:
|
# skip the anime
|
||||||
exit_adl()
|
elif action == "s" or action == "S":
|
||||||
# skip the anime
|
exit_adl()
|
||||||
elif action == "s" or action == "S":
|
|
||||||
exit_adl()
|
def main_loop(retrieve, account, msg, download,provider, download_location):
|
||||||
|
# main loop
|
||||||
def main_loop(retrieve, account, msg, download,provider, download_location):
|
while True:
|
||||||
# main loop
|
# retrieving the list on start
|
||||||
while True:
|
if retrieve:
|
||||||
# retrieving the list on start
|
retrieve_list(account)
|
||||||
if retrieve:
|
retrieve = False
|
||||||
retrieve_list(account)
|
|
||||||
retrieve = False
|
# get the list of anime
|
||||||
|
alist = load_list(account)
|
||||||
# get the list of anime
|
|
||||||
alist = load_list(account)
|
# get choice from fzf
|
||||||
|
choice = subprocess.run(["fzf", "--ansi", "--unicode", "--reverse", "--prompt", "Choose anime to watch: "], input=alist, stdout=subprocess.PIPE, encoding='utf-8').stdout
|
||||||
# write list to file
|
|
||||||
list2file(alist, FZF_FILE)
|
if choice:
|
||||||
|
# get needed info
|
||||||
# reload file (I Guess ??)
|
index, title, episode, score = get_info(choice)
|
||||||
FZF_FILE.seek(0)
|
|
||||||
|
# the watch loop
|
||||||
# get choice from fzf
|
while True:
|
||||||
choice = subprocess.getoutput(f'{PRINT_FZF_PATH} | fzf --ansi --unicode --reverse --prompt "Choose anime to watch: "')
|
# choose what to do with the choosen anime
|
||||||
|
action = choose_episode()
|
||||||
if choice:
|
# watch next episode
|
||||||
# get needed info
|
if action == "n" or action == "N" or action == "":
|
||||||
index, title, episode, score = get_info(choice)
|
next_episode(title, episode, msg, download,provider, download_location)
|
||||||
|
wanna_update_title_after_watch(index, title, episode, score, download, account)
|
||||||
# the watch loop
|
exit_ask()
|
||||||
while True:
|
break
|
||||||
# choose what to do with the choosen anime
|
# watch all left episodes
|
||||||
action = choose_episode()
|
elif action == "l" or action == "L":
|
||||||
# watch next episode
|
all_from_last(title, episode, msg, download,provider, download_location)
|
||||||
if action == "n" or action == "N" or action == "":
|
wanna_update_title_after_watch(index, title, episode, score, download, account)
|
||||||
next_episode(title, episode, msg, download,provider, download_location)
|
exit_ask()
|
||||||
wanna_update_title_after_watch(index, title, episode, score, download, account)
|
break
|
||||||
exit_ask()
|
# watch every episode available
|
||||||
break
|
elif action == "a" or action == "A":
|
||||||
# watch all left episodes
|
all_episodes(title, msg, download,provider, download_location)
|
||||||
elif action == "l" or action == "L":
|
wanna_update_title_after_watch(index, title, episode, score, download, account)
|
||||||
all_from_last(title, episode, msg, download,provider, download_location)
|
exit_ask()
|
||||||
wanna_update_title_after_watch(index, title, episode, score, download, account)
|
break
|
||||||
exit_ask()
|
# custom range of episodes
|
||||||
break
|
elif action == "i" or action == "I":
|
||||||
# watch every episode available
|
custom_episode_range(title, msg, download,provider, download_location)
|
||||||
elif action == "a" or action == "A":
|
if wanna_continu_watch(download):
|
||||||
all_episodes(title, msg, download,provider, download_location)
|
continue
|
||||||
wanna_update_title_after_watch(index, title, episode, score, download, account)
|
else:
|
||||||
exit_ask()
|
wanna_update_title_after_watch(index, title, episode, score, download, account)
|
||||||
break
|
exit_ask()
|
||||||
# custom range of episodes
|
break
|
||||||
elif action == "i" or action == "I":
|
# something?
|
||||||
custom_episode_range(title, msg, download,provider, download_location)
|
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":
|
||||||
if wanna_continu_watch(download):
|
next_plus_n(title, episode, action, msg, download,provider, download_location)
|
||||||
continue
|
if wanna_continu_watch(download):
|
||||||
else:
|
continue
|
||||||
wanna_update_title_after_watch(index, title, episode, score, download, account)
|
else:
|
||||||
exit_ask()
|
wanna_update_title_after_watch(index, title, episode, score, download, account)
|
||||||
break
|
exit_ask()
|
||||||
# something?
|
break
|
||||||
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":
|
# rewatch current episode
|
||||||
next_plus_n(title, episode, action, msg, download,provider, download_location)
|
elif action == "r" or action == "R":
|
||||||
if wanna_continu_watch(download):
|
rewatch_episode(title, episode, msg, download,provider, download_location)
|
||||||
continue
|
if wanna_continu_watch(download):
|
||||||
else:
|
continue
|
||||||
wanna_update_title_after_watch(index, title, episode, score, download, account)
|
else:
|
||||||
exit_ask()
|
wanna_update_title_after_watch(index, title, episode, score, download, account)
|
||||||
break
|
exit_ask()
|
||||||
# rewatch current episode
|
break
|
||||||
elif action == "r" or action == "R":
|
# watch custom episode
|
||||||
rewatch_episode(title, episode, msg, download,provider, download_location)
|
elif action == "c" or action == "C":
|
||||||
if wanna_continu_watch(download):
|
custom_episode(title, msg, download,provider, download_location)
|
||||||
continue
|
if wanna_continu_watch(download):
|
||||||
else:
|
continue
|
||||||
wanna_update_title_after_watch(index, title, episode, score, download, account)
|
else:
|
||||||
exit_ask()
|
wanna_update_title_after_watch(index, title, episode, score, download, account)
|
||||||
break
|
exit_ask()
|
||||||
# watch custom episode
|
break
|
||||||
elif action == "c" or action == "C":
|
# update anime meta
|
||||||
custom_episode(title, msg, download,provider, download_location)
|
elif action == "u" or action == "U":
|
||||||
if wanna_continu_watch(download):
|
update_question(index, title, episode, score, account)
|
||||||
continue
|
exit_ask()
|
||||||
else:
|
break
|
||||||
wanna_update_title_after_watch(index, title, episode, score, download, account)
|
# skip the anime
|
||||||
exit_ask()
|
elif action == "s" or action == "S":
|
||||||
break
|
break
|
||||||
# update anime meta
|
else:
|
||||||
elif action == "u" or action == "U":
|
exit_ask()
|
||||||
update_question(index, title, episode, score, account)
|
|
||||||
exit_ask()
|
|
||||||
break
|
def main():
|
||||||
# skip the anime
|
signal.signal(signal.SIGINT, interupt_command)
|
||||||
elif action == "s" or action == "S":
|
# print("Inside")
|
||||||
break
|
|
||||||
else:
|
# setup env variables for better readability of outputs
|
||||||
exit_ask()
|
os.environ['LINES'] = '25'
|
||||||
|
os.environ['COLUMNS'] = '120'
|
||||||
|
os.environ['PYTHONIOENCODING'] = 'utf-8'
|
||||||
def main():
|
# get argument and config parameters
|
||||||
signal.signal(signal.SIGINT, interupt_command)
|
(provider, show, episode, account, download, msg, download_location) = argument_and_config_parser()
|
||||||
|
|
||||||
# setup env variables for better readability of outputs
|
# retrieve the trackma list on run
|
||||||
os.environ['LINES'] = '25'
|
retrieve = True
|
||||||
os.environ['COLUMNS'] = '120'
|
|
||||||
os.environ['PYTHONIOENCODING'] = 'utf-8'
|
if not show == "" and not episode == 0:
|
||||||
# get argument and config parameters
|
# watching just a specific show and episode only
|
||||||
(provider, show, episode, account, download, msg, download_location) = argument_and_config_parser()
|
watch(show, str(episode), download, provider, download_location)
|
||||||
|
elif not show == "":
|
||||||
# retrieve the trackma list on run
|
# choose want to do with a specific show
|
||||||
retrieve = True
|
specific_show_loop(show, msg, download, provider, download_location)
|
||||||
|
else:
|
||||||
if not show == "" and not episode == 0:
|
# main loop that connets with your list with trackma
|
||||||
# watching just a specific show and episode only
|
main_loop(retrieve, account, msg, download,provider, download_location)
|
||||||
watch(show, str(episode), download, provider, download_location)
|
exit_adl()
|
||||||
elif not show == "":
|
|
||||||
# choose want to do with a specific show
|
# run only if runned directly
|
||||||
specific_show_loop(show, msg, download, provider, download_location)
|
if __name__ == "__main__" :
|
||||||
else:
|
main()
|
||||||
# main loop that connets with your list with trackma
|
|
||||||
main_loop(retrieve, account, msg, download,provider, download_location)
|
|
||||||
exit_adl()
|
|
||||||
|
|
||||||
# run only if runned directly
|
|
||||||
if __name__ == "__main__" :
|
|
||||||
main()
|
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
Komi-san wa, Komyushou desu.
|
|
||||||
SK∞
|
|
@ -1,9 +0,0 @@
|
|||||||
import os,sys
|
|
||||||
#just a quick script to print the fzf.txt file content
|
|
||||||
|
|
||||||
dn = os.path.dirname(os.path.realpath(__file__))
|
|
||||||
fzf_file = open(dn + "/fzf.txt", encoding="utf-8").read()
|
|
||||||
fzf_file = fzf_file.replace("[0;34m", "[0;33m")
|
|
||||||
fzf_file = fzf_file.replace('[0m', '[0m')
|
|
||||||
print(fzf_file)
|
|
||||||
sys.exit()
|
|
@ -1,2 +0,0 @@
|
|||||||
Komi-san wa, Komyushou desu
|
|
||||||
SK∞
|
|
Loading…
Reference in New Issue
Block a user