combine audiobooks: extend to opus
asd asd
This commit is contained in:
1 parent
e4f1cce494
commit
8b6fc7fdcd
2 files changed
+10
-50
No files matched your search
@@ -43,7 +43,10 @@ def ffmpeg_escape(path: Path) -> str:
|
|||||||
return str(path.resolve()).replace("'", r"'\''")
|
return str(path.resolve()).replace("'", r"'\''")
|
||||||
|
|
||||||
def create_m4b(root_path: Path, book_dir: Path) -> None:
|
def create_m4b(root_path: Path, book_dir: Path) -> None:
|
||||||
media_files = sorted(book_dir.glob("*.m[p,4][3,b,a]"))
|
media_files = sorted(list(book_dir.glob("*.mp3"))
|
||||||
|
+ list(book_dir.glob("*.m4a"))
|
||||||
|
+ list(book_dir.glob("*.m4b"))
|
||||||
|
+ list(book_dir.glob("*.opus")))
|
||||||
if not media_files:
|
if not media_files:
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -152,6 +155,7 @@ def find_book_dirs(root: Path) -> tuple[list[Any], int]:
|
|||||||
list(root.rglob("*.mp3"))
|
list(root.rglob("*.mp3"))
|
||||||
+ list(root.rglob("*.m4a"))
|
+ list(root.rglob("*.m4a"))
|
||||||
+ list(root.rglob("*.m4b"))
|
+ list(root.rglob("*.m4b"))
|
||||||
|
+ list(root.rglob("*.opus"))
|
||||||
)
|
)
|
||||||
|
|
||||||
counts: dict[Path, int] = {}
|
counts: dict[Path, int] = {}
|
||||||
@@ -166,7 +170,7 @@ def find_book_dirs(root: Path) -> tuple[list[Any], int]:
|
|||||||
for directory, count in counts.items():
|
for directory, count in counts.items():
|
||||||
if count > 1:
|
if count > 1:
|
||||||
directories.append(directory)
|
directories.append(directory)
|
||||||
size += sum(file.stat().st_size for pattern in ("*.mp3", "*.m4a", "*.m4b") for file in directory.glob(pattern))
|
size += sum(file.stat().st_size for pattern in ("*.mp3", "*.m4a", "*.m4b", "*.opus") for file in directory.glob(pattern))
|
||||||
|
|
||||||
|
|
||||||
return sorted(directories), size
|
return sorted(directories), size
|
||||||
@@ -179,7 +183,6 @@ def process_book(args):
|
|||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
return book_dir, str(exc)
|
return book_dir, str(exc)
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
@@ -196,7 +199,10 @@ def main() -> None:
|
|||||||
raise SystemExit(f"Path does not exist: {target}")
|
raise SystemExit(f"Path does not exist: {target}")
|
||||||
|
|
||||||
# Direct book folder
|
# Direct book folder
|
||||||
if any(target.glob("*.m[p,4][3,b]")):
|
if any(list(target.glob("*.mp3"))
|
||||||
|
+ list(target.glob("*.m4a"))
|
||||||
|
+ list(target.glob("*.m4b"))
|
||||||
|
+ list(target.glob("*.opus"))):
|
||||||
create_m4b(target.parent,target)
|
create_m4b(target.parent,target)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -295,52 +295,6 @@ def rename_media(media_data,episodes, series_path,file_title):
|
|||||||
print("Cancelled.")
|
print("Cancelled.")
|
||||||
return
|
return
|
||||||
|
|
||||||
def process_series(series_path: Path):
|
|
||||||
series = series_path.name
|
|
||||||
|
|
||||||
m = re.match(r"^(.*?)\s*\((\d{4})\)\s*\[(\d+)\]$", series)
|
|
||||||
|
|
||||||
if not m:
|
|
||||||
print(f"Skipping invalid folder: {series}")
|
|
||||||
return
|
|
||||||
|
|
||||||
file_title = m.group(1).strip()
|
|
||||||
file_year = int(m.group(2))
|
|
||||||
file_tmdb_id = int(m.group(3))
|
|
||||||
|
|
||||||
print()
|
|
||||||
print("=" * 80)
|
|
||||||
print(f"TITLE={file_title}")
|
|
||||||
print(f"YEAR={file_year}")
|
|
||||||
print(f"TMDB_ID={file_tmdb_id}")
|
|
||||||
|
|
||||||
if file_tmdb_id == 0:
|
|
||||||
print("TMDB ID required")
|
|
||||||
return
|
|
||||||
|
|
||||||
try:
|
|
||||||
data = find_by_tmdb_id(file_tmdb_id)
|
|
||||||
|
|
||||||
if not data:
|
|
||||||
print("TMDB lookup failed")
|
|
||||||
return
|
|
||||||
|
|
||||||
media_type, media_data = data
|
|
||||||
|
|
||||||
print_results(data)
|
|
||||||
|
|
||||||
episodes = get_episode_list(media_data)
|
|
||||||
|
|
||||||
rename_media(
|
|
||||||
media_data,
|
|
||||||
episodes,
|
|
||||||
series_path,
|
|
||||||
file_title
|
|
||||||
)
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Error processing {series}: {e}")
|
|
||||||
|
|
||||||
def process_series(series_path: Path):
|
def process_series(series_path: Path):
|
||||||
series = series_path.name
|
series = series_path.name
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user