Commit f9068c9ca4
Unsigned
Layout: unified · split
curd.py +27 −15
| @@ -20,7 +20,6 @@ from start_video import start_video, send_command, get_percentage_watched, perce | |||
| 20 | from select_anime import load_anime_data | 20 | from select_anime import load_anime_data |
| 21 | from select_anime import extract_anime_info | 21 | from select_anime import extract_anime_info |
| 22 | from select_anime import select_anime | 22 | from select_anime import select_anime |
| 23 | |||
| 24 | from track_anime import add_anime, update_anime, get_all_anime, delete_anime, find_anime | 23 | from track_anime import add_anime, update_anime, get_all_anime, delete_anime, find_anime |
| 25 | 24 | ||
| 26 | mark_episode_as_completed_at = 85 | 25 | mark_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 | ||
| 59 | def download_anilist_data(access_token, user_id): | 58 | def 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 | ||
| 177 | access_token = os.environ.get('ANILIST_ACCESS_TOKEN') | 176 | access_token = os.environ.get('ANILIST_ACCESS_TOKEN') |
| 177 | rewatching = False | ||
| 178 | 178 | ||
| 179 | parser = argparse.ArgumentParser(description="Print a greeting message.") | 179 | parser = 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") |
| 181 | parser.add_argument("-new", action='store_true', help="Add new anime to watching (optional)") | 181 | parser.add_argument("-new", action='store_true', help="Add new anime to watching (optional)") |
| 182 | parser.add_argument("-sub", action='store_true', help="Anime audio type (optional)") | ||
| 183 | parser.add_argument("-dub", action='store_true', help="Anime audio type (optional)") | ||
| 182 | args = parser.parse_args() | 184 | args = parser.parse_args() |
| 183 | 185 | ||
| 184 | if args.new: | 186 | if 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 | ||
| 244 | if get_userconfig_value(user_config, "sub_or_dub")=="sub": | ||
| 245 | write_to_tmp("mode", "sub") | ||
| 246 | elif get_userconfig_value(user_config, "sub_or_dub")=="dub": | ||
| 247 | write_to_tmp("mode", "dub") | ||
| 248 | |||
| 249 | if args.sub: # arguments take precidence | ||
| 250 | write_to_tmp("mode", "sub") | ||
| 251 | if args.dub: | ||
| 252 | write_to_tmp("mode", "dub") | ||
| 253 | |||
| 242 | run_script("episode_list") | 254 | run_script("episode_list") |
| 243 | 255 | ||
| 244 | binge_watching = False | 256 | binge_watching = False |
| @@ -247,22 +259,22 @@ last_episode = int(read_tmp("episode_list").split()[-1]) | |||
| 247 | anime_watch_history = get_all_anime(get_userconfig_value(user_config, 'history_file')) | 259 | anime_watch_history = get_all_anime(get_userconfig_value(user_config, 'history_file')) |
| 248 | anime_history = find_anime(anime_watch_history, anilist_id=media_id, allanime_id=get_contents_of("id")) | 260 | anime_history = find_anime(anime_watch_history, anilist_id=media_id, allanime_id=get_contents_of("id")) |
| 249 | episode_completed = False | 261 | episode_completed = False |
| 250 | rewatching = False | ||
| 251 | 262 | ||
| 252 | if anime_history: # if it exists in local history | 263 | if 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']) |
| 265 | else: # 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 | ||
| 277 | else: # 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") |
| 278 | run_script("episode_url") | 290 | run_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 | |||
| 84 | allanime_refr="https://allanime.to" | 84 | allanime_refr="https://allanime.to" |
| 85 | allanime_base="allanime.day" | 85 | allanime_base="allanime.day" |
| 86 | allanime_api="https://api.${allanime_base}" | 86 | allanime_api="https://api.${allanime_base}" |
| 87 | mode="${ANI_CLI_MODE:-sub}" | 87 | sub_or_dub=$(cat ./scripts/tmp/mode) |
| 88 | mode="${ANI_CLI_MODE:-$sub_or_dub}" | ||
| 88 | download_dir="${ANI_CLI_DOWNLOAD_DIR:-.}" | 89 | download_dir="${ANI_CLI_DOWNLOAD_DIR:-.}" |
| 89 | quality="${ANI_CLI_QUALITY:-best}" | 90 | quality="${ANI_CLI_QUALITY:-best}" |
| 90 | case "$(uname -a)" in | 91 | case "$(uname -a)" in |