mirror of
https://github.com/beetbox/beets.git
synced 2025-12-15 13:07:09 +01:00
Move raw_seconds_short to beets.util
This commit is contained in:
parent
0e64275993
commit
4afdbdfdf4
4 changed files with 15 additions and 17 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue