Commit f4d5cedeb2

f4d5cedeb279a12b765d677d5dafe4f6cd1bcc36

parent: efb6ebd6c9

Unsigned

Wraient <wraient.911@gmail.com> · 2024-09-25 13:07 UTC

Skip anime opening and ending with curd

Layout: unified · split

curd.py +67 −41
@@ -685,15 +685,30 @@ def get_all_anime(database_file):
685685
686686# Function to update or add a new anime entry
687687def update_anime(database_file: str, anilist_id:str, allanime_id: str, episode:str, time:str, duration:str, name:str):
688 anime_list = get_all_anime(database_file)
689 updated = False
688 try:
689 anime_list = get_all_anime(database_file)
690 updated = False
690691
691 # Create a new list to store updated entries
692 updated_anime_list = []
693
694 # Check if the anime entry exists and update it
695 for anime in anime_list:
696 if anime['anilist_id'] == anilist_id and anime['allanime_id'] == allanime_id:
692 # Create a new list to store updated entries
693 updated_anime_list = []
694
695 # Check if the anime entry exists and update it
696 for anime in anime_list:
697 if anime['anilist_id'] == anilist_id and anime['allanime_id'] == allanime_id:
698 updated_anime_list.append({
699 'anilist_id': anilist_id,
700 'allanime_id': allanime_id,
701 'episode': episode,
702 'time': time,
703 'duration': duration,
704 'name': name
705 })
706 updated = True
707 else:
708 updated_anime_list.append(anime)
709
710 # If no entry was updated, add new entry
711 if not updated:
697712 updated_anime_list.append({
698713 'anilist_id': anilist_id,
699714 'allanime_id': allanime_id,
@@ -702,28 +717,16 @@ def update_anime(database_file: str, anilist_id:str, allanime_id: str, episode:s
702717 'duration': duration,
703718 'name': name
704719 })
705 updated = True
706 else:
707 updated_anime_list.append(anime)
708
709 # If no entry was updated, add new entry
710 if not updated:
711 updated_anime_list.append({
712 'anilist_id': anilist_id,
713 'allanime_id': allanime_id,
714 'episode': episode,
715 'time': time,
716 'duration': duration,
717 'name': name
718 })
719
720 # Write all entries back to the file
721 with open(database_file, mode='w', newline='') as file:
722 writer = csv.writer(file)
723 for anime in updated_anime_list:
724 writer.writerow([anime['anilist_id'], anime['allanime_id'], anime['episode'], anime['time'], anime['duration'], anime['name']])
725
726 # print("Updated the file")
720
721 # Write all entries back to the file
722 with open(database_file, mode='w', newline='') as file:
723 writer = csv.writer(file)
724 for anime in updated_anime_list:
725 writer.writerow([anime['anilist_id'], anime['allanime_id'], anime['episode'], anime['time'], anime['duration'], anime['name']])
726
727 # print("Updated the file")
728 except Exception as e:
729 print_error(f"This: {e}")
727730
728731def find_anime(anime_list, anilist_id=-1, allanime_id=-1):
729732 for anime in anime_list:
@@ -795,10 +798,11 @@ default_config = {
795798 "sub_or_dub":"sub",
796799 "percentage_to_mark_complete":85,
797800 "next_episode_prompt": False,
801 "skip_op": True,
802 "skip_ed": True,
798803 "score_on_completion": True,
799804 "save_mpv_speed": True,
800 "discord_presence": True,
801 "presence_script_path":"curddiscordpresence.py"
805 "discord_presence": False,
802806}
803807
804808def convert_seconds_to_minutes(seconds) -> str:
@@ -1218,6 +1222,7 @@ else: # if history does not exist
12181222 write_to_tmp("ep_no", str(watching_ep))
12191223# print(watching_ep)
12201224# os.system("{current_dir}/scripts/episode_url.sh")
1225print("Fetching anime")
12211226run_script("episode_url")
12221227
12231228# Print the result
@@ -1235,7 +1240,14 @@ if get_userconfig_value(user_config, "discord_presence") == True:
12351240 # print("imported pypresence")
12361241 rpc = Presence(discord_client_id)
12371242 rpc.connect()
1238 anime_image_url = get_anime_image(media_id)
1243 anime_mal_id, anime_image_url = get_anime_id_and_image(media_id)
1244else:
1245 anime_mal_id = get_anime_mal_id(media_id)
1246
1247# default variable declaration
1248watched_percentage = 0
1249is_paused = False
1250mpv_playback_speed = 1.0
12391251
12401252while True:
12411253
@@ -1245,9 +1257,17 @@ while True:
12451257 start_video(links[0][1], salt, mpv_args)
12461258 mpv_socket_path = "/tmp/curd/curd_mpvsocket"+str(salt)
12471259 connect_mpv_command = """echo '{ "command": ["get_property", "playback-time"] }' | socat - """+mpv_socket_path
1248 is_paused = False
1260 if get_userconfig_value(user_config, "skip_op") == True or get_userconfig_value(user_config, "skip_end"):
1261 skip_intervals = get_and_parse_aniskip_data(anime_mal_id, watching_ep)
1262 if skip_intervals == None:
1263 print("failed to get skip times")
1264
12491265 while True:
1250 time.sleep(1)
1266 # Example usage
1267 # anime_id = 28223
1268 # episode = 10
1269
1270 time.sleep(2)
12511271 result = subprocess.run(connect_mpv_command, shell=True, capture_output=True, text=True)
12521272 # print(result)
12531273 if result.returncode == 0:
@@ -1255,16 +1275,12 @@ while True:
12551275 if not output: # Check if output is empty
12561276 print("No data received. Retrying...")
12571277 try:
1258 time.sleep(1)
12591278 data = json.loads(output)
12601279 if data["error"] == "success":
12611280 playback_time = round(int(data["data"]), 2)
12621281 if get_userconfig_value(user_config, "discord_presence") == True:
1263 mpv_status = get_mpv_paused_status(mpv_socket_path)
1264 if mpv_status == True:
1265 is_paused = True
1266 else:
1267 is_paused = False
1282 is_paused = get_mpv_paused_status(mpv_socket_path)
1283
12681284
12691285 # print("mpv_status", mpv_status)
12701286 # print("is_paused", is_paused)
@@ -1284,6 +1300,16 @@ while True:
12841300 large_image=anime_image_url,
12851301 large_text=title,
12861302 )
1303 if skip_intervals:
1304 if get_userconfig_value(user_config, "skip_op") == True:
1305 if round(int(playback_time)) > round(int(skip_intervals['op']['start_time'])) and round(int(playback_time)) < round(int(skip_intervals['op']['start_time']))+10:
1306 print("skipped opening")
1307 seek_mpv(mpv_socket_path, int(skip_intervals['op']['end_time']))
1308
1309 if get_userconfig_value(user_config, "skip_ed") == True:
1310 if round(int(playback_time)) > round(int(skip_intervals['ed']['start_time'])) and round(int(playback_time)) < round(int(skip_intervals['ed']['start_time']))+10:
1311 print("skipped ending")
1312 seek_mpv(mpv_socket_path, int(skip_intervals['ed']['end_time']))
12871313
12881314 update_anime(get_userconfig_value(user_config, 'history_file'), str(media_id), str(get_contents_of("id")), str(watching_ep), str(playback_time), str(duration), str(title))
12891315 # print("Playback time:", playback_time)