3 Copyright 2005 Kenneth Hayber <ken@hayber.us>, All rights reserved.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License.
9 This program is distributed in the hope that it will be useful
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 print 'No OGG support!'
29 tag_info
= ogg
.vorbis
.VorbisFile(song
.filename
).comment().as_dict()
30 if tag_info
.has_key('TITLE'): song
.title
= tag_info
['TITLE'][0]
31 if tag_info
.has_key('TRACKNUMBER'): song
.track
= int(tag_info
['TRACKNUMBER'][0])
32 if tag_info
.has_key('ALBUM'): song
.album
= tag_info
['ALBUM'][0]
33 if tag_info
.has_key('ARTIST'): song
.artist
= tag_info
['ARTIST'][0]
34 if tag_info
.has_key('GENRE'): song
.genre
= tag_info
['GENRE'][0]
42 A decoder to process OGG sound files. Utilizes pyogg and pyvorbis modules
43 Called from the Player class to read and decode OGG files.
45 def __init__(self
, filename
, buffersize
):
46 """Initialize the decoder"""
47 self
.buffersize
= buffersize
48 self
.filename
= filename
51 """Open the file and prepare for decoding"""
52 self
.vf
= ogg
.vorbis
.VorbisFile(self
.filename
)
53 self
.vi
= self
.vf
.info()
56 """Close the file and do any needed cleanup"""
60 """Return the length of the file in seconds as an integer"""
61 return int(self
.vf
.time_total(0))
64 """Return the sample rate of the file in samples per second"""
68 """Return the number of channels in the file"""
69 return self
.vi
.channels
73 Read data from the file and decode to PCM data. Return a buffer
74 of data and length, or (None, 0) at EOF
76 #recent versions don't want buffersize? (buff, bytes, bit) = self.vf.read(self.buffersize)
77 (buff
, bytes
, bit
) = self
.vf
.read()
83 """Return the current playback position in seconds"""
84 return int(self
.vf
.time_tell())
87 """Jump to pos as a percentage of the total length of the file"""
88 self
.vf
.time_seek(float(pos
* self
.length()))
91 """Display some information"""
92 print self
.vf
.comment().as_dict()