Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

some cleanup

  • Loading branch information...
commit 0413f25243e70e4e4e5a2e54a1a08e2c0edc7bd4 1 parent 6df1e76
@zhaoz authored
Showing with 12 additions and 15 deletions.
  1. +12 −15 muname.py
View
27 muname.py
@@ -16,25 +16,22 @@
SUPPORTED_TYPES = ['audio/mpeg', 'audio/ogg']
TAGS = ['artist', 'track', 'album', 'album_artist', 'title', 'genre']
-DEFAULT_FORMAT = '{artist}/{album}/{track} - {title}'
+DEFAULT_OUTPUT_FORMAT = '{artist}/{album}/{track} - {title}'
_TRACK_RE = re.compile(r'^\d+')
_FILE_ESCAPE_RE = re.compile(r'([/])')
-_SAFE_TRANS_TABLE = string.maketrans(
- ':',
- '_'
- )
+_SAFE_TRANS_TABLE = string.maketrans(':', '_')
-def GetType(path):
- return mimetypes.guess_type(path)[0]
-
-
-def IsSong(path):
- return GetType(path) in SUPPORTED_TYPES
+def SanitizeFilename(name):
+ """Given a name, make sure that it can be made a file cleanly.
+ Args:
+ name: Filename.
-def SanitizeFilename(name):
+ Returns:
+ Sanitized filename.
+ """
return _FILE_ESCAPE_RE.sub(r'\\\1',
name.translate(_SAFE_TRANS_TABLE))
@@ -92,7 +89,7 @@ def _GetTagInfo(self):
def GetSong(path):
- t = GetType(path)
+ t = mimetypes.guess_type(path)[0]
if t == 'audio/mpeg':
return Mp3(path)
@@ -113,7 +110,7 @@ def _ParseFormatString(path):
class Collection(object):
"""A collection of songs."""
- def __init__(self, format_string=DEFAULT_FORMAT):
+ def __init__(self, format_string=DEFAULT_OUTPUT_FORMAT):
self._format = format_string
self._path_parts = _ParseFormatString(self._format)
self._songs = []
@@ -184,7 +181,7 @@ class MuName(object):
"""
def __init__(self, destination=None, source=None, no_action=True,
- output_format=DEFAULT_FORMAT):
+ output_format=DEFAULT_OUTPUT_FORMAT):
"""MuName __init__
Initialize the MuName object with given parameters.
Please sign in to comment.
Something went wrong with that request. Please try again.