equal
deleted
inserted
replaced
1 #!/usr/bin/python |
|
2 |
|
3 import dircache, os.path |
1 import dircache, os.path |
4 from sys import stderr |
2 from sys import stderr |
5 import readline |
3 import readline |
|
4 |
|
5 def sql_quote(str): |
|
6 return str.replace("'", "''") |
|
7 |
|
8 def get_song_info(path): |
|
9 "Return (artist, title) pair from path." |
|
10 artist, title = None, None |
|
11 if os.path.isfile(path): |
|
12 if path[-4:] == '.mp3': |
|
13 from ID3 import ID3 |
|
14 id3 = ID3(path) |
|
15 try: |
|
16 artist = id3['ARTIST'] |
|
17 except: |
|
18 pass |
|
19 try: |
|
20 title = id3['TITLE'] |
|
21 except: |
|
22 pass |
|
23 elif path[-4:] == '.ogg': |
|
24 from ogg.vorbis import VorbisFile |
|
25 vf = VorbisFile(path) |
|
26 vc = vf.comment() |
|
27 try: |
|
28 artist = vc['ARTIST'][0] |
|
29 except: |
|
30 pass |
|
31 try: |
|
32 title = vc['TITLE'][0] |
|
33 except: |
|
34 pass |
|
35 return artist, title |
|
36 |
|
37 def strdelay(seconds): |
|
38 secs = abs(round(seconds)) |
|
39 minutes = secs / 60; |
|
40 hours = minutes / 60; |
|
41 days = hours / 24; |
|
42 secs = secs % 60; |
|
43 minutes %= 60; |
|
44 hours %= 24; |
|
45 |
|
46 if seconds < 0: |
|
47 s = "-" |
|
48 else: |
|
49 s = "" |
|
50 if days >= 1: |
|
51 s += "%dd %dh" % (days, hours) |
|
52 elif hours >= 1: |
|
53 s += "%dh%02d" % (hours, minutes) |
|
54 elif minutes >= 1: |
|
55 s += "%d'%02d\"" % (minutes, secs) |
|
56 else: |
|
57 s += "%d\"" % (secs) |
|
58 return s |
6 |
59 |
7 def set_file_completer(): |
60 def set_file_completer(): |
8 readline.set_completer_delims('') |
61 readline.set_completer_delims('') |
9 readline.set_completer(_file_completer) |
62 readline.set_completer(_file_completer) |
10 |
63 |