Commit f9068c9ca4

f9068c9ca4aa04315cee06aa4534ccade22c902b

parent: e5ab07670e

Unsigned

Wraient <wraient.911@gmail.com> · 2024-09-22 02:46 UTC

sub or dub chooser complete

Layout: unified · split

curd.py +27 −15
@@ -20,7 +20,6 @@ from start_video import start_video, send_command, get_percentage_watched, perce
2020from select_anime import load_anime_data
2121from select_anime import extract_anime_info
2222from select_anime import select_anime
23
2423from track_anime import add_anime, update_anime, get_all_anime, delete_anime, find_anime
2524
2625mark_episode_as_completed_at = 85
@@ -55,7 +54,7 @@ def read_tmp(tmp_filename:str):
5554 return ""
5655 except:
5756 return False
58
57
5958def download_anilist_data(access_token, user_id):
6059 ''' dowlnoad anilist user data'''
6160 # print("downloading user data")
@@ -175,10 +174,13 @@ if not os.path.exists("./scripts/tmp/"):
175174 pass
176175
177176access_token = os.environ.get('ANILIST_ACCESS_TOKEN')
177rewatching = False
178178
179179parser = argparse.ArgumentParser(description="Print a greeting message.")
180180# parser.add_argument("--name", type=str, required=True, help="Your name")
181181parser.add_argument("-new", action='store_true', help="Add new anime to watching (optional)")
182parser.add_argument("-sub", action='store_true', help="Anime audio type (optional)")
183parser.add_argument("-dub", action='store_true', help="Anime audio type (optional)")
182184args = parser.parse_args()
183185
184186if args.new:
@@ -239,6 +241,16 @@ except:
239241 print("Please select anime")
240242 select_anime(anime_dict)
241243
244if get_userconfig_value(user_config, "sub_or_dub")=="sub":
245 write_to_tmp("mode", "sub")
246elif get_userconfig_value(user_config, "sub_or_dub")=="dub":
247 write_to_tmp("mode", "dub")
248
249if args.sub: # arguments take precidence
250 write_to_tmp("mode", "sub")
251if args.dub:
252 write_to_tmp("mode", "dub")
253
242254run_script("episode_list")
243255
244256binge_watching = False
@@ -247,22 +259,22 @@ last_episode = int(read_tmp("episode_list").split()[-1])
247259anime_watch_history = get_all_anime(get_userconfig_value(user_config, 'history_file'))
248260anime_history = find_anime(anime_watch_history, anilist_id=media_id, allanime_id=get_contents_of("id"))
249261episode_completed = False
250rewatching = False
251262
252263if anime_history: # if it exists in local history
253264 # print(f"came in history {str(progress)}")
254 if int(anime_history['episode']) != progress+1: # if the upstream progress is ahead
255 write_to_tmp("ep_no", str(int(progress)+1))
256 # print(f"Starting anime from upstream {str(progress + 1)}")
257 watching_ep = progress + 1
258
259 elif int(anime_history['episode']) == int(progress)+1: # if the upstream progress is NOT ahead
265 if progress == last_episode or int(anime_history['episode']) == int(progress)+1:
266 # print(anime_history['episode'])
267 if progress == last_episode:
268 rewatching = True
260269 mpv_args.append(f"--start={anime_history['time']}")
261 write_to_tmp("ep_no", anime_history['episode'])
262 # print(f"STARTING ANIME FROM EPISODE {anime_history['episode']} {anime_history['time']}")
263
264270 watching_ep = int(anime_history['episode'])
265else: # if there is no history
271 write_to_tmp("ep_no", str(watching_ep))
272 # print(f"STARTING ANIME FROM EPISODE {anime_history['episode']} {anime_history['time']}")
273 elif int(anime_history['episode']) < progress+1: # if the upstream progress is ahead
274 write_to_tmp("ep_no", str(int(progress)+1))
275 print(f"Starting anime from upstream {str(progress + 1)}")
276 watching_ep = progress + 1
277else: # if history does not exist
266278 if progress == last_episode:
267279 user_input = input("Do you want to start this anime from beginning? (y/n):")
268280 if user_input.lower() == "yes" or user_input.lower() == "y" or user_input.lower() == "":
@@ -271,8 +283,8 @@ else: # if there is no history
271283 else:
272284 print("Starting last episode of anime")
273285 progress = last_episode - 1
274 watching_ep = int(progress)+1
275 write_to_tmp("ep_no", str(watching_ep))
286 watching_ep = int(progress)+1
287 write_to_tmp("ep_no", str(watching_ep))
276288
277289# os.system("./scripts/episode_url.sh")
278290run_script("episode_url")
scripts/episode_url.sh +2 −1
@@ -84,7 +84,8 @@ agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefo
8484allanime_refr="https://allanime.to"
8585allanime_base="allanime.day"
8686allanime_api="https://api.${allanime_base}"
87mode="${ANI_CLI_MODE:-sub}"
87sub_or_dub=$(cat ./scripts/tmp/mode)
88mode="${ANI_CLI_MODE:-$sub_or_dub}"
8889download_dir="${ANI_CLI_DOWNLOAD_DIR:-.}"
8990quality="${ANI_CLI_QUALITY:-best}"
9091case "$(uname -a)" in