emmental/curds/playlist/playlist.py

21 lines
686 B
Python

# Copyright 2019 (c) Anna Schumaker.
class Playlist(list):
def __init__(self, name):
self.name = name
def add(self, track):
if track is not None:
self.append(track)
def runtime(self):
m, s = divmod(sum([ track.length for track in self ]), 60)
h, m = divmod(m, 60)
d, h = divmod(h, 24)
res = [ ]
if d > 0: res.append(f"{int(d)} day{'s' if d != 1 else ''}")
if h > 0: res.append(f"{int(h)} hour{'s' if h != 1 else ''}")
if m > 0: res.append(f"{int(m)} minute{'s' if m != 1 else ''}")
if s > 0: res.append(f"{int(s)} second{'s' if s != 1 else ''}")
return ", ".join(res)