summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSjoerd Mullender <sjoerd@acm.org>1994-09-06 16:19:03 (GMT)
committerSjoerd Mullender <sjoerd@acm.org>1994-09-06 16:19:03 (GMT)
commite202c38d76d2d3946fc16baa9f6e536871779802 (patch)
tree93d1c542b17b0e5d1f12581b6160e7bc88731783 /Lib
parent1f05754640c114ccce5746bf93de03d8d78c8c5b (diff)
downloadcpython-e202c38d76d2d3946fc16baa9f6e536871779802.zip
cpython-e202c38d76d2d3946fc16baa9f6e536871779802.tar.gz
cpython-e202c38d76d2d3946fc16baa9f6e536871779802.tar.bz2
Can now also give a hashed ID to Cddb.
Diffstat (limited to 'Lib')
-rwxr-xr-xLib/irix5/cddb.py97
-rwxr-xr-xLib/plat-irix5/cddb.py97
2 files changed, 112 insertions, 82 deletions
diff --git a/Lib/irix5/cddb.py b/Lib/irix5/cddb.py
index 0dee709..68d26c0 100755
--- a/Lib/irix5/cddb.py
+++ b/Lib/irix5/cddb.py
@@ -14,7 +14,7 @@
# You can then use c.write() to write out the changed values to the
# .cdplayerrc file.
-import string, posix
+import string, posix, os
_cddbrc = '.cddb'
_DB_ID_NTRACKS = 5
@@ -56,45 +56,15 @@ def tochash(toc):
class Cddb:
def __init__(self, tracklist):
- if posix.environ.has_key('CDDB_PATH'):
- path = posix.environ['CDDB_PATH']
+ if os.environ.has_key('CDDB_PATH'):
+ path = os.environ['CDDB_PATH']
cddb_path = string.splitfields(path, ',')
else:
- home = posix.environ['HOME']
+ home = os.environ['HOME']
cddb_path = [home + '/' + _cddbrc]
- self.artist = ''
- self.title = ''
- if type(tracklist) == type(''):
- t = []
- for i in range(2, len(tracklist), 4):
- t.append((None, \
- (string.atoi(tracklist[i:i+2]), \
- string.atoi(tracklist[i+2:i+4]))))
- tracklist = t
- ntracks = len(tracklist)
- self.track = [None] + [''] * ntracks
- self.id = _dbid((ntracks >> 4) & 0xF) + _dbid(ntracks & 0xF)
- if ntracks <= _DB_ID_NTRACKS:
- nidtracks = ntracks
- else:
- nidtracks = _DB_ID_NTRACKS - 1
- min = 0
- sec = 0
- for track in tracklist:
- start, length = track
- min = min + length[0]
- sec = sec + length[1]
- min = min + sec / 60
- sec = sec % 60
- self.id = self.id + _dbid(min) + _dbid(sec)
- for i in range(nidtracks):
- start, length = tracklist[i]
- self.id = self.id + _dbid(length[0]) + _dbid(length[1])
- self.toc = string.zfill(ntracks, 2)
- for track in tracklist:
- start, length = track
- self.toc = self.toc + string.zfill(length[0], 2) + \
- string.zfill(length[1], 2)
+
+ self._get_id(tracklist)
+
for dir in cddb_path:
file = dir + '/' + self.id + '.rdb'
try:
@@ -103,6 +73,10 @@ class Cddb:
break
except IOError:
pass
+ ntracks = string.atoi(self.id[:2], 16)
+ self.artist = ''
+ self.title = ''
+ self.track = [None] + [''] * ntracks
if not hasattr(self, 'file'):
return
import regex
@@ -123,6 +97,8 @@ class Cddb:
elif name2 == 'title':
self.title = value
elif name2 == 'toc':
+ if not self.toc:
+ self.toc = value
if self.toc != value:
print 'toc\'s don\'t match'
elif name1[:5] == 'track':
@@ -142,7 +118,7 @@ class Cddb:
track = self.track[i]
# if track title starts with `,', use initial part
# of previous track's title
- if track[0] == ',':
+ if track and track[0] == ',':
try:
off = string.index(self.track[i - 1],
',')
@@ -152,12 +128,51 @@ class Cddb:
self.track[i] = self.track[i-1][:off] \
+ track
+ def _get_id(self, tracklist):
+ # fill in self.id and self.toc.
+ # if the argument is a string ending in .rdb, the part
+ # upto the suffix is taken as the id.
+ if type(tracklist) == type(''):
+ if tracklist[-4:] == '.rdb':
+ self.id = tracklist[:-4]
+ self.toc = ''
+ return
+ t = []
+ for i in range(2, len(tracklist), 4):
+ t.append((None, \
+ (string.atoi(tracklist[i:i+2]), \
+ string.atoi(tracklist[i+2:i+4]))))
+ tracklist = t
+ ntracks = len(tracklist)
+ self.id = _dbid((ntracks >> 4) & 0xF) + _dbid(ntracks & 0xF)
+ if ntracks <= _DB_ID_NTRACKS:
+ nidtracks = ntracks
+ else:
+ nidtracks = _DB_ID_NTRACKS - 1
+ min = 0
+ sec = 0
+ for track in tracklist:
+ start, length = track
+ min = min + length[0]
+ sec = sec + length[1]
+ min = min + sec / 60
+ sec = sec % 60
+ self.id = self.id + _dbid(min) + _dbid(sec)
+ for i in range(nidtracks):
+ start, length = tracklist[i]
+ self.id = self.id + _dbid(length[0]) + _dbid(length[1])
+ self.toc = string.zfill(ntracks, 2)
+ for track in tracklist:
+ start, length = track
+ self.toc = self.toc + string.zfill(length[0], 2) + \
+ string.zfill(length[1], 2)
+
def write(self):
import posixpath
- if posix.environ.has_key('CDDB_WRITE_DIR'):
- dir = posix.environ['CDDB_WRITE_DIR']
+ if os.environ.has_key('CDDB_WRITE_DIR'):
+ dir = os.environ['CDDB_WRITE_DIR']
else:
- dir = posix.environ['HOME'] + '/' + _cddbrc
+ dir = os.environ['HOME'] + '/' + _cddbrc
file = dir + '/' + self.id + '.rdb'
if posixpath.exists(file):
# make backup copy
diff --git a/Lib/plat-irix5/cddb.py b/Lib/plat-irix5/cddb.py
index 0dee709..68d26c0 100755
--- a/Lib/plat-irix5/cddb.py
+++ b/Lib/plat-irix5/cddb.py
@@ -14,7 +14,7 @@
# You can then use c.write() to write out the changed values to the
# .cdplayerrc file.
-import string, posix
+import string, posix, os
_cddbrc = '.cddb'
_DB_ID_NTRACKS = 5
@@ -56,45 +56,15 @@ def tochash(toc):
class Cddb:
def __init__(self, tracklist):
- if posix.environ.has_key('CDDB_PATH'):
- path = posix.environ['CDDB_PATH']
+ if os.environ.has_key('CDDB_PATH'):
+ path = os.environ['CDDB_PATH']
cddb_path = string.splitfields(path, ',')
else:
- home = posix.environ['HOME']
+ home = os.environ['HOME']
cddb_path = [home + '/' + _cddbrc]
- self.artist = ''
- self.title = ''
- if type(tracklist) == type(''):
- t = []
- for i in range(2, len(tracklist), 4):
- t.append((None, \
- (string.atoi(tracklist[i:i+2]), \
- string.atoi(tracklist[i+2:i+4]))))
- tracklist = t
- ntracks = len(tracklist)
- self.track = [None] + [''] * ntracks
- self.id = _dbid((ntracks >> 4) & 0xF) + _dbid(ntracks & 0xF)
- if ntracks <= _DB_ID_NTRACKS:
- nidtracks = ntracks
- else:
- nidtracks = _DB_ID_NTRACKS - 1
- min = 0
- sec = 0
- for track in tracklist:
- start, length = track
- min = min + length[0]
- sec = sec + length[1]
- min = min + sec / 60
- sec = sec % 60
- self.id = self.id + _dbid(min) + _dbid(sec)
- for i in range(nidtracks):
- start, length = tracklist[i]
- self.id = self.id + _dbid(length[0]) + _dbid(length[1])
- self.toc = string.zfill(ntracks, 2)
- for track in tracklist:
- start, length = track
- self.toc = self.toc + string.zfill(length[0], 2) + \
- string.zfill(length[1], 2)
+
+ self._get_id(tracklist)
+
for dir in cddb_path:
file = dir + '/' + self.id + '.rdb'
try:
@@ -103,6 +73,10 @@ class Cddb:
break
except IOError:
pass
+ ntracks = string.atoi(self.id[:2], 16)
+ self.artist = ''
+ self.title = ''
+ self.track = [None] + [''] * ntracks
if not hasattr(self, 'file'):
return
import regex
@@ -123,6 +97,8 @@ class Cddb:
elif name2 == 'title':
self.title = value
elif name2 == 'toc':
+ if not self.toc:
+ self.toc = value
if self.toc != value:
print 'toc\'s don\'t match'
elif name1[:5] == 'track':
@@ -142,7 +118,7 @@ class Cddb:
track = self.track[i]
# if track title starts with `,', use initial part
# of previous track's title
- if track[0] == ',':
+ if track and track[0] == ',':
try:
off = string.index(self.track[i - 1],
',')
@@ -152,12 +128,51 @@ class Cddb:
self.track[i] = self.track[i-1][:off] \
+ track
+ def _get_id(self, tracklist):
+ # fill in self.id and self.toc.
+ # if the argument is a string ending in .rdb, the part
+ # upto the suffix is taken as the id.
+ if type(tracklist) == type(''):
+ if tracklist[-4:] == '.rdb':
+ self.id = tracklist[:-4]
+ self.toc = ''
+ return
+ t = []
+ for i in range(2, len(tracklist), 4):
+ t.append((None, \
+ (string.atoi(tracklist[i:i+2]), \
+ string.atoi(tracklist[i+2:i+4]))))
+ tracklist = t
+ ntracks = len(tracklist)
+ self.id = _dbid((ntracks >> 4) & 0xF) + _dbid(ntracks & 0xF)
+ if ntracks <= _DB_ID_NTRACKS:
+ nidtracks = ntracks
+ else:
+ nidtracks = _DB_ID_NTRACKS - 1
+ min = 0
+ sec = 0
+ for track in tracklist:
+ start, length = track
+ min = min + length[0]
+ sec = sec + length[1]
+ min = min + sec / 60
+ sec = sec % 60
+ self.id = self.id + _dbid(min) + _dbid(sec)
+ for i in range(nidtracks):
+ start, length = tracklist[i]
+ self.id = self.id + _dbid(length[0]) + _dbid(length[1])
+ self.toc = string.zfill(ntracks, 2)
+ for track in tracklist:
+ start, length = track
+ self.toc = self.toc + string.zfill(length[0], 2) + \
+ string.zfill(length[1], 2)
+
def write(self):
import posixpath
- if posix.environ.has_key('CDDB_WRITE_DIR'):
- dir = posix.environ['CDDB_WRITE_DIR']
+ if os.environ.has_key('CDDB_WRITE_DIR'):
+ dir = os.environ['CDDB_WRITE_DIR']
else:
- dir = posix.environ['HOME'] + '/' + _cddbrc
+ dir = os.environ['HOME'] + '/' + _cddbrc
file = dir + '/' + self.id + '.rdb'
if posixpath.exists(file):
# make backup copy