utils.py
branchimmsview
changeset 33 ad808d18c693
parent 31 13f56bb29b96
--- a/utils.py	Sun Feb 08 17:27:21 2004 -0500
+++ b/utils.py	Mon Feb 09 23:29:08 2004 -0500
@@ -1,9 +1,62 @@
-#!/usr/bin/python
-
 import dircache, os.path
 from sys import stderr
 import readline
 
+def sql_quote(str):
+    return str.replace("'", "''")
+
+def get_song_info(path):
+    "Return (artist, title) pair from path."
+    artist, title = None, None
+    if os.path.isfile(path):
+        if path[-4:] == '.mp3':
+            from ID3 import ID3
+            id3 = ID3(path)
+            try:
+                artist = id3['ARTIST']
+            except:
+                pass
+            try:
+                title = id3['TITLE']
+            except:
+                pass
+        elif path[-4:] == '.ogg':
+            from ogg.vorbis import VorbisFile
+            vf = VorbisFile(path)
+            vc = vf.comment()
+            try:
+                artist = vc['ARTIST'][0]
+            except:
+                pass
+            try:
+                title = vc['TITLE'][0]
+            except:
+                pass
+    return artist, title
+
+def strdelay(seconds):
+    secs = abs(round(seconds))
+    minutes = secs / 60;
+    hours = minutes / 60;
+    days = hours / 24;
+    secs = secs % 60;
+    minutes %= 60;
+    hours %= 24;
+
+    if seconds < 0:
+            s = "-"
+    else:
+            s = ""
+    if days >= 1:
+            s += "%dd %dh" % (days, hours)
+    elif hours >= 1:
+            s += "%dh%02d" % (hours, minutes)
+    elif minutes >= 1:
+            s += "%d'%02d\"" % (minutes, secs)
+    else:
+            s += "%d\"" % (secs)
+    return s
+
 def set_file_completer():
     readline.set_completer_delims('')
     readline.set_completer(_file_completer)