|
4 | 4 | # Usage is as follows: |
5 | 5 | # |
6 | 6 | # import readcd |
7 | | -# r = readcd.Readcd().init() |
8 | | -# c = Cddb().init(r.gettrackinfo()) |
| 7 | +# r = readcd.Readcd() |
| 8 | +# c = Cddb(r.gettrackinfo()) |
9 | 9 | # |
10 | 10 | # Now you can use c.artist, c.title and c.track[trackno] (where trackno |
11 | 11 | # starts at 1). When the CD is not recognized, all values will be the empty |
@@ -55,7 +55,7 @@ def tochash(toc): |
55 | 55 | return hash |
56 | 56 |
|
57 | 57 | class Cddb: |
58 | | - def init(self, tracklist): |
| 58 | + def __init__(self, tracklist): |
59 | 59 | if posix.environ.has_key('CDDB_PATH'): |
60 | 60 | path = posix.environ['CDDB_PATH'] |
61 | 61 | cddb_path = string.splitfields(path, ',') |
@@ -104,7 +104,7 @@ def init(self, tracklist): |
104 | 104 | except IOError: |
105 | 105 | pass |
106 | 106 | if not hasattr(self, 'file'): |
107 | | - return self |
| 107 | + return |
108 | 108 | import regex |
109 | 109 | reg = regex.compile('^\\([^.]*\\)\\.\\([^:]*\\):\t\\(.*\\)') |
110 | 110 | while 1: |
@@ -138,14 +138,17 @@ def init(self, tracklist): |
138 | 138 | continue |
139 | 139 | self.track[trackno] = value |
140 | 140 | f.close() |
141 | | - return self |
142 | 141 |
|
143 | 142 | def write(self): |
| 143 | + import posixpath |
144 | 144 | if posix.environ.has_key('CDDB_WRITE_DIR'): |
145 | 145 | dir = posix.environ['CDDB_WRITE_DIR'] |
146 | 146 | else: |
147 | 147 | dir = posix.environ['HOME'] + '/' + _cddbrc |
148 | 148 | file = dir + '/' + self.id + '.rdb' |
| 149 | + if posixpath.exists(file): |
| 150 | + # make backup copy |
| 151 | + posix.rename(file, file + '~') |
149 | 152 | f = open(file, 'w') |
150 | 153 | f.write('album.title:\t' + self.title + '\n') |
151 | 154 | f.write('album.artist:\t' + self.artist + '\n') |
|
0 commit comments