Back to index

eyed3  0.6.18
Public Member Functions | Public Attributes | Static Public Attributes
tag.Mp3AudioFile Class Reference
Inheritance diagram for tag.Mp3AudioFile:
Inheritance graph
[legend]
Collaboration diagram for tag.Mp3AudioFile:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def getBitRate
def getBitRateString
def getSampleFreq
def getTag
def getSize
def rename
def getPlayTime
def getPlayTimeString

Public Attributes

 tag
 header
 xingHeader
 lameTag
 play_time
 fileName
 fileSize

Static Public Attributes

tuple fileName = str("")
tuple fileSize = int(0)

Detailed Description

Definition at line 1639 of file tag.py.


Constructor & Destructor Documentation

def tag.Mp3AudioFile.__init__ (   self,
  fileName,
  tagVersion = ID3_ANY_VERSION 
)

Definition at line 1641 of file tag.py.

01641 
01642    def __init__(self, fileName, tagVersion = ID3_ANY_VERSION):
01643       TagFile.__init__(self, fileName)
01644 
01645       self.tag        = None
01646       self.header     = None
01647       self.xingHeader = None
01648       self.lameTag    = None
01649 
01650       if not isMp3File(fileName):
01651          raise InvalidAudioFormatException("File is not mp3");
01652 
01653       # Parse ID3 tag.
01654       f = file(self.fileName, "rb");
01655       self.tag = Tag();
01656       hasTag = self.tag.link(f, tagVersion);
01657       # Find the first mp3 frame.
01658       if self.tag.isV1():
01659          framePos = 0;
01660       elif not hasTag:
01661          framePos = 0;
01662          self.tag = None;
01663       else:
01664          framePos = self.tag.header.SIZE + self.tag.header.tagSize;
01665 
01666       TRACE_MSG("mp3 header search starting @ %x" % framePos)
01667       # Find an mp3 header
01668       header_pos, header, header_bytes = mp3.find_header(f, framePos)
01669       if header:
01670           try:
01671               self.header = mp3.Header(header)
01672           except mp3.Mp3Exception, ex:
01673               self.header = None
01674               raise InvalidAudioFormatException(str(ex));
01675           else:
01676               TRACE_MSG("mp3 header %x found at position: 0x%x" % (header,
01677                                                                    header_pos))
01678       else:
01679         raise InvalidAudioFormatException("Unable to find a valid mp3 frame")
01680 
01681       # Check for Xing/Info header information which will always be in the
01682       # first "null" frame.
01683       f.seek(header_pos)
01684       mp3_frame = f.read(self.header.frameLength)
01685       if re.compile('Xing|Info').search(mp3_frame):
01686           self.xingHeader = mp3.XingHeader();
01687           if not self.xingHeader.decode(mp3_frame):
01688               TRACE_MSG("Ignoring corrupt Xing header")
01689               self.xingHeader = None
01690       # Check for LAME Tag
01691       self.lameTag = mp3.LameTag(mp3_frame)
01692 
01693       # Compute track play time.
01694       tpf = mp3.computeTimePerFrame(self.header);
01695       if self.xingHeader and self.xingHeader.vbr:
01696          self.play_time = int(tpf * self.xingHeader.numFrames);
01697       else:
01698          length = self.getSize();
01699          if self.tag and self.tag.isV2():
01700             length -= self.tag.header.SIZE + self.tag.header.tagSize;
01701             # Handle the case where there is a v2 tag and a v1 tag.
01702             f.seek(-128, 2)
01703             if f.read(3) == "TAG":
01704                length -= 128;
01705          elif self.tag and self.tag.isV1():
01706             length -= 128;
01707          self.play_time = int((length / self.header.frameLength) * tpf);
01708 
01709       f.close();


Member Function Documentation

Definition at line 1712 of file tag.py.

01712 
01713    def getBitRate(self):
01714       xHead = self.xingHeader;
01715       if xHead and xHead.vbr:
01716          tpf = eyeD3.mp3.computeTimePerFrame(self.header);
01717          # FIXME: if xHead.numFrames == 0 (Fuoco.mp3), ZeroDivisionError
01718          br = int((xHead.numBytes * 8) / (tpf * xHead.numFrames * 1000));
01719          vbr = 1;
01720       else:
01721          br = self.header.bitRate;
01722          vbr = 0;
01723       return (vbr, br);

Here is the caller graph for this function:

Definition at line 1724 of file tag.py.

01724 
01725    def getBitRateString(self):
01726       (vbr, bitRate) = self.getBitRate();
01727       brs = "%d kb/s" % bitRate;
01728       if vbr:
01729          brs = "~" + brs;
      return brs;

Here is the call graph for this function:

def tag.TagFile.getPlayTime (   self) [inherited]

Definition at line 1630 of file tag.py.

01630 
01631    def getPlayTime(self):
01632       return self.play_time;

Here is the caller graph for this function:

def tag.TagFile.getPlayTimeString (   self) [inherited]

Definition at line 1633 of file tag.py.

01633 
01634    def getPlayTimeString(self):
01635       from eyeD3.utils import format_track_time
01636       return format_track_time(self.getPlayTime())
01637 

Here is the call graph for this function:

Definition at line 1730 of file tag.py.

01730 
01731    def getSampleFreq(self):
01732       return self.header.sampleFreq;

def tag.TagFile.getSize (   self) [inherited]

Definition at line 1606 of file tag.py.

01606 
01607    def getSize(self):
01608       if not self.fileSize:
01609          self.fileSize = os.stat(self.fileName)[ST_SIZE];
01610       return self.fileSize;

def tag.TagFile.getTag (   self) [inherited]

Definition at line 1603 of file tag.py.

01603 
01604    def getTag(self):
01605       return self.tag;

def tag.TagFile.rename (   self,
  name,
  fsencoding 
) [inherited]

Definition at line 1611 of file tag.py.

01611 
01612    def rename(self, name, fsencoding):
01613        base = os.path.basename(self.fileName);
01614        base_ext = os.path.splitext(base)[1];
01615        dir = os.path.dirname(self.fileName);
01616        if not dir:
01617            dir = ".";
01618        new_name = dir + os.sep + name.encode(fsencoding) + base_ext;
01619 
01620        if os.path.exists(new_name):
01621            raise TagException("File '%s' exists, eyeD3 will not overwrite it" %
01622                               new_name)
01623 
01624        try:
01625            os.rename(self.fileName, new_name);
01626            self.fileName = new_name;
01627        except OSError, ex:
01628            raise TagException("Error renaming '%s' to '%s'" % (self.fileName,
01629                                                                new_name));


Member Data Documentation

tuple tag.TagFile.fileName = str("") [static, inherited]

Definition at line 1594 of file tag.py.

tag.TagFile.fileName [inherited]

Definition at line 1601 of file tag.py.

tuple tag.TagFile.fileSize = int(0) [static, inherited]

Definition at line 1595 of file tag.py.

tag.TagFile.fileSize [inherited]

Definition at line 1608 of file tag.py.

Definition at line 1645 of file tag.py.

Definition at line 1647 of file tag.py.

Reimplemented from tag.TagFile.

Definition at line 1695 of file tag.py.

Reimplemented from tag.TagFile.

Definition at line 1644 of file tag.py.

Definition at line 1646 of file tag.py.


The documentation for this class was generated from the following file: