Skip to content

Fix cryptic combine crash and segment ordering past 1000 files#175

Open
s0len wants to merge 2 commits into
jo1gi:masterfrom
s0len:fix-combine-robustness
Open

Fix cryptic combine crash and segment ordering past 1000 files#175
s0len wants to merge 2 commits into
jo1gi:masterfrom
s0len:fix-combine-robustness

Conversation

@s0len

@s0len s0len commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

While downloading a ~3300-segment Nextory audiobook with --combine, the combine step crashed with a confusing FileNotFoundError: output_file.aac and discarded the in-progress merge. Two distinct issues:

1. combine_audiofiles crashes cryptically when ffmpeg writes no output

The re-encode fallback in output.py could finish without producing output_file (e.g. a transient ffmpeg error on a chunk). The code then ran os.remove(tmp_input) followed by shutil.move(tmp_output, tmp_input) on a file that was never created — crashing with a FileNotFoundError and deleting the accumulated combine progress.

Now the fallback result is checked: if ffmpeg produced no output, raise FailedCombining (logging ffmpeg's stderr at debug level) and leave tmp_input intact, instead of crashing and losing progress.

2. Segment filenames under-pad past powers of ten

create_filepath used zfill(int(log10(len(files)))). For 3307 files that pads to 3 digits, so Part 1000Part 3306 sort lexically before Part 999, scrambling the concat order. + 1 makes the padding width cover the largest index.

Testing

Built and installed locally; a full --combine -f mp4 download of a 3307-segment book now completes end-to-end and produces a valid 2h19m mp4.

🤖 Generated with Claude Code

s0len and others added 2 commits June 16, 2026 22:18
The re-encode fallback could silently produce nothing (e.g. a transient
ffmpeg error on a chunk). The code then removed the accumulated input and
moved a non-existent output_file, crashing with a cryptic FileNotFoundError
and discarding combine progress. Verify ffmpeg actually wrote output before
moving; otherwise raise FailedCombining and log ffmpeg stderr at debug.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
zfill(int(log10(n))) under-pads once the file count crosses a power of ten
(e.g. 3307 files -> 3-digit padding), so 'Part 1000' sorts lexically before
'Part 999' and segments combine out of order. Add 1 so the width covers the
largest index.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@s0len

s0len commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

Looks good to me and verified locally. Thanks for your work @jo1gi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant