Back to index

eyed3  0.6.18
Public Member Functions | Public Attributes | Static Public Attributes
frames.FrameHeader Class Reference

List of all members.

Public Member Functions

def __init__
def setVersion
def setBitMask
def render
def parse2_2
def parse
def isFrameIdValid
def clearFlags

Public Attributes

 FRAME_HEADER_SIZE
 dataSize
 tagAlter
 fileAlter
 readOnly
 compressed
 encrypted
 grouped
 unsync
 dataLenIndicator

Static Public Attributes

int FRAME_HEADER_SIZE = 10
 majorVersion = DEFAULT_ID3_MAJOR_VERSION;
 minorVersion = DEFAULT_ID3_MINOR_VERSION;
 id = None;
 flags = NULL_FRAME_FLAGS;
int tagAlter = 0
int fileAlter = 0
int readOnly = 0
int compressed = 0
int encrypted = 0
int grouped = 0
int unsync = 0
int dataLenIndicator = 0
int dataSize = 0
 TAG_ALTER = None;
 FILE_ALTER = None;
 READ_ONLY = None;
 COMPRESSION = None;
 ENCRYPTION = None;
 GROUPING = None;
 UNSYNC = None;
 DATA_LEN = None;

Detailed Description

Definition at line 323 of file frames.py.


Constructor & Destructor Documentation

def frames.FrameHeader.__init__ (   self,
  tagHeader = None 
)

Definition at line 356 of file frames.py.

00356 
00357    def __init__(self, tagHeader = None):
00358       if tagHeader:
00359          self.setVersion(tagHeader);
00360       else:
00361          self.setVersion([DEFAULT_ID3_MAJOR_VERSION,
00362                           DEFAULT_ID3_MINOR_VERSION]);

Here is the call graph for this function:


Member Function Documentation

Definition at line 536 of file frames.py.

00536 
00537    def clearFlags(self):
00538       flags = [0] * 16;

def frames.FrameHeader.isFrameIdValid (   self,
  id 
)

Definition at line 533 of file frames.py.

00533 
00534    def isFrameIdValid(self, id):
00535       return re.compile(r"^[A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9]$").match(id);

Here is the caller graph for this function:

def frames.FrameHeader.parse (   self,
  f 
)

Definition at line 469 of file frames.py.

00469 
00470    def parse(self, f):
00471       TRACE_MSG("FrameHeader [start byte]: %d (0x%X)" % (f.tell(),
00472                                                          f.tell()));
00473       if self.minorVersion == 2:
00474           return self.parse2_2(f)
00475 
00476       frameId = f.read(4);
00477       if self.isFrameIdValid(frameId):
00478          TRACE_MSG("FrameHeader [id]: %s (0x%x%x%x%x)" % (frameId,
00479                                                           ord(frameId[0]),
00480                                                           ord(frameId[1]),
00481                                                           ord(frameId[2]),
00482                                                           ord(frameId[3])));
00483          self.id = frameId;
00484          # dataSize corresponds to the size of the data segment after
00485          # encryption, compression, and unsynchronization.
00486          sz = f.read(4);
00487          # In ID3 v2.4 this value became a synch-safe integer, meaning only
00488          # the low 7 bits are used per byte.
00489          if self.minorVersion == 3:
00490             self.dataSize = bin2dec(bytes2bin(sz, 8));
00491          else:
00492             self.dataSize = bin2dec(bytes2bin(sz, 7));
00493          TRACE_MSG("FrameHeader [data size]: %d (0x%X)" % (self.dataSize,
00494                                                            self.dataSize));
00495 
00496          # Frame flags.
00497          flags = f.read(2);
00498          self.flags = bytes2bin(flags);
00499          self.tagAlter = self.flags[self.TAG_ALTER];
00500          self.fileAlter = self.flags[self.FILE_ALTER];
00501          self.readOnly = self.flags[self.READ_ONLY];
00502          self.compressed = self.flags[self.COMPRESSION];
00503          self.encrypted = self.flags[self.ENCRYPTION];
00504          self.grouped = self.flags[self.GROUPING];
00505          self.unsync = self.flags[self.UNSYNC];
00506          self.dataLenIndicator = self.flags[self.DATA_LEN];
00507          TRACE_MSG("FrameHeader [flags]: ta(%d) fa(%d) ro(%d) co(%d) "\
00508                    "en(%d) gr(%d) un(%d) dl(%d)" % (self.tagAlter,
00509                                                     self.fileAlter,
00510                                                     self.readOnly,
00511                                                     self.compressed,
00512                                                     self.encrypted,
00513                                                     self.grouped,
00514                                                     self.unsync,
00515                                                     self.dataLenIndicator));
00516          if self.minorVersion >= 4 and self.compressed and \
00517             not self.dataLenIndicator:
00518             raise FrameException("Invalid frame; compressed with no data "
00519                                  "length indicator");
00520 
00521          return True
00522       elif frameId == '\x00\x00\x00\x00':
00523          TRACE_MSG("FrameHeader: Null frame id found at byte " +\
00524                    str(f.tell()));
00525       elif not strictID3() and frameId in KNOWN_BAD_FRAMES:
00526          TRACE_MSG("FrameHeader: Illegal but known "\
00527                    "(possibly created by the shitty mp3ext) frame found; "\
00528                    "Happily ignoring!" + str(f.tell()));
00529       elif strictID3():
00530          raise FrameException("FrameHeader: Illegal Frame ID: " + frameId);
00531       return False
00532 

Here is the call graph for this function:

def frames.FrameHeader.parse2_2 (   self,
  f 
)

Definition at line 438 of file frames.py.

00438 
00439    def parse2_2(self, f):
00440       frameId_22 = f.read(3);
00441       frameId = map2_2FrameId(frameId_22);
00442       if self.isFrameIdValid(frameId):
00443          TRACE_MSG("FrameHeader [id]: %s (0x%x%x%x)" % (frameId_22,
00444                                                         ord(frameId_22[0]),
00445                                                         ord(frameId_22[1]),
00446                                                         ord(frameId_22[2])));
00447          self.id = frameId;
00448          # dataSize corresponds to the size of the data segment after
00449          # encryption, compression, and unsynchronization.
00450          sz = f.read(3);
00451          self.dataSize = bin2dec(bytes2bin(sz, 8));
00452          TRACE_MSG("FrameHeader [data size]: %d (0x%X)" % (self.dataSize,
00453                                                            self.dataSize));
00454          return True
00455       elif frameId == '\x00\x00\x00':
00456          TRACE_MSG("FrameHeader: Null frame id found at byte " +\
00457                    str(f.tell()));
00458       elif not strictID3() and frameId in KNOWN_BAD_FRAMES:
00459          TRACE_MSG("FrameHeader: Illegal but known frame found; "\
00460                    "Happily ignoring" + str(f.tell()));
00461       elif strictID3():
00462          raise FrameException("FrameHeader: Illegal Frame ID: " + frameId);
00463 
00464       return False
00465 

Here is the call graph for this function:

Here is the caller graph for this function:

def frames.FrameHeader.render (   self,
  dataSize 
)

Definition at line 414 of file frames.py.

00414 
00415    def render(self, dataSize):
00416       data = self.id;
00417 
00418       if self.minorVersion == 3:
00419          data += bin2bytes(dec2bin(dataSize, 32));
00420       else:
00421          data += bin2bytes(bin2synchsafe(dec2bin(dataSize, 32)));
00422 
00423       self.setBitMask();
00424       self.flags = NULL_FRAME_FLAGS;
00425       self.flags[self.TAG_ALTER] = self.tagAlter;
00426       self.flags[self.FILE_ALTER] = self.fileAlter;
00427       self.flags[self.READ_ONLY] = self.readOnly;
00428       self.flags[self.COMPRESSION] = self.compressed;
00429       self.flags[self.COMPRESSION] = self.compressed;
00430       self.flags[self.ENCRYPTION] = self.encrypted;
00431       self.flags[self.GROUPING] = self.grouped;
00432       self.flags[self.UNSYNC] = self.unsync;
00433       self.flags[self.DATA_LEN] = self.dataLenIndicator;
00434 
00435       data += bin2bytes(self.flags);
00436 
00437       return data;

Here is the call graph for this function:

Definition at line 378 of file frames.py.

00378 
00379    def setBitMask(self):
00380       major = self.majorVersion;
00381       minor = self.minorVersion;
00382 
00383       # 1.x tags are converted to 2.4 frames internally.  These frames are
00384       # created with frame flags \x00.
00385       if (major == 2 and minor == 2):
00386           # no flags for 2.2 frames
00387           pass;
00388       elif (major == 2 and minor == 3):
00389          self.TAG_ALTER   = 0;
00390          self.FILE_ALTER  = 1;
00391          self.READ_ONLY   = 2;
00392          self.COMPRESSION = 8;
00393          self.ENCRYPTION  = 9;
00394          self.GROUPING    = 10;
00395          # This is not really in 2.3 frame header flags, but there is
00396          # a "global" unsync bit in the tag header and that is written here
00397          # so access to the tag header is not required.
00398          self.UNSYNC      = 14;
00399          # And this is mapped to an used bit, so that 0 is returned.
00400          self.DATA_LEN    = 4;
00401       elif (major == 2 and minor == 4) or \
00402            (major == 1 and (minor == 0 or minor == 1)):
00403          self.TAG_ALTER   = 1;
00404          self.FILE_ALTER  = 2;
00405          self.READ_ONLY   = 3;
00406          self.COMPRESSION = 12;
00407          self.ENCRYPTION  = 13;
00408          self.GROUPING    = 9;
00409          self.UNSYNC      = 14;
00410          self.DATA_LEN    = 15;
00411       else:
00412          raise ValueError("ID3 v" + str(major) + "." + str(minor) +\
00413                           " is not supported.");

Here is the caller graph for this function:

def frames.FrameHeader.setVersion (   self,
  tagHeader 
)

Definition at line 363 of file frames.py.

00363 
00364    def setVersion(self, tagHeader):
00365       # A slight hack to make the default ctor work.
00366       if isinstance(tagHeader, list):
00367          self.majorVersion = tagHeader[0];
00368          self.minorVersion = tagHeader[1];
00369       else:
00370          self.majorVersion = tagHeader.majorVersion;
00371          self.minorVersion = tagHeader.minorVersion;
00372       # Correctly set size of header
00373       if self.minorVersion == 2:
00374          self.FRAME_HEADER_SIZE = 6;
00375       else:
00376          self.FRAME_HEADER_SIZE = 10;
00377       self.setBitMask();

Here is the caller graph for this function:


Member Data Documentation

Definition at line 336 of file frames.py.

Definition at line 501 of file frames.py.

Definition at line 349 of file frames.py.

frames.FrameHeader.DATA_LEN = None; [static]

Definition at line 353 of file frames.py.

Definition at line 340 of file frames.py.

Definition at line 505 of file frames.py.

int frames.FrameHeader.dataSize = 0 [static]

Definition at line 342 of file frames.py.

Definition at line 450 of file frames.py.

int frames.FrameHeader.encrypted = 0 [static]

Definition at line 337 of file frames.py.

Definition at line 502 of file frames.py.

Definition at line 350 of file frames.py.

Definition at line 347 of file frames.py.

int frames.FrameHeader.fileAlter = 0 [static]

Definition at line 334 of file frames.py.

Definition at line 499 of file frames.py.

Definition at line 331 of file frames.py.

Definition at line 324 of file frames.py.

Definition at line 373 of file frames.py.

int frames.FrameHeader.grouped = 0 [static]

Definition at line 338 of file frames.py.

Definition at line 503 of file frames.py.

frames.FrameHeader.GROUPING = None; [static]

Definition at line 351 of file frames.py.

frames.FrameHeader.id = None; [static]

Definition at line 329 of file frames.py.

Definition at line 326 of file frames.py.

Definition at line 327 of file frames.py.

frames.FrameHeader.READ_ONLY = None; [static]

Definition at line 348 of file frames.py.

int frames.FrameHeader.readOnly = 0 [static]

Definition at line 335 of file frames.py.

Definition at line 500 of file frames.py.

frames.FrameHeader.TAG_ALTER = None; [static]

Definition at line 346 of file frames.py.

int frames.FrameHeader.tagAlter = 0 [static]

Definition at line 333 of file frames.py.

Definition at line 498 of file frames.py.

int frames.FrameHeader.unsync = 0 [static]

Definition at line 339 of file frames.py.

frames.FrameHeader.UNSYNC = None; [static]

Definition at line 352 of file frames.py.

Definition at line 504 of file frames.py.


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