mkm3u: Make filename parser commit to a set of patterns.
authorMark Wooding <mdw@distorted.org.uk>
Fri, 18 Mar 2022 10:32:46 +0000 (10:32 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 18 Mar 2022 13:56:07 +0000 (13:56 +0000)
Now hopefully it won't get confused by things which look like foreign
patterns but are actually just anomalies that it shouldn't worry about.

mkm3u

diff --git a/mkm3u b/mkm3u
index 08ef4ff..21c9a4b 100755 (executable)
--- a/mkm3u
+++ b/mkm3u
@@ -159,16 +159,18 @@ def match_group(m, *groups, dflt = None, mustp = False):
 
 class VideoDir (object):
 
-  _R_ISO_PRE = list(map(lambda pat: RX.compile("^" + pat + r"\.iso$", RX.X),
-    [r""" S? (?P<si> \d+) [A-Z]? \. \ (?P<stitle> .*) —
-            (?: D \d+ \. \ )?
-          (?P<epex> .*) """,
-     r""" S (?P<si> \d+) (?: D \d+)? \. \ (?P<epex> .*) """,
-     r""" S (?P<si> \d+) \. \ (?P<epex> E \d+ .*) """,
-     r""" S (?P<si> \d+) \. \ (?P<epex> E \d+ .*) """,
-     r""" S (?P<si> \d+) (?P<epex> E \d+) \. \ .* """,
-     r""" \d+ \. \ (?P<epex> [ES] \d+ .*) """,
-     r""" (?P<epnum> \d+ ) \. \ .* """]))
+  _R_ISO_PRE = list(map(lambda pats:
+                          list(map(lambda pat:
+                                     RX.compile("^" + pat + r"\.iso$", RX.X),
+                                   pats)),
+    [[r""" S (?P<si> \d+) \. \ (?P<stitle> .*) — (?: D \d+ \. \ )?
+           (?P<epex> .*) """,
+      r""" S (?P<si> \d+) (?: D \d+)? \. \ (?P<epex> .*) """,
+      r""" S (?P<si> \d+) \. \ (?P<epex> E \d+ .*) """,
+      r""" S (?P<si> \d+) (?P<epex> E \d+) \. \ .* """],
+     [r""" (?P<si> \d+) [A-Z]? \. \ (?P<stitle> .*) — (?P<epex> .*) """],
+     [r""" \d+ \. \ (?P<epex> [ES] \d+ .*) """],
+     [r""" (?P<epnum> \d+ ) \. \ .* """]]))
 
   _R_ISO_EP = RX.compile(r""" ^
         (?: S (?P<si> \d+) \ )?
@@ -181,13 +183,18 @@ class VideoDir (object):
     fns.sort()
     season = None
     seasons = {}
+    styles = me._R_ISO_PRE
     for fn in fns:
       path = OS.path.join(dir, fn)
       if not fn.endswith(".iso"): continue
       #print(";; `%s'" % path, file = SYS.stderr)
-      for r in me._R_ISO_PRE:
-        m = r.match(fn)
-        if m: break
+      for sty in styles:
+        for r in sty:
+          m = r.match(fn)
+          if m: styles = [sty]; break
+        else:
+          continue
+        break
       else:
         #print(";;\tignored (regex mismatch)", file = SYS.stderr)
         continue