Fix extremely long filenames causing file not found #860
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix for Extremely Long Filename FileNotFoundErrors
Problem
Users were experiencing
FileNotFoundErrorexceptions when downloading tracks with extremely long filenames, particularly classical music with detailed metadata. The error occurred because the generated file paths exceeded filesystem limits (typically 260 characters on Windows).Example error:
Solution
Core Changes
1. Enhanced
clean_filepath()Functionmax_lengthparameter (default: 200 characters)2. Album Folder Path Handling (
streamrip/media/album.py)_album_folder()to useclean_filepath()withmax_length=1503. Track Path Management (
streamrip/media/track.py)_set_download_path()with comprehensive path length checkingtruncate_tosetting4. Robust Error Handling (
streamrip/media/track.py)preprocess()method with try-catch for directory creationTest Coverage
Comprehensive Unit Tests
tests/test_filepath_utils.py(287 lines)truncate_str()respects 255-byte limitsmax_lengthvaluestests/test_track_filepath_handling.py(365 lines)truncate_tosetting with various values (50, 100, 200)tests/test_album_filepath_handling.py(369 lines)tests/test_filepath_integration.py(434 lines)Test Scenarios Covered
Validation
The fix has been validated against the original error case:
This comprehensive solution ensures robust handling of extremely long filenames while maintaining backward compatibility and user experience.