annotate vixm/util.py @ 32:f97eb9f0c207 master

Add random song selection for default queue
author Josef "Jeff" Sipek <jeffpc@josefsipek.net>
date Fri, 03 Nov 2006 23:26:35 -0500
parents dfcf1a46fc56
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21
dfcf1a46fc56 Added GPLv2 file & copyright headers
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 12
diff changeset
1 # util.py - utility functions
dfcf1a46fc56 Added GPLv2 file & copyright headers
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 12
diff changeset
2 #
dfcf1a46fc56 Added GPLv2 file & copyright headers
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 12
diff changeset
3 # Copyright (C) 2006 Josef "Jeff" Sipek <jeffpc@josefsipek.net>
dfcf1a46fc56 Added GPLv2 file & copyright headers
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 12
diff changeset
4 #
dfcf1a46fc56 Added GPLv2 file & copyright headers
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 12
diff changeset
5 # This program is free software; you can redistribute it and/or modify
dfcf1a46fc56 Added GPLv2 file & copyright headers
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 12
diff changeset
6 # it under the terms of the GNU General Public License version 2 as
dfcf1a46fc56 Added GPLv2 file & copyright headers
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 12
diff changeset
7 # published by the Free Software Foundation.
dfcf1a46fc56 Added GPLv2 file & copyright headers
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 12
diff changeset
8
6
50745af6a63b Print song lengths in something better than number of milliseconds, added
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff changeset
9 def strtime(t):
50745af6a63b Print song lengths in something better than number of milliseconds, added
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff changeset
10 ms = t % 1000
50745af6a63b Print song lengths in something better than number of milliseconds, added
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff changeset
11 t /= 1000
50745af6a63b Print song lengths in something better than number of milliseconds, added
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff changeset
12
50745af6a63b Print song lengths in something better than number of milliseconds, added
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff changeset
13 s = t % 60
50745af6a63b Print song lengths in something better than number of milliseconds, added
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff changeset
14 t /= 60
50745af6a63b Print song lengths in something better than number of milliseconds, added
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff changeset
15
50745af6a63b Print song lengths in something better than number of milliseconds, added
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff changeset
16 ret = "%02d.%03d" % (s, ms)
50745af6a63b Print song lengths in something better than number of milliseconds, added
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff changeset
17
50745af6a63b Print song lengths in something better than number of milliseconds, added
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff changeset
18 if t != 0:
50745af6a63b Print song lengths in something better than number of milliseconds, added
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff changeset
19 m = t
50745af6a63b Print song lengths in something better than number of milliseconds, added
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff changeset
20 ret = "%d:%s" % (m, ret)
50745af6a63b Print song lengths in something better than number of milliseconds, added
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff changeset
21
50745af6a63b Print song lengths in something better than number of milliseconds, added
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff changeset
22 return ret
12
b5370c42288b Code refactoring & implemented help command
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 6
diff changeset
23
b5370c42288b Code refactoring & implemented help command
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 6
diff changeset
24 def special2int(s):
b5370c42288b Code refactoring & implemented help command
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 6
diff changeset
25 if s == '$':
b5370c42288b Code refactoring & implemented help command
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 6
diff changeset
26 return -1
b5370c42288b Code refactoring & implemented help command
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 6
diff changeset
27 if s == '':
b5370c42288b Code refactoring & implemented help command
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 6
diff changeset
28 return 1
b5370c42288b Code refactoring & implemented help command
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 6
diff changeset
29 return int(s)
b5370c42288b Code refactoring & implemented help command
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 6
diff changeset
30
b5370c42288b Code refactoring & implemented help command
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 6
diff changeset
31 def fixupint(i, m):
b5370c42288b Code refactoring & implemented help command
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 6
diff changeset
32 if i == -1:
b5370c42288b Code refactoring & implemented help command
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 6
diff changeset
33 return m
b5370c42288b Code refactoring & implemented help command
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 6
diff changeset
34 return i
b5370c42288b Code refactoring & implemented help command
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 6
diff changeset
35