mirror of
https://github.com/SoongNoonien/mpdevil.git
synced 2023-08-10 21:12:44 +03:00
added a fallback string to "Duration"
This commit is contained in:
32
bin/mpdevil
32
bin/mpdevil
@ -441,15 +441,29 @@ class MPRISInterface: # TODO emit Seeked if needed
|
|||||||
# MPD client wrapper #
|
# MPD client wrapper #
|
||||||
######################
|
######################
|
||||||
|
|
||||||
class Duration(float):
|
class Duration():
|
||||||
def __str__(self):
|
def __init__(self, value=None):
|
||||||
delta=datetime.timedelta(seconds=int(self))
|
if value is None:
|
||||||
if delta.days > 0:
|
self._fallback=True
|
||||||
days=ngettext("{days} day", "{days} days", delta.days).format(days=delta.days)
|
self._value=0.0
|
||||||
time_string=f"{days}, {datetime.timedelta(seconds=delta.seconds)}"
|
|
||||||
else:
|
else:
|
||||||
time_string=str(delta).lstrip("0").lstrip(":")
|
self._fallback=False
|
||||||
return time_string.replace(":", "∶") # use 'ratio' as delimiter
|
self._value=float(value)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
if self._fallback:
|
||||||
|
return "––∶––"
|
||||||
|
else:
|
||||||
|
delta=datetime.timedelta(seconds=int(self._value))
|
||||||
|
if delta.days > 0:
|
||||||
|
days=ngettext("{days} day", "{days} days", delta.days).format(days=delta.days)
|
||||||
|
time_string=f"{days}, {datetime.timedelta(seconds=delta.seconds)}"
|
||||||
|
else:
|
||||||
|
time_string=str(delta).lstrip("0").lstrip(":")
|
||||||
|
return time_string.replace(":", "∶") # use 'ratio' as delimiter
|
||||||
|
|
||||||
|
def __float__(self):
|
||||||
|
return self._value
|
||||||
|
|
||||||
class LastModified():
|
class LastModified():
|
||||||
def __init__(self, date):
|
def __init__(self, date):
|
||||||
@ -511,7 +525,7 @@ class Song(collections.UserDict):
|
|||||||
if key == "title":
|
if key == "title":
|
||||||
return MultiTag([os.path.basename(self.data["file"])])
|
return MultiTag([os.path.basename(self.data["file"])])
|
||||||
elif key == "duration":
|
elif key == "duration":
|
||||||
return "0"
|
return Duration()
|
||||||
else:
|
else:
|
||||||
return MultiTag([""])
|
return MultiTag([""])
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user