aboutsummaryrefslogtreecommitdiffstats
path: root/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'models.py')
-rw-r--r--models.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/models.py b/models.py
index 01f91c2..5e35c97 100644
--- a/models.py
+++ b/models.py
@@ -1,5 +1,6 @@
from __future__ import annotations
+import re
from dataclasses import dataclass
from pathlib import Path
from types import SimpleNamespace
@@ -47,6 +48,18 @@ def flac_name(name: str) -> str:
return name if name.lower().endswith(".flac") else name + ".flac"
+def track_number(path: Path) -> int | None:
+ try:
+ value = FLAC(str(path)).get("TRACKNUMBER", [""])[0]
+ except Exception:
+ value = ""
+ for text in (str(value), path.stem):
+ match = re.match(r"\s*0*(\d{1,3})\b", text)
+ if match:
+ return int(match.group(1))
+ return None
+
+
@dataclass
class Track:
path: Path
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage