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