Also use CDDB_PATH and CDDB_WRITE_DIR environment variables in cddb.py.
# Usage is as follows:
#
# import readcd
-# r = readcd.Readcd().init()
-# c = Cddb().init(r.gettrackinfo())
+# r = readcd.Readcd()
+# c = Cddb(r.gettrackinfo())
#
# Now you can use c.artist, c.title and c.track[trackno] (where trackno
# starts at 1). When the CD is not recognized, all values will be the empty
return hash
class Cddb:
- def init(self, tracklist):
+ def __init__(self, tracklist):
if posix.environ.has_key('CDDB_PATH'):
path = posix.environ['CDDB_PATH']
cddb_path = string.splitfields(path, ',')
except IOError:
pass
if not hasattr(self, 'file'):
- return self
+ return
import regex
reg = regex.compile('^\\([^.]*\\)\\.\\([^:]*\\):\t\\(.*\\)')
while 1:
continue
self.track[trackno] = value
f.close()
- return self
def write(self):
+ import posixpath
if posix.environ.has_key('CDDB_WRITE_DIR'):
dir = posix.environ['CDDB_WRITE_DIR']
else:
dir = posix.environ['HOME'] + '/' + _cddbrc
file = dir + '/' + self.id + '.rdb'
+ if posixpath.exists(file):
+ # make backup copy
+ posix.rename(file, file + '~')
f = open(file, 'w')
f.write('album.title:\t' + self.title + '\n')
f.write('album.artist:\t' + self.artist + '\n')
# Usage is as follows:
#
# import readcd
-# r = readcd.Readcd().init()
-# c = Cdplayer().init(r.gettrackinfo())
+# r = readcd.Readcd()
+# c = Cdplayer(r.gettrackinfo())
#
# Now you can use c.artist, c.title and c.track[trackno] (where trackno
# starts at 1). When the CD is not recognized, all values will be the empty
cdplayerrc = '.cdplayerrc'
class Cdplayer:
- def init(self, tracklist):
+ def __init__(self, tracklist):
import string
self.artist = ''
self.title = ''
import posix
f = open(posix.environ['HOME'] + '/' + cdplayerrc, 'r')
except IOError:
- return self
+ return
import regex
reg = regex.compile('^\\([^:]*\\):\t\\(.*\\)')
s = self.id + '.'
trackno = string.atoi(name[6:])
self.track[trackno] = value
f.close()
- return self
def write(self):
import posix
Initialization.
===============
-r = readcd.Readcd().init([cd-player [, mode]])
+r = readcd.Readcd([cd-player [, mode]])
The optional arguments are the name of the CD device and the mode.
When "mode" is not specified, it defaults to 'r' (which is the only
func(arg, cb_type, data)
class Readcd:
- def init(self, *arg):
+ def __init__(self, *arg):
if len(arg) == 0:
self.player = cd.open()
elif len(arg) == 1:
self.end = 0
self.status = None
self.trackinfo = None
- return self
def eject(self):
self.player.eject()
# Usage is as follows:
#
# import readcd
-# r = readcd.Readcd().init()
-# c = Cddb().init(r.gettrackinfo())
+# r = readcd.Readcd()
+# c = Cddb(r.gettrackinfo())
#
# Now you can use c.artist, c.title and c.track[trackno] (where trackno
# starts at 1). When the CD is not recognized, all values will be the empty
return hash
class Cddb:
- def init(self, tracklist):
+ def __init__(self, tracklist):
if posix.environ.has_key('CDDB_PATH'):
path = posix.environ['CDDB_PATH']
cddb_path = string.splitfields(path, ',')
except IOError:
pass
if not hasattr(self, 'file'):
- return self
+ return
import regex
reg = regex.compile('^\\([^.]*\\)\\.\\([^:]*\\):\t\\(.*\\)')
while 1:
continue
self.track[trackno] = value
f.close()
- return self
def write(self):
+ import posixpath
if posix.environ.has_key('CDDB_WRITE_DIR'):
dir = posix.environ['CDDB_WRITE_DIR']
else:
dir = posix.environ['HOME'] + '/' + _cddbrc
file = dir + '/' + self.id + '.rdb'
+ if posixpath.exists(file):
+ # make backup copy
+ posix.rename(file, file + '~')
f = open(file, 'w')
f.write('album.title:\t' + self.title + '\n')
f.write('album.artist:\t' + self.artist + '\n')
# Usage is as follows:
#
# import readcd
-# r = readcd.Readcd().init()
-# c = Cdplayer().init(r.gettrackinfo())
+# r = readcd.Readcd()
+# c = Cdplayer(r.gettrackinfo())
#
# Now you can use c.artist, c.title and c.track[trackno] (where trackno
# starts at 1). When the CD is not recognized, all values will be the empty
cdplayerrc = '.cdplayerrc'
class Cdplayer:
- def init(self, tracklist):
+ def __init__(self, tracklist):
import string
self.artist = ''
self.title = ''
import posix
f = open(posix.environ['HOME'] + '/' + cdplayerrc, 'r')
except IOError:
- return self
+ return
import regex
reg = regex.compile('^\\([^:]*\\):\t\\(.*\\)')
s = self.id + '.'
trackno = string.atoi(name[6:])
self.track[trackno] = value
f.close()
- return self
def write(self):
import posix
Initialization.
===============
-r = readcd.Readcd().init([cd-player [, mode]])
+r = readcd.Readcd([cd-player [, mode]])
The optional arguments are the name of the CD device and the mode.
When "mode" is not specified, it defaults to 'r' (which is the only
func(arg, cb_type, data)
class Readcd:
- def init(self, *arg):
+ def __init__(self, *arg):
if len(arg) == 0:
self.player = cd.open()
elif len(arg) == 1:
self.end = 0
self.status = None
self.trackinfo = None
- return self
def eject(self):
self.player.eject()