aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan <me@jordan.im>2020-05-04 21:12:12 -0700
committerJordan <me@jordan.im>2020-05-04 21:12:12 -0700
commitdead612147dc86de019a680a473351a10e419338 (patch)
tree43c295c7082e6496c71c2304619ffee9643eb772
parent61066bbe2d95b9d9571de5003151fcb712c6a0e3 (diff)
downloadroka-dead612147dc86de019a680a473351a10e419338.tar.gz
roka-dead612147dc86de019a680a473351a10e419338.zip
use natural sort of files in RSS resp if 'ignore_tracknum' in book path
-rw-r--r--README4
-rwxr-xr-xrun.py34
2 files changed, 25 insertions, 13 deletions
diff --git a/README b/README
index 843cdbd..cef6721 100644
--- a/README
+++ b/README
@@ -33,5 +33,9 @@ design decisions
3. XML pubDate and list order is derived from MP3 track attributes; if not
present or duplicates exist, tracks are sorted alphanumerically
+ if a book's track numbers are unique but incorrect, a preference for filename
+ sort can be established by creating an 'ignore_tracknum' file in the
+ audiobook's path
+
4. no rebuild endpoint exists; cache-affecting routines are run externally via
rebuild.py
diff --git a/run.py b/run.py
index af9abba..d73545b 100755
--- a/run.py
+++ b/run.py
@@ -127,20 +127,28 @@ def list_books():
book_title = ET.SubElement(channel, 'title')
book_title.text = escape(books[a]['title'])
- # sort by track number, alphanumerically if track is absent
- track_list = [] # account for duplicates
- for a_file in books[a]['files']:
- track = books[a]['files'][a_file]['track']
- if not track or track in track_list:
- # remove leading zeros from digits (natural sort)
- conv = lambda s: [int(x) if x.isdigit() else x.lower() for x in
- re.split('(\d+)', s)]
- key = lambda x: conv(books[a]['files'][x]['filename'])
- break
- track_list.append(track)
+ # use filename sort if ignore_tracknum file present in book dir
+ ignore_tracknum = os.path.join(books[a]['path'], 'ignore_tracknum')
+ if os.path.exists(ignore_tracknum):
+ # remove leading zeros from digits (natural sort)
+ conv = lambda s: [int(x) if x.isdigit() else x.lower() for x in
+ re.split('(\d+)', s)]
+ key = lambda x: conv(books[a]['files'][x]['filename'])
else:
- # we have populated and unique track values, use those
- key = lambda x: books[a]['files'][x]['track']
+ # sort by track number, alphanumerically if track is absent
+ track_list = [] # account for duplicates
+ for a_file in books[a]['files']:
+ track = books[a]['files'][a_file]['track']
+ if not track or track in track_list:
+ # remove leading zeros from digits (natural sort)
+ conv = lambda s: [int(x) if x.isdigit() else x.lower()
+ for x in re.split('(\d+)', s)]
+ key = lambda x: conv(books[a]['files'][x]['filename'])
+ break
+ track_list.append(track)
+ else:
+ # we have populated and unique track values, use those
+ key = lambda x: books[a]['files'][x]['track']
# populate XML attribute values required by Apple podcasts
for idx, f in enumerate(sorted(books[a]['files'], key=key)):