Skip to content

fix: support directory paths in save_lyrics() filename arg (closes #251)#333

Merged
johnwmillr merged 1 commit into
masterfrom
fix/save-lyrics-path
Mar 6, 2026
Merged

fix: support directory paths in save_lyrics() filename arg (closes #251)#333
johnwmillr merged 1 commit into
masterfrom
fix/save-lyrics-path

Conversation

@johnwmillr

Copy link
Copy Markdown
Owner

Summary

Closes #251.

The filename parameter of save_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 path parameter — the existing filename argument already supports paths naturally, and adding a separate parameter would have been redundant.

Changes

  • lyricsgenius/types/base.py: Refactored save_lyrics(), to_json(), and to_text() to use pathlib.Path throughout (removes import os). Parent directories are created with Path.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- **pypro uv.lock: Version bumped 3.8.03.9.0.

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.
@johnwmillr johnwmillr merged commit 3538bb1 into master Mar 6, 2026
10 checks passed
@johnwmillr johnwmillr deleted the fix/save-lyrics-path branch March 6, 2026 07:16
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.

Feature request: add a path option to the genius.save_lyrics()-function

1 participant