Now Playing on Flynn's Arcade Radio: Sonic 3D Blast - Title

Armagetron Servers

Turbo Teamplay: No players online
Brakes: No players online
Flynn's Arcade Network:
1 players online

Welcome!

Greetings, Programs! Welcome to Flynn's Arcade! Here you will find my random musings on life and technology, as well as various interesting computer projects of mine. The name of my site comes from the 1982 sci-fi classic TRON. I am a huge fan of the movie and of classic video gaming and computing. As such, the Flynn's Arcade Radio stream plays various original and remixed music from those bygone days, as well as some of the best newer video game and chiptune music. I also host quite a few Armagetron Advanced servers to help carry on the spirit of classic gaming and serve the TRON community.

C10ud


Python Vorbis Comment Parser E-mail
Written by C10ud   
Tuesday, 07 April 2009

So, I was working on a re-write of icesDJ, a DJ interface to ices (allows for playlist manipulation and such), and I decided to do it in Python. The basic idea is that ices will call one of my scripts, songpicker.py, which will spit out the next song to play based on 1) DJ Requests (highest priority), 2) User requests (second priority), and finally 3) Random selection based on user ratings. My dilemma was that the ratings and requests are stored in a database, but I didn't have a way of mapping between song titles and the file names they correspond to. What I wanted to do was to go through the media directory periodically and populate the database with the tag data from the files, but was extremely disappointed to find that there were very few Python vorbis libraries of any sort and the ones that existed depended on multiple other libraries. Once I finally got one to build, it crashed upon importing the module.

 

So, what do I do when I'm fed up with existing software (or lack thereof) and not feeling like doing my (boring) schoolwork? I go write some code! After deeply meditating on the Vorbis file specification's header section for a very long time I finally realized how simply the header was setup. Armed with my trusty (not so) dusty hex editor, I opened up an ogg file, played around with my ideas in the Python interpreter, and soon came up with a working function that will read any ogg/vorbis file and extract the comment header information as a dictionary. The code is pasted below for the benefit of whoever may need it. (Yes, I realize it is somewhat inefficient and I will add stuff later to only read in the necessary header info).

def getVorbisComments(filename):
  '''
    Parses the given input file and returns the vorbis comments as a dictionary
  '''
  comments = {}
 
  fp = open(filename)
 
  # Read in the file
  data = fp.read().split('vorbis')[2]
 
  fp.close()
 
  # Read in the length of the first field (vendor string)
  fieldLen = int(''.join([str(ord(c)) for c in data[3::-1]]))
 
  # Remove the first field (vendor string)
  data = data[fieldLen+4:]
 
  # Read in the length of the comment fields
  numComments = int(''.join([str(ord(c)) for c in data[3::-1]]))
 
  # Remove the comment field length data
  data = data[4:]
 
  # Read in the comment fields
  for i in range(numComments):
    fieldLen = int(''.join([str(ord(c)) for c in data[3::-1]]))
    fieldData = data[4:fieldLen+4].split('=')
   
    comments[fieldData[0]] = fieldData[1]
   
    data = data[fieldLen+4:]
 
  return comments


Quote this article on your site | Print

Be first to comment this article

Write Comment
  • Please keep the topic of messages relevant to the subject of the article.
  • Personal verbal attacks will be deleted.
  • Please don't use comments to plug your web site. Such material will be removed.
  • Just ensure to *Refresh* your browser for a new security code to be displayed prior to clicking on the 'Send' button.
  • Keep in mind that the above process only applies if you simply entered the wrong security code.
Name:
E-mail
Homepage
BBCode:Web AddressEmail AddressBold TextItalic TextUnderlined TextQuoteCodeOpen ListList ItemClose List
Comment:



Code:* Code
I wish to be contacted by email regarding additional comments

Powered by AkoComment Tweaked Special Edition v.1.4.6
AkoComment © Copyright 2004 by Arthur Konze - www.mamboportal.com
All right reserved

Last Updated ( Tuesday, 27 October 2009 )
 

Radio Top 20 Tracks

1. Anamanaguchi - Video Challenge

2. Aurasil - Yie ar kung fu

3. Bit Shifter - Hexadecimal Genome

4. Bit Shifter - The Information Chase

5. DJ Mitch - Noisy Pillars (Ibiza Sunset Mix - Remastered)

6. FFmusicDJ - HiddenPalaceFuture

7. Final Fantasy 7 A World of Piano OC ReMix

8. Final Fantasy 8 EyesOnMe(NotFayWong) OC ReMix

9. Hadyn - PartyInTheEmeraldHills

10. Lagerfeldt - Angel (Merry X-Max)

11. Lagerfeldt - Sweet (My Sun Shines On)

12. Random - Spontaneous Devotion

13. Rayza - Sonic the Hedgehog Green Hill Zone (Euroclub '95 Mix) OC ReMix

14. Saberpulse - Hey Kate

15. She - Nebula

16. She - Pioneer

17. Sonic 3D Blast Snow OC ReMix

18. Trance-Canada - Sonic the Hedgehog 3 Ice Attack OC ReMix

19. USK - Little Sound Disko04

20. USK - Little Sound Disko05

FreeBSD Logo
up 24 days
(C) 2007 - 2010 Flynn's Arcade
Joomla! is Free Software released under the GNU/GPL License.