Skip to content

Commit 561c67a

Browse files
committed
Merge branch 'pr/azumukupoe/158'
2 parents fd7cac5 + fb52e06 commit 561c67a

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ If an artist's URL is given, all albums by the specified artist will be download
4949
| `-c`, `--config-location` | Specify a directory containing a Zotify `config.json` file to load settings |
5050
| `-u`, `--username` | Account username |
5151
| `--password` | Account password |
52-
| `--token` | Authentication token |
52+
| `--token` | Authentication token |
5353

5454
| Command Line Flag (exclusive) | Function |
5555
|-------------------------------|----------------------------------------------------------------------------------------|
@@ -85,6 +85,7 @@ Set arguments in the commandline like this: `-sc False` or `--codec mp3`. Wrap a
8585
| `ALBUM_ART_JPG_FILE` | `--album-art-jpg-file` | False | Save album art as a separate .jpg file |
8686
| `SONG_ARCHIVE_LOCATION` | `--song-archive-location` | | Directory where Zotify saves the global song_archive file |
8787
| `DISABLE_DIRECTORY_ARCHIVES` | `--disable-directory-archives` | False | Disable local song_archive in download directories |
88+
| `MAX_FILENAME_LENGTH` | `--max-filename-length` | 0 | Maximum character length of filenames, truncated to fit, 0 meaning no limit |
8889
| `SPLIT_ALBUM_DISCS` | `--split-album-discs` | False | Saves each disk in its own folder |
8990
| `DOWNLOAD_LYRICS` | `--download-lyrics` | True | Downloads synced lyrics in .lrc format, uses unsynced as fallback |
9091
| `LYRICS_LOCATION` | `--lyrics-location` | | Directory where Zotify saves lyrics files (default is output directory) |

zotify/config.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
EXPORT_M3U8 = 'EXPORT_M3U8'
5353
LIKED_SONGS_ARCHIVE_M3U8 = 'LIKED_SONGS_ARCHIVE_M3U8'
5454
ALBUM_ART_JPG_FILE = 'ALBUM_ART_JPG_FILE'
55-
55+
MAX_FILENAME_LENGTH = 'MAX_FILENAME_LENGTH'
5656

5757
CONFIG_VALUES = {
5858
ROOT_PATH: { 'default': '~/Music/Zotify Music', 'type': str, 'arg': ('-rp', '--root-path' ,) },
@@ -77,6 +77,7 @@
7777
EXPORT_M3U8: { 'default': 'False', 'type': bool, 'arg': ('-e, --export-m3u8' ,) },
7878
LIKED_SONGS_ARCHIVE_M3U8: { 'default': 'True', 'type': bool, 'arg': ('--liked-songs-archive-m3u8' ,) },
7979
ROOT_PODCAST_PATH: { 'default': '~/Music/Zotify Podcasts', 'type': str, 'arg': ('-rpp', '--root-podcast-path' ,) },
80+
MAX_FILENAME_LENGTH: { 'default': '0', 'type': int, 'arg': ('--max-filename-length' ,) },
8081
TEMP_DOWNLOAD_DIR: { 'default': '', 'type': str, 'arg': ('-td', '--temp-download-dir' ,) },
8182
DOWNLOAD_FORMAT: { 'default': 'copy', 'type': str, 'arg': ('--codec', '--download-format' ,) },
8283
DOWNLOAD_QUALITY: { 'default': 'auto', 'type': str, 'arg': ('-q', '--download-quality' ,) },
@@ -409,4 +410,8 @@ def get_liked_songs_archive_m3u8(cls) -> bool:
409410

410411
@classmethod
411412
def get_album_art_jpg_file(cls) -> bool:
412-
return cls.get(ALBUM_ART_JPG_FILE)
413+
return cls.get(ALBUM_ART_JPG_FILE)
414+
415+
@classmethod
416+
def get_max_filename_length(cls) -> int:
417+
return cls.get(MAX_FILENAME_LENGTH)

zotify/utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,13 @@ def fix_filename(name):
328328
>>> all('_' == fix_filename(chr(i)) for i in list(range(32)))
329329
True
330330
"""
331-
return re.sub(r'[/\\:|<>"?*\0-\x1f]|^(AUX|COM[1-9]|CON|LPT[1-9]|NUL|PRN)(?![^.])|^\s|[\s.]$', "_", str(name), flags=re.IGNORECASE)
331+
name = re.sub(r'[/\\:|<>"?*\0-\x1f]|^(AUX|COM[1-9]|CON|LPT[1-9]|NUL|PRN)(?![^.])|^\s|[\s.]$', "_", str(name), flags=re.IGNORECASE)
332+
333+
maxlen = Zotify.CONFIG.get_max_filename_length()
334+
if maxlen and len(name) > maxlen:
335+
name = name[:maxlen]
336+
337+
return name
332338

333339

334340
def fmt_seconds(secs: float) -> str:

0 commit comments

Comments
 (0)