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
20from select_anime import load_anime_data 20from select_anime import load_anime_data
21from select_anime import extract_anime_info 21from select_anime import extract_anime_info
22from select_anime import select_anime 22from select_anime import select_anime
23
24from track_anime import add_anime, update_anime, get_all_anime, delete_anime, find_anime 23from track_anime import add_anime, update_anime, get_all_anime, delete_anime, find_anime
25 24
26mark_episode_as_completed_at = 85 25mark_episode_as_completed_at = 85
@@ -55,7 +54,7 @@ def read_tmp(tmp_filename:str):
55 return "" 54 return ""
56 except: 55 except:
57 return False 56 return False
58 57
59def download_anilist_data(access_token, user_id): 58def download_anilist_data(access_token, user_id):
60 ''' dowlnoad anilist user data''' 59 ''' dowlnoad anilist user data'''
61 # print("downloading user data") 60 # print("downloading user data")
@@ -175,10 +174,13 @@ if not os.path.exists("./scripts/tmp/"):
175 pass 174 pass
176 175
177access_token = os.environ.get('ANILIST_ACCESS_TOKEN') 176access_token = os.environ.get('ANILIST_ACCESS_TOKEN')
177rewatching = False
178 178
179parser = argparse.ArgumentParser(description="Print a greeting message.") 179parser = argparse.ArgumentParser(description="Print a greeting message.")
180# parser.add_argument("--name", type=str, required=True, help="Your name") 180# parser.add_argument("--name", type=str, required=True, help="Your name")
181parser.add_argument("-new", action='store_true', help="Add new anime to watching (optional)") 181parser.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)")
182args = parser.parse_args() 184args = parser.parse_args()
183 185
184if args.new: 186if args.new:
@@ -239,6 +241,16 @@ except:
239 print("Please select anime") 241 print("Please select anime")
240 select_anime(anime_dict) 242 select_anime(anime_dict)
241 243
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
242run_script("episode_list") 254run_script("episode_list")
243 255
244binge_watching = False 256binge_watching = False
@@ -247,22 +259,22 @@ last_episode = int(read_tmp("episode_list").split()[-1])
247anime_watch_history = get_all_anime(get_userconfig_value(user_config, 'history_file')) 259anime_watch_history = get_all_anime(get_userconfig_value(user_config, 'history_file'))
248anime_history = find_anime(anime_watch_history, anilist_id=media_id, allanime_id=get_contents_of("id")) 260anime_history = find_anime(anime_watch_history, anilist_id=media_id, allanime_id=get_contents_of("id"))
249episode_completed = False 261episode_completed = False
250rewatching = False
251 262
252if anime_history: # if it exists in local history 263if anime_history: # if it exists in local history
253 # print(f"came in history {str(progress)}") 264 # print(f"came in history {str(progress)}")
254 if int(anime_history['episode']) != progress+1: # if the upstream progress is ahead 265 if progress == last_episode or int(anime_history['episode']) == int(progress)+1:
255 write_to_tmp("ep_no", str(int(progress)+1)) 266 # print(anime_history['episode'])
256 # print(f"Starting anime from upstream {str(progress + 1)}") 267 if progress == last_episode:
257 watching_ep = progress + 1 268 rewatching = True
258
259 elif int(anime_history['episode']) == int(progress)+1: # if the upstream progress is NOT ahead
260 mpv_args.append(f"--start={anime_history['time']}") 269 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
264 watching_ep = int(anime_history['episode']) 270 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
266 if progress == last_episode: 278 if progress == last_episode:
267 user_input = input("Do you want to start this anime from beginning? (y/n):") 279 user_input = input("Do you want to start this anime from beginning? (y/n):")
268 if user_input.lower() == "yes" or user_input.lower() == "y" or user_input.lower() == "": 280 if user_input.lower() == "yes" or user_input.lower() == "y" or user_input.lower() == "":
@@ -271,8 +283,8 @@ else: # if there is no history
271 else: 283 else:
272 print("Starting last episode of anime") 284 print("Starting last episode of anime")
273 progress = last_episode - 1 285 progress = last_episode - 1
274 watching_ep = int(progress)+1 286 watching_ep = int(progress)+1
275 write_to_tmp("ep_no", str(watching_ep)) 287 write_to_tmp("ep_no", str(watching_ep))
276 288
277# os.system("./scripts/episode_url.sh") 289# os.system("./scripts/episode_url.sh")
278run_script("episode_url") 290run_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
84allanime_refr="https://allanime.to" 84allanime_refr="https://allanime.to"
85allanime_base="allanime.day" 85allanime_base="allanime.day"
86allanime_api="https://api.${allanime_base}" 86allanime_api="https://api.${allanime_base}"
87mode="${ANI_CLI_MODE:-sub}" 87sub_or_dub=$(cat ./scripts/tmp/mode)
88mode="${ANI_CLI_MODE:-$sub_or_dub}"
88download_dir="${ANI_CLI_DOWNLOAD_DIR:-.}" 89download_dir="${ANI_CLI_DOWNLOAD_DIR:-.}"
89quality="${ANI_CLI_QUALITY:-best}" 90quality="${ANI_CLI_QUALITY:-best}"
90case "$(uname -a)" in 91case "$(uname -a)" in