Basic animdl stream and download functionality.
This commit is contained in:
parent
8a4586f4de
commit
16855e8eb6
113
adl.py
113
adl.py
@ -8,6 +8,8 @@ FZF_FILE = open(DN + "/fzf.txt", "w+") # temp file for fzf
|
|||||||
FZF_FILE_PATH = DN +"/fzf.txt" # path of the temp file
|
FZF_FILE_PATH = DN +"/fzf.txt" # path of the temp file
|
||||||
PRINT_FZF_PATH = "python " + DN + "/print_fzf.py" # print the fzf file
|
PRINT_FZF_PATH = "python " + DN + "/print_fzf.py" # print the fzf file
|
||||||
CONFIG_FILE_PATH = os.path.join('C:\\', 'Users', str(os.getlogin()), 'Documents', 'Adl', 'config.json')
|
CONFIG_FILE_PATH = os.path.join('C:\\', 'Users', str(os.getlogin()), 'Documents', 'Adl', 'config.json')
|
||||||
|
DEFAULT_DOWNLOAD_LOCATION = os.path.join('C:\\', 'Users', str(os.getlogin()), 'Videos', 'Anime')
|
||||||
|
CURRENT_DIR = os.getcwd()
|
||||||
|
|
||||||
# exit function
|
# exit function
|
||||||
def exit_adl():
|
def exit_adl():
|
||||||
@ -91,25 +93,34 @@ def get_score(choice):
|
|||||||
return choice
|
return choice
|
||||||
|
|
||||||
# watch animes
|
# watch animes
|
||||||
def watch(title, episode, download, provider, player):
|
def watch(title, episode, download, provider, download_location):
|
||||||
cmd = f'anime dl "{title}" --episodes {episode}'
|
cmd = f'animdl'
|
||||||
|
|
||||||
if not download:
|
if download:
|
||||||
cmd += f' --play {player}'
|
cmd += f' download '
|
||||||
|
if os.path.isdir(download_location):
|
||||||
|
os.chdir(download_location)
|
||||||
|
else:
|
||||||
|
os.mkdir(download_location)
|
||||||
|
os.chdir(download_location)
|
||||||
|
else:
|
||||||
|
cmd += f' stream '
|
||||||
|
|
||||||
if not provider == "":
|
cmd += f'"{provider}:{title}" -r {episode}'
|
||||||
cmd += f' --provider {provider}'
|
|
||||||
|
|
||||||
subprocess.run(cmd)
|
subprocess.run(cmd)
|
||||||
|
|
||||||
|
if download:
|
||||||
|
os.chdir(CURRENT_DIR)
|
||||||
|
|
||||||
# next episode
|
# next episode
|
||||||
def next_episode(title,episode, msg, download, provider, player):
|
def next_episode(title,episode, msg, download, provider, download_location):
|
||||||
if not download:
|
if not download:
|
||||||
watch_next = True
|
watch_next = True
|
||||||
while watch_next:
|
while watch_next:
|
||||||
episode = episode + 1
|
episode = episode + 1
|
||||||
watch_prompt(title, str(episode), msg)
|
watch_prompt(title, str(episode), msg)
|
||||||
watch(title, str(episode), download, provider, player)
|
watch(title, str(episode), download, provider, download_location)
|
||||||
while True:
|
while True:
|
||||||
color_print(f"Current watched episode: {str(episode)}")
|
color_print(f"Current watched episode: {str(episode)}")
|
||||||
yn = color_prommpt("Wanna watch next episode? [Y/n]: ")
|
yn = color_prommpt("Wanna watch next episode? [Y/n]: ")
|
||||||
@ -121,40 +132,40 @@ def next_episode(title,episode, msg, download, provider, player):
|
|||||||
else:
|
else:
|
||||||
episode = episode + 1
|
episode = episode + 1
|
||||||
watch_prompt(title, str(episode), msg)
|
watch_prompt(title, str(episode), msg)
|
||||||
watch(title, str(episode), download, provider, player)
|
watch(title, str(episode), download, provider, download_location)
|
||||||
|
|
||||||
# all from last watched
|
# all from last watched
|
||||||
def all_from_last(title,episode, msg, download, provider, player):
|
def all_from_last(title,episode, msg, download, provider, download_location):
|
||||||
watch_prompt(title, f"{str(episode)} all left episodes", msg)
|
watch_prompt(title, f"{str(episode)} all left episodes", msg)
|
||||||
watch(title, f'{str(episode + 1)}:', download, provider, player)
|
watch(title, f'{str(episode + 1)}:', download, provider, download_location)
|
||||||
|
|
||||||
# all episode
|
# all episode
|
||||||
def all_episodes(title, msg, download, provider, player):
|
def all_episodes(title, msg, download, provider, download_location):
|
||||||
watch_prompt(title, "all", msg)
|
watch_prompt(title, "all", msg)
|
||||||
watch(title, '1:', download, provider, player)
|
watch(title, '1:', download, provider, download_location)
|
||||||
|
|
||||||
# watch from custom range
|
# watch from custom range
|
||||||
def custom_episode_range(title, msg, download, provider, player):
|
def custom_episode_range(title, msg, download, provider, download_location):
|
||||||
begginig = color_prommpt("Beggining of interval?: ")
|
begginig = color_prommpt("Beggining of interval?: ")
|
||||||
end = color_prommpt("End of interval?: ")
|
end = color_prommpt("End of interval?: ")
|
||||||
watch_prompt(title, f"{begginig} to {end}", msg)
|
watch_prompt(title, f"{begginig} to {end}", msg)
|
||||||
watch(title, f"{begginig}:{end}", download, provider, player)
|
watch(title, f"{begginig}:{end}", download, provider, download_location)
|
||||||
|
|
||||||
# add to last watched m
|
# add to last watched m
|
||||||
def next_plus_n(title, episode, action, msg, download, provider, player):
|
def next_plus_n(title, episode, action, msg, download, provider, download_location):
|
||||||
watch_prompt(title, str(episode + int(action)), msg)
|
watch_prompt(title, str(episode + int(action)), msg)
|
||||||
watch(title, str(episode + int(action)), download, provider, player)
|
watch(title, str(episode + int(action)), download, provider, download_location)
|
||||||
|
|
||||||
# rewatch current episode
|
# rewatch current episode
|
||||||
def rewatch_episode(title, episode, msg, download, provider, player):
|
def rewatch_episode(title, episode, msg, download, provider, download_location):
|
||||||
watch_prompt(title, str(episode), msg)
|
watch_prompt(title, str(episode), msg)
|
||||||
watch(title, str(episode), download, provider, player)
|
watch(title, str(episode), download, provider, download_location)
|
||||||
|
|
||||||
# watch custom episode
|
# watch custom episode
|
||||||
def custom_episode(title, msg, download,provider, player):
|
def custom_episode(title, msg, download,provider, download_location):
|
||||||
episode = color_prommpt("Enter custom episode: ")
|
episode = color_prommpt("Enter custom episode: ")
|
||||||
watch_prompt(title, episode, msg)
|
watch_prompt(title, episode, msg)
|
||||||
watch(title, episode, download, provider, player)
|
watch(title, episode, download, provider, download_location)
|
||||||
|
|
||||||
# update title
|
# update title
|
||||||
def update_title(title, episode, account):
|
def update_title(title, episode, account):
|
||||||
@ -252,9 +263,7 @@ def argument_and_config_parser():
|
|||||||
# argument parser
|
# argument parser
|
||||||
ap = argparse.ArgumentParser()
|
ap = argparse.ArgumentParser()
|
||||||
|
|
||||||
ap.add_argument("-p", "--player", required=False,
|
ap.add_argument("-p", "--provider", required=False,
|
||||||
help="Define player used for streaming. Ex: \033[0;36mpyadl -p mpv\033[0m")
|
|
||||||
ap.add_argument("-i", "--provider", required=False,
|
|
||||||
help="Define provider used for streaming (check \033[0;36m$anime dl --help\033[0m for providers list)")
|
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,
|
ap.add_argument("-s", "--show", required=False,
|
||||||
help='Watch custom show. Ep nr optional, careful with the quotes. Ex: \033[0;36m$adl -s "gegege 2018"\033[0m')
|
help='Watch custom show. Ep nr optional, careful with the quotes. Ex: \033[0;36m$adl -s "gegege 2018"\033[0m')
|
||||||
@ -264,6 +273,8 @@ def argument_and_config_parser():
|
|||||||
help="By default trackma will use account 1. Use '-a 2' for example to change trackma account")
|
help="By default trackma will use account 1. Use '-a 2' for example to change trackma account")
|
||||||
ap.add_argument("-d", "--download", required=False, type=bool, nargs='?', const=True, default=False,
|
ap.add_argument("-d", "--download", required=False, type=bool, nargs='?', const=True, default=False,
|
||||||
help="Download instead of streaming")
|
help="Download instead of streaming")
|
||||||
|
ap.add_argument("-l", "--download-location", required=False,
|
||||||
|
help="Define downloads location, Default location is in 'User folder/Videos/Anime'")
|
||||||
ap.add_argument("-t", "--test-providers", required=False, type=bool, nargs='?', const=True, default=False,
|
ap.add_argument("-t", "--test-providers", required=False, type=bool, nargs='?', const=True, default=False,
|
||||||
help="Check the state of possible providers")
|
help="Check the state of possible providers")
|
||||||
ap.add_argument("-c", "--check-show", required=False,
|
ap.add_argument("-c", "--check-show", required=False,
|
||||||
@ -288,21 +299,13 @@ def argument_and_config_parser():
|
|||||||
subprocess.run(f"anime test '{str(args['check_show'])}'")
|
subprocess.run(f"anime test '{str(args['check_show'])}'")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
# get player
|
|
||||||
if args["player"]:
|
|
||||||
player = str(args["player"]) # get player from user
|
|
||||||
elif ConfigExists and 'player' in config and config["player"]:
|
|
||||||
player = str(config["player"]) # get player from config
|
|
||||||
else:
|
|
||||||
player = "mpv" # default player
|
|
||||||
|
|
||||||
# get provider
|
# get provider
|
||||||
if args['provider']:
|
if args['provider']:
|
||||||
provider = str(args["provider"])
|
provider = str(args["provider"])
|
||||||
elif ConfigExists and 'provider' in config and config['provider']:
|
elif ConfigExists and 'provider' in config and config['provider']:
|
||||||
provider = str(config["provider"])
|
provider = str(config["provider"])
|
||||||
else:
|
else:
|
||||||
provider = ""
|
provider = "zoro"
|
||||||
|
|
||||||
# get show
|
# get show
|
||||||
if args['show']:
|
if args['show']:
|
||||||
@ -336,25 +339,35 @@ def argument_and_config_parser():
|
|||||||
download = False # specify whether to download or not
|
download = False # specify whether to download or not
|
||||||
msg = "watching" # msg for the watch prompt
|
msg = "watching" # msg for the watch prompt
|
||||||
|
|
||||||
return (player, provider, show, episode, account, download, msg)
|
|
||||||
|
|
||||||
def specific_show_loop(show, msg, download, provider, player):
|
if not download and args["download_location"]:
|
||||||
|
color_print("You need to be downloading to use this option!")
|
||||||
|
exit_adl()
|
||||||
|
elif download and args["download_location"]:
|
||||||
|
download_location = str(args["download_location"])
|
||||||
|
else:
|
||||||
|
download_location = DEFAULT_DOWNLOAD_LOCATION
|
||||||
|
|
||||||
|
|
||||||
|
return (provider, show, episode, account, download, msg, download_location)
|
||||||
|
|
||||||
|
def specific_show_loop(show, msg, download, provider, download_location):
|
||||||
while True:
|
while True:
|
||||||
# choose what to do with the choosen anime
|
# choose what to do with the choosen anime
|
||||||
action = choose_episode_specific_show()
|
action = choose_episode_specific_show()
|
||||||
if action == "a" or action == "A" or action == "":
|
if action == "a" or action == "A" or action == "":
|
||||||
all_episodes(show, msg, download, provider, player)
|
all_episodes(show, msg, download, provider, download_location)
|
||||||
exit_adl()
|
exit_adl()
|
||||||
# custom range of episodes
|
# custom range of episodes
|
||||||
elif action == "i" or action == "I":
|
elif action == "i" or action == "I":
|
||||||
custom_episode_range(show, msg, download, provider, player)
|
custom_episode_range(show, msg, download, provider, download_location)
|
||||||
if wanna_continu_watch(download):
|
if wanna_continu_watch(download):
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
exit_adl()
|
exit_adl()
|
||||||
# watch custom episode
|
# watch custom episode
|
||||||
elif action == "c" or action == "C":
|
elif action == "c" or action == "C":
|
||||||
custom_episode(show, msg, download, provider, player)
|
custom_episode(show, msg, download, provider, download_location)
|
||||||
if wanna_continu_watch(download):
|
if wanna_continu_watch(download):
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
@ -363,7 +376,7 @@ def specific_show_loop(show, msg, download, provider, player):
|
|||||||
elif action == "s" or action == "S":
|
elif action == "s" or action == "S":
|
||||||
exit_adl()
|
exit_adl()
|
||||||
|
|
||||||
def main_loop(retrieve, account, msg, download,provider,player):
|
def main_loop(retrieve, account, msg, download,provider, download_location):
|
||||||
# main loop
|
# main loop
|
||||||
while True:
|
while True:
|
||||||
# retrieving the list on start
|
# retrieving the list on start
|
||||||
@ -397,25 +410,25 @@ def main_loop(retrieve, account, msg, download,provider,player):
|
|||||||
action = choose_episode()
|
action = choose_episode()
|
||||||
# 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,player)
|
next_episode(title, episode, msg, download,provider, download_location)
|
||||||
wanna_update_title_after_watch(title, episode, score, download, account)
|
wanna_update_title_after_watch(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,player)
|
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(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,player)
|
all_episodes(title, msg, download,provider, download_location)
|
||||||
wanna_update_title_after_watch(title, episode, score, download, account)
|
wanna_update_title_after_watch(title, episode, score, download, account)
|
||||||
exit_ask()
|
exit_ask()
|
||||||
break
|
break
|
||||||
# custom range of episodes
|
# custom range of episodes
|
||||||
elif action == "i" or action == "I":
|
elif action == "i" or action == "I":
|
||||||
custom_episode_range(title, msg, download,provider,player)
|
custom_episode_range(title, msg, download,provider, download_location)
|
||||||
if wanna_continu_watch(download):
|
if wanna_continu_watch(download):
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
@ -424,7 +437,7 @@ def main_loop(retrieve, account, msg, download,provider,player):
|
|||||||
break
|
break
|
||||||
# something?
|
# something?
|
||||||
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":
|
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, action, msg, download,provider,player)
|
next_plus_n(title, episode, action, msg, download,provider, download_location)
|
||||||
if wanna_continu_watch(download):
|
if wanna_continu_watch(download):
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
@ -433,7 +446,7 @@ def main_loop(retrieve, account, msg, download,provider,player):
|
|||||||
break
|
break
|
||||||
# rewatch current episode
|
# rewatch current episode
|
||||||
elif action == "r" or action == "R":
|
elif action == "r" or action == "R":
|
||||||
rewatch_episode(title, episode, msg, download,provider,player)
|
rewatch_episode(title, episode, msg, download,provider, download_location)
|
||||||
if wanna_continu_watch(download):
|
if wanna_continu_watch(download):
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
@ -442,7 +455,7 @@ def main_loop(retrieve, account, msg, download,provider,player):
|
|||||||
break
|
break
|
||||||
# watch custom episode
|
# watch custom episode
|
||||||
elif action == "c" or action == "C":
|
elif action == "c" or action == "C":
|
||||||
custom_episode(title, msg, download,provider,player)
|
custom_episode(title, msg, download,provider, download_location)
|
||||||
if wanna_continu_watch(download):
|
if wanna_continu_watch(download):
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
@ -469,20 +482,20 @@ def main():
|
|||||||
os.environ['COLUMNS'] = '120'
|
os.environ['COLUMNS'] = '120'
|
||||||
|
|
||||||
# get argument and config parameters
|
# get argument and config parameters
|
||||||
(player, provider, show, episode, account, download, msg) = argument_and_config_parser()
|
(provider, show, episode, account, download, msg, download_location) = argument_and_config_parser()
|
||||||
|
|
||||||
# retrieve the trackma list on run
|
# retrieve the trackma list on run
|
||||||
retrieve = True
|
retrieve = True
|
||||||
|
|
||||||
if not show == "" and not episode == 0:
|
if not show == "" and not episode == 0:
|
||||||
# watching just a specific show and episode only
|
# watching just a specific show and episode only
|
||||||
watch(show, str(episode), download, provider, player)
|
watch(show, str(episode), download, provider, download_location)
|
||||||
elif not show == "":
|
elif not show == "":
|
||||||
# choose want to do with a specific show
|
# choose want to do with a specific show
|
||||||
specific_show_loop(show, msg, download, provider, player)
|
specific_show_loop(show, msg, download, provider, download_location)
|
||||||
else:
|
else:
|
||||||
# main loop that connets with your list with trackma
|
# main loop that connets with your list with trackma
|
||||||
main_loop(retrieve, account, msg, download,provider,player)
|
main_loop(retrieve, account, msg, download,provider, download_location)
|
||||||
exit_adl()
|
exit_adl()
|
||||||
|
|
||||||
# run only if runned directly
|
# run only if runned directly
|
||||||
|
Loading…
Reference in New Issue
Block a user