A Python UPnP Media Server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.0 KiB

  1. #!/usr/bin/env python
  2. def checksum(n):
  3. ret = 0
  4. while n > 0:
  5. n, m = divmod(n, 10)
  6. ret += m
  7. return ret
  8. def discid(tracks):
  9. '''Pass in a list of tuples. Each tuple must contain
  10. (minutes, seconds) of the track. The last tuple in the list should
  11. contain the start of lead out.'''
  12. last = len(tracks) - 1
  13. tracksms = map(lambda x: x[0] * 60 + x[1], tracks)
  14. n = sum(map(checksum, tracksms[:-1]))
  15. t = tracksms[-1] - tracksms[0]
  16. discid = (long(n) % 0xff) << 24 | t << 8 | last
  17. ret = [ discid, last ]
  18. try:
  19. tracksframes = map(lambda x: x[0] * 60 * 75 + x[1] * 75 + x[2], tracks)
  20. ret.extend(tracksframes[:-1])
  21. ret.append(tracksms[-1])
  22. except IndexError:
  23. tracksframes = map(lambda x: x[0] * 60 * 75 + x[1] * 75, tracks)
  24. ret.extend(tracksframes[:-1])
  25. ret.append(tracksms[-1])
  26. return ret
  27. if __name__ == '__main__':
  28. tracks = [ (0, 3, 71), (5, 44, 0) ]
  29. tracksdiskinfo = [ 0x03015501, 1, 296, 344 ]
  30. diskinfo = discid(tracks)
  31. assert diskinfo == tracksdiskinfo
  32. print '%08x' % diskinfo[0],
  33. print ' '.join(map(str, diskinfo[1:]))