Skip to content

Conversation

@jcomicsutils
Copy link
Contributor

No description provided.

@jcomicsutils jcomicsutils force-pushed the feature/minimal-slugify branch from 3b2f617 to acba3b8 Compare August 12, 2025 06:27
@Evolution0
Copy link
Owner

What is the use-case? An example would be helpful.

@jcomicsutils
Copy link
Contributor Author

Sorry, I had problems with git and forgot to add a description.

This is useful for people not using any id in template and trying to download albums with characters that would be removed by slugify, such as https://deathbedtapes.bandcamp.com/album/-, https://sonnovdrone.bandcamp.com/album/--162 and https://woodstruth.bandcamp.com/album/-, since slugify removes the characters it'd fail to create a folder and just download the tracks to base-dir. This would only remove illegal characters for filenames and folders (at least for windows, I'm not sure about other OS), so the paths would be as close as possible to the original titles and avoid folders failing to be created.

@Evolution0
Copy link
Owner

Would not --ok-chars="-" work in this case?

@jcomicsutils
Copy link
Contributor Author

Doing python.exe -m bandcamp_dl --ok-chars="-" --template "%{album} [%{album_id}]/%{track} - %{title} [%{track_id}]" --debug https://deathbedtapes.bandcamp.com/album/- resulted in

 [4274798753]/
    01 -  [54253158].mp3
    02 -  [2641764917].mp3
    cover.jpg

Doing python.exe -m bandcamp_dl --minimal-slugify --template "%{album} [%{album_id}]/%{track} - %{title} [%{track_id}]" --debug https://deathbedtapes.bandcamp.com/album/- resulted in

█████ [4274798753]/
   01 - █████ [54253158].mp3
   02 - █████ [2641764917].mp3
   cover.jpg

@Evolution0
Copy link
Owner

Ah I see, I assumed the album name was the problem here, in that case: --ok-chars="-█" you would basically just "whitelist" whatever is getting removed that you would like to keep.

My issue is that slugification does a bit more than filtering chars out and this is essentially doing --no-slugify and adding a char filter in, perhaps the solution here is to instead extend slugify_preset() and add a new preset however I have had my eye once again on a new slugification library namely python-slugify which is actually maintained (the previous two libraries I have used for this eventually went unmaintained) which has some nice features so the way slugification is handled may change soon anymore, more presets would be nice, I have let the process be a bit.. heavy handed on the output.

@jcomicsutils
Copy link
Contributor Author

I thought of this mainly for batch downloading, where it's not reasonable to whitelist everything, and using --no-slugify would fail for albums with prohibited characters, at least for windows, these are the ones I removed. For example, downloading this album https://polarlichthnw.bandcamp.com/album/where-do-we-go-after-the-end-of-the-world

python.exe -m bandcamp_dl --base-dir="D:\PythonProjects\git\bandcamp-dl" --no-slugify --debug --template "%{album} [%{album_id}]/%{track} - %{title} [%{track_id}]" https://polarlichthnw.bandcamp.com/album/where-do-we-go-after-the-end-of-the-world

DEBUG:bandcamp-dl:Config/Args: Namespace(URL=['https://polarlichthnw.bandcamp.com/album/where-do-we-go-after-the-end-of-the-world'], version=False, debug=True, artist=None, track=None, album=None, template='%{album} [%{album_id}]/%{track} - %{title} [%{track_id}]', base_dir='D:\\PythonProjects\\git\\bandcamp-dl', full_album=False, overwrite=False, no_art=False, embed_lyrics=False, group=False, embed_art=False, cover_quality=0, untitled_path_from_slug=False, no_slugify=True, ok_chars='-_~', space_char='-', ascii_only=False, keep_spaces=False, case_mode='lower', no_confirm=False, embed_genres=False, truncate_album=0, truncate_track=0)
DEBUG:bandcamp-dl:
        URL: https://polarlichthnw.bandcamp.com/album/where-do-we-go-after-the-end-of-the-world
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): polarlichthnw.bandcamp.com:443
DEBUG:urllib3.connectionpool:https://polarlichthnw.bandcamp.com:443 "GET /album/where-do-we-go-after-the-end-of-the-world HTTP/1.1" 200 None
DEBUG:bandcamp-dl.Main: Generating BandcampJSON..
DEBUG:bandcamp-dl.JSON: Grab pagedata JSON..
DEBUG:bandcamp-dl.JSON: Grabbing embedded scripts..
DEBUG:bandcamp-dl.JSON: Converting JS to JSON..
DEBUG:bandcamp-dl.JSON: Converting JS to JSON..
DEBUG:bandcamp-dl.Main: BandcampJSON generated..
DEBUG:bandcamp-dl.Main: Generating Album..
DEBUG:bandcamp-dl.Main: Album page, found album_id: 2622853844
DEBUG:bandcamp-dl.Main: Generating track metadata..
DEBUG:bandcamp-dl.Main: Track metadata generated..
DEBUG:bandcamp-dl.Main: Album generated..
DEBUG:bandcamp-dl.Main: Album URL: https://polarlichthnw.bandcamp.com/album/where-do-we-go-after-the-end-of-the-world
DEBUG:bandcamp-dl: Album data:
        {'tracks': [{'duration': 5208.19, 'track': '1', 'title': 'Where Do We Go After the End of the World?', 'artist': None, 'track_id': 878360566, 'url': 'https://t4.bcbits.com/stream/7f596bab69146bbed9e840b58e369671/mp3-128/878360566?p=0&ts=1755459511&t=d83ffc816acc362c715d140bf8403a211de6a3d3&token=1755459511_239fc6279893320b77b1457195b9019eb095e2a9'}], 'title': 'Where Do We Go After the End of the World?', 'artist': 'Polarlicht', 'label': 'Polarlicht', 'full': True, 'art': 'https://f4.bcbits.com/img/a3496531994_0.jpg', 'date': '2024', 'url': 'https://polarlichthnw.bandcamp.com/album/where-do-we-go-after-the-end-of-the-world', 'genres': '', 'album_id': 2622853844}
DEBUG:bandcamp-dl:Preparing download process..
DEBUG:bandcamp-dl:Initiating download process..
DEBUG:bandcamp-dl.Downloader: Generating filepath/trackname..
DEBUG:bandcamp-dl.Downloader:
        Template: %{album} [%{album_id}]/%{track} - %{title} [%{track_id}]
DEBUG:bandcamp-dl.Downloader:Track artist is None, replacing with album artist
DEBUG:bandcamp-dl.Downloader: filepath/trackname generated..
DEBUG:bandcamp-dl.Downloader:
        Path: D:\PythonProjects\git\bandcamp-dl/Where Do We Go After the End of the World? [2622853844]/01 - Where Do We Go After the End of the World? [878360566].mp3
DEBUG:bandcamp-dl.Downloader: Directory:
        D:\PythonProjects\git\bandcamp-dl/Where Do We Go After the End of the World? [2622853844]
DEBUG:bandcamp-dl.Downloader: Directory doesn't exist, creating..
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "D:\PythonProjects\git\bandcamp-dl\bandcamp_dl\__main__.py", line 164, in <module>
    main()
  File "D:\PythonProjects\git\bandcamp-dl\bandcamp_dl\__main__.py", line 156, in main
    bandcamp_downloader.start(album)
  File "D:\PythonProjects\git\bandcamp-dl\bandcamp_dl\bandcampdownloader.py", line 54, in start
    self.download_album(album)
  File "D:\PythonProjects\git\bandcamp-dl\bandcamp_dl\bandcampdownloader.py", line 171, in download_album
    dirname = self.create_directory(filepath)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\PythonProjects\git\bandcamp-dl\bandcamp_dl\bandcampdownloader.py", line 130, in create_directory
    os.makedirs(directory)
  File "<frozen os>", line 225, in makedirs
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: 'D:\\PythonProjects\\git\\bandcamp-dl/Where Do We Go After the End of the World? [2622853844]'

But doing python.exe -m bandcamp_dl --base-dir="D:\PythonProjects\git\bandcamp-dl" --minimal-slugify --debug --template "%{album} [%{album_id}]/%{track} - %{title} [%{track_id}]" https://polarlichthnw.bandcamp.com/album/where-do-we-go-after-the-end-of-the-world works fine

Where Do We Go After the End of the World [2622853844]/
    01 - Where Do We Go After the End of the World [878360566].mp3
    cover.jpg

But if it's going to be changed soon then maybe it's not needed.

@Evolution0
Copy link
Owner

Depends on how the new implementation turns out really, for example remember #267 which lead to #269 ? python-slugify has max length and word boundary support built in so that may get refactored but I'm not sure yet how simply putting together presets with it will be, I may still need to leave the option open to go scorched earth, skip slugification, and use this method.

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.

2 participants