Skip to content

Commit 127f78b

Browse files
committed
feat: add tag script
1 parent 7c1f036 commit 127f78b

3 files changed

Lines changed: 54 additions & 0 deletions

File tree

‎pyproject.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ dependencies = [
1212
"markdownify==1.2.3",
1313
"requests==2.34.2",
1414
"feedparser==6.0.14",
15+
"mutagen>=1.48.1",
1516
]
1617

1718
[dependency-groups]

‎scripts/tag.py‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from pathlib import Path
2+
from mutagen.oggopus import OggOpus
3+
import re
4+
5+
files = sorted(Path("/path/to/files").glob("*.opus"))
6+
7+
current_book = None
8+
chapter_counter = 0
9+
10+
for file in files:
11+
stem = file.stem
12+
13+
# Match filenames like:
14+
# 11_002_Chapter 2_Some Chapter Title
15+
# 12_045_Chapter 45_Other Chapter Title
16+
#
17+
# but NOT:
18+
# 11_003_Chapter 3
19+
20+
m = re.match(r'^\d+_\d+_Chapter \d+_(.+)$', stem)
21+
22+
if m:
23+
current_book = m.group(1).strip()
24+
chapter_counter = 1
25+
else:
26+
chapter_counter += 1
27+
28+
if not current_book:
29+
print(f"Skipping {file.name} (no chapter book yet)")
30+
continue
31+
32+
title = f"{current_book} - {chapter_counter:02d}"
33+
34+
try:
35+
audio = OggOpus(file)
36+
audio["TITLE"] = [title]
37+
audio.save()
38+
39+
print(f"{file.name} -> {title}")
40+
41+
except Exception as e:
42+
print(f"ERROR {file.name}: {e}")

‎uv.lock‎

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)