mkm3u: Teach video parser to handle single-episode discs with titles.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 14 Mar 2022 18:29:06 +0000 (18:29 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Mon, 14 Mar 2022 20:06:40 +0000 (20:06 +0000)
mkm3u

diff --git a/mkm3u b/mkm3u
index bcc3536..9fdc90f 100755 (executable)
--- a/mkm3u
+++ b/mkm3u
@@ -139,10 +139,16 @@ def some_group(m, *gg):
 class VideoDir (object):
 
   _R_ISO_PRE = RX.compile(r""" ^
-        (?: S (?P<si> \d+) (?: \. \ (?P<st> .*)—)? (?: D (?P<sdi> \d+))? |
-            (?P<di> \d+))
-        \. \  #
-        (?P<eps> .*)
+        (?: S (?P<si> \d+)
+              (?: \. \ (?P<st> .*) — (?: D \d+ \. \ )? |
+                  D \d+ \. \ |
+                  (?= E \d+ \. \ ) |
+                  \. \ ) |
+            \d+ \. \ )
+        (?: (?P<eplist>
+             (?: S \d+ \ )? E \d+ (?: – \d+)?
+             (?: , \ (?: S \d+ \ )? E \d+ (?: – \d+)?)*) |
+            (?P<epname> E \d+) \. \ .*)
         \. iso $
   """, RX.X)
 
@@ -183,7 +189,10 @@ class VideoDir (object):
       disc = VideoDisc(path)
       ts = season
       any, bad = False, False
-      for eprange in m.group("eps").split(", "):
+      epname = m.group("epname")
+      if epname is not None: eplist = [epname]
+      else: eplist = m.group("eplist").split(", ")
+      for eprange in eplist:
         mm = me._R_ISO_EP.match(eprange)
         if mm is None: bad = True; continue
         if not any: