diff options
author | Jordan <me@jordan.im> | 2020-05-04 21:12:12 -0700 |
---|---|---|
committer | Jordan <me@jordan.im> | 2020-05-04 21:12:12 -0700 |
commit | dead612147dc86de019a680a473351a10e419338 (patch) | |
tree | 43c295c7082e6496c71c2304619ffee9643eb772 | |
parent | 61066bbe2d95b9d9571de5003151fcb712c6a0e3 (diff) | |
download | roka-dead612147dc86de019a680a473351a10e419338.tar.gz roka-dead612147dc86de019a680a473351a10e419338.zip |
use natural sort of files in RSS resp if 'ignore_tracknum' in book path
-rw-r--r-- | README | 4 | ||||
-rwxr-xr-x | run.py | 34 |
2 files changed, 25 insertions, 13 deletions
@@ -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 @@ -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)): |