fix: support directory paths in save_lyrics() filename arg (closes #251)#333
Merged
Conversation
The `filename` parameter of save_lyrics() now accepts a full or relative path (e.g. "output/my_song"). The parent directory is created automatically if it does not exist, using pathlib.Path.mkdir(parents=True, exist_ok=True). Sanitization is applied only to the final filename stem, so caller-supplied directory path components are preserved as-is. Also fixes a latent double-sanitize: the base implementation now passes sanitize=False when delegating to to_json()/to_text(), since the filename is already sanitized at that point. Refactored base.py to use pathlib.Path throughout, removing the os module.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Closes #251.
The
filenameparameter ofsave_lyrics()now accepts a full or relative path (e.g."output/my_song"or"/tmp/lyrics/my_song"). The parent directory is created automatically if it does not exist.There is no new
pathparameter — the existingfilenameargument already supports paths naturally, and adding a separate parameter would have been redundant.Changes
lyricsgenius/types/base.py: Refactoredsave_lyrics(),to_json(), andto_text()to usepathlib.Paththroughout (removesimport os). Parent directories are created withPath.mkdir(parents=True, exist_ok=True). Sanitization is applied only to the filename stem, preserving caller-supplied directory components.lyricsgenius/types/song.py,artist.py,album.py: No interface changes — the fix is entirely in the base class.tests/test_song.py: Three new tests covering JSON/TXT saves into a subdirectory path and automatic directory creation.pyproje- **pyprouv.lock: Version bumped3.8.0→3.9.0.