Hi all, This was posted long ago. I tried to compress a mp3 file but i couldnt get the keycode+".out" file which is of size 1 bit. instead it is printed to STDOUT. i am usng python 2.4 . i understand that the keycode is embedded in the filename itself. Is it a problem with python not able to create a file with such a big filename ? any workarounds ?
regards, KM ---------------------------------------------------------------------------- On Thu, Apr 14, 2005 at 01:49:22PM +0200, Fredrik Lundh wrote: > Will McGugan wrote: > > > Please implement this as a Python module. I would like to compress my mp3 > > collection to single > > bits. > > here's the magic algorithm (somewhat simplified): > > def algorithm(data): > m = 102021 # magic constant > d = [int(c) for c in str(1*2*3*4*5*m+5+4+2+1)] > x = [ord(c) for c in hex(1+2+4+5+m*5*4*3*2*1)] > x[d[0]*d[1]*d[2]] = x[d[-1]] + sum(d) - d[d[-d[-1]-1]] + d[0] > x = __import__("".join(chr(c) for c in x[d[0]*d[1]:])).encodestring > return "".join(x(data).split("\n")).rstrip("="), sum(d)-sum(reversed(d)) > > and here's a driver for your MP3 collection: > > import glob > > def compress(filename): > data = open(filename, "rb").read() > keycode, bit = algorithm(data) > file = open(keycode + ".out", "wb") > file.write(chr(bit)) > file.close() > print "compressed", filename, > print len(data), "=>", 1, round(100.0/len(data), 3), "%" > > for file in glob.glob("*.mp3"): > compress(file) > > </F> > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list