-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
Conversation
@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! |
I think a better way of doing this is using the config file. |
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 |
The |
This feature will be available from version 0.6. |
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).