diff --git a/beets/dbcore/query.py b/beets/dbcore/query.py index a33a2946a..d8a3a0ea8 100644 --- a/beets/dbcore/query.py +++ b/beets/dbcore/query.py @@ -670,9 +670,7 @@ class DurationQuery(NumericQuery): if not s: return None try: - # TODO: tidy up circular import - from beets.ui import raw_seconds_short - return raw_seconds_short(s) + return util.raw_seconds_short(s) except ValueError: try: return float(s) diff --git a/beets/library.py b/beets/library.py index d8eb9d5d3..ed6b39280 100644 --- a/beets/library.py +++ b/beets/library.py @@ -209,7 +209,7 @@ class DurationType(types.Float): def parse(self, string): try: # Try to format back hh:ss to seconds. - return beets.ui.raw_seconds_short(string) + return util.raw_seconds_short(string) except ValueError: # Fall back to a plain float.. try: diff --git a/beets/ui/__init__.py b/beets/ui/__init__.py index 3a25a03ff..c51c3acb6 100644 --- a/beets/ui/__init__.py +++ b/beets/ui/__init__.py @@ -416,19 +416,6 @@ def human_seconds_short(interval): return u'%i:%02i' % (interval // 60, interval % 60) -def raw_seconds_short(string): - """Formats a human-readable M:SS string as a float (number of seconds). - - Raises ValueError if the conversion cannot take place due to `string` not - being in the right format. - """ - match = re.match('^(\d+):([0-5]\d)$', string) - if not match: - raise ValueError('String not in M:SS format') - minutes, seconds = map(int, match.groups()) - return float(minutes * 60 + seconds) - - # Colorization. # ANSI terminal colorization code heavily inspired by pygments: diff --git a/beets/util/__init__.py b/beets/util/__init__.py index e2d09c3ab..55c599a05 100644 --- a/beets/util/__init__.py +++ b/beets/util/__init__.py @@ -843,3 +843,16 @@ def case_sensitive(path): lower = _windows_long_path_name(path.lower()) upper = _windows_long_path_name(path.upper()) return lower != upper + + +def raw_seconds_short(string): + """Formats a human-readable M:SS string as a float (number of seconds). + + Raises ValueError if the conversion cannot take place due to `string` not + being in the right format. + """ + match = re.match('^(\d+):([0-5]\d)$', string) + if not match: + raise ValueError('String not in M:SS format') + minutes, seconds = map(int, match.groups()) + return float(minutes * 60 + seconds)