Skip to content

Commit 1adb2a2

Browse files
committed
draw a progress bar while playing a song
1 parent ed6f7ad commit 1adb2a2

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

mpsyt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2323
"""
2424

2525
from __future__ import print_function
26+
from math import ceil
2627

2728
__version__ = "0.01.38"
2829
__author__ = "nagev"
@@ -1345,15 +1346,21 @@ def make_status_line(match_object):
13451346
pct = (current / total * 100)
13461347

13471348
except ZeroDivisionError:
1348-
pct = '?'
1349+
pct = 0
13491350

1350-
return " %s%s%s (%.0f%%)" % (
1351+
status_line = " %s%s%s %s" % (
13511352
match_object.group('elapsed_h') or '',
13521353
match_object.group('elapsed_m') or '00:',
13531354
match_object.group('elapsed_s'),
1354-
pct
1355+
("(%.0f%%)" % pct).ljust(6)
13551356
)
13561357

1358+
progress_bar_size = 30
1359+
progress = int(ceil(pct / 100 * progress_bar_size))
1360+
status_line += " [%s]" % ("=" * (progress - 1) + ">").ljust(progress_bar_size, '.')
1361+
1362+
return status_line
1363+
13571364

13581365
def _search(url, progtext, qs=None, splash=True):
13591366
""" Perform memoized url fetch, display progtext. """

0 commit comments

Comments
 (0)