Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added folder to save files #6

Closed
wants to merge 4 commits into from
Closed

Added folder to save files #6

wants to merge 4 commits into from

Conversation

arsaboo
Copy link
Contributor

@arsaboo arsaboo commented Jun 4, 2022

Currently, fmdpy saves everything in the root folder, making importing difficult (for example, beets only imports files in folders). Added an artist folder under which files will be saved (we can even use album, if you prefer that). This is the same format that is used by other similar programs (e.g., deemix).

@arsaboo
Copy link
Contributor Author

arsaboo commented Jun 4, 2022

@Liupold not sure how to handle the file path. There are a few errors that I am not sure how to handle. Can you take a look into this...thanks!

@Liupold
Copy link
Owner

Liupold commented Jun 5, 2022

I think a better way of doing this is using the config file. default_directoy and output_file_name can support the string replacement supported by player_cmd (we can add more if need be). But before the folder / file is created a safe check must be performed on the path as some operating system doesn't support some folder / file names. This will provide what you want + this will also preserve the current behaviour. What do you think ?

@Liupold
Copy link
Owner

Liupold commented Jun 5, 2022

This can be used:

import os, re

def sanitize_filename(s, restricted=False):
    if s == '':
        return ''

    def replace_insane(char):
        if char == '\n':
            return '_ '
        elif char == '?' or ord(char) < 32 or ord(char) == 127:
            return ''
        elif char == '"':
            return '' if restricted else '\''
        elif char == ':':
            return '___-' if restricted else '_ _-'
        elif char in '\\/|*<>':
            return '__'
        if restricted and (char in '!&\'()[]{}$;`^,#' or char.isspace() or ord(char) > 127):
            return '__'
        return char

    s = re.sub(r'[0-9]+(?::[0-9]+)+',
            lambda m: m.group(0).replace(':', '_'), s) # Handle timestamps
    result = ''.join(map(replace_insane, s))

    # Remove repeated substitute chars
    result = re.sub('(_.)(?:(?=\\1)..)+', r'\1', result)
    STRIP_RE = '(?:_.|[ _-])*'

    # Remove substitute chars from start/end
    result = re.sub(f'^_.{STRIP_RE}|{STRIP_RE}_.$', '', result)

    while '__' in result:
        result = result.replace('__', '_')
    result = result.strip('_')
    # Common case of "Foreign band name - English song title"
    if restricted and result.startswith('-_'):
        result = result[2:]
    if result.startswith('-'):
        result = '_' + result[len('-'):]
    result = result.lstrip('.')
    if not result:
        result = '_'
    return result

@arsaboo
Copy link
Contributor Author

arsaboo commented Jun 5, 2022

The output_file_name option sounds great and should work for everyone. You clearly have thought more about this, so I am going to close this PR and hope that you can incorporate this feature..thanks!

@arsaboo arsaboo closed this Jun 5, 2022
@Liupold
Copy link
Owner

Liupold commented Mar 12, 2023

This feature will be available from version 0.6.

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