diff --git a/homelab/rename-one-piece.py b/homelab/rename-one-piece.py new file mode 100644 index 0000000..08aa4a9 --- /dev/null +++ b/homelab/rename-one-piece.py @@ -0,0 +1,79 @@ +#!/usr/bin/python3 + +import os +import re + +ONE_PIECE_SEASON_COUNT = [ + 8, # Season 1 + 22, # Season 2 + 17, # Season 3 + 13, # Season 4 + 9, # Season 5 + 22, # Season 6 + 39, # Season 7 + 13, # Season 8 + 52, # Season 9 + 31, # Season 10 + 99, # Season 11 + 56, # Season 12 + 100, # Season 13 + 35, # Season 14 + 62, # Season 15 + 49, # Season 16 + 118, # Season 17 + 33, # Season 18 + 98, # Season 19 + 14, # Season 20 + 179, # Season 21 +] + +ONE_PIECE_DIR = "/mnt/mergerfs/media/tv/One Piece" + + +def _extract_episode_number(filename): + # [HorribleSubs] One Piece - 260 [1080p].mkv -> 260 + return int(re.findall(r"\s(\d+)\s", filename)[0]) + + +def _get_episode_season(absolute_number): + season = 1 + episodes_in_season = ONE_PIECE_SEASON_COUNT[season - 1] + while absolute_number > episodes_in_season: + season += 1 + episodes_in_season += ONE_PIECE_SEASON_COUNT[season - 1] + return season + + +def _get_episode_number(season, absolute_number): + relative_number = absolute_number - sum(ONE_PIECE_SEASON_COUNT[:season - 1]) + missing_episode = 590 + if relative_number > missing_episode: + relative_number += 1 + return relative_number + + +def _get_new_name(relative_episode_number, actual_season): + name = "[HorribleSubs] One Piece - S" + if actual_season < 10: + name += "0" + name += f"{actual_season}" + return name + f"E{relative_episode_number} [1080p].mkv" + + +def main(): + # 589 -> 591 + all_files = os.listdir(ONE_PIECE_DIR) + for f in all_files: + # skip files that have a season associated with them + if "S0" in f: + print(f'Skipping {f}') + continue + current_episode = _extract_episode_number(f) + episode_season = _get_episode_season(current_episode) + relative_episode_number = _get_episode_number(episode_season, current_episode) + new_name = _get_new_name(relative_episode_number, episode_season) + print(f"Renaming {f} to {new_name}") + + +if __name__ == "__main__": + main() diff --git a/zx/change_branch.mjs b/zx/change_branch.mjs new file mode 100755 index 0000000..e48eb6b --- /dev/null +++ b/zx/change_branch.mjs @@ -0,0 +1,3 @@ +#!/usr/bin/env zx + +$.verbose = false; diff --git a/zx/new_issue_branch.mjs b/zx/new_issue_branch.mjs index 6212285..bb5362f 100755 --- a/zx/new_issue_branch.mjs +++ b/zx/new_issue_branch.mjs @@ -6,7 +6,7 @@ const issueNumber = process.argv[3]; const issue = await $`gh issue view ${issueNumber} --repo cosmos/ibc-go --json title`; const issueTitle = JSON.parse(issue).title; -let sanitizedTitle = issueTitle.replaceAll(" ", "-").trim() +let sanitizedTitle = issueTitle.replaceAll(" ", "-").trim().toLowerCase() sanitizedTitle = sanitizedTitle.replaceAll(".", "") sanitizedTitle = sanitizedTitle.replaceAll("`", "") sanitizedTitle = sanitizedTitle.replaceAll(":", "")