Back to index

eyed3  0.6.18
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions
tag.ExtendedTagHeader Class Reference

List of all members.

Public Member Functions

def isUpdate
def hasCRC
def hasRestrictions
def setSizeRestrictions
def getSizeRestrictions
def getSizeRestrictionsString
def setTextEncodingRestrictions
def getTextEncodingRestrictions
def getTextEncodingRestrictionsString
def setTextFieldSizeRestrictions
def getTextFieldSizeRestrictions
def getTextFieldSizeRestrictionsString
def setImageEncodingRestrictions
def getImageEncodingRestrictions
def getImageEncodingRestrictionsString
def setImageSizeRestrictions
def getImageSizeRestrictions
def getImageSizeRestrictionsString
def render
def parse

Public Attributes

 restrictions
 crc
 size
 flags

Static Public Attributes

int size = 0
int flags = 0
int crc = 0
int restrictions = 0

Private Member Functions

def _syncsafeCRC

Detailed Description

Definition at line 164 of file tag.py.


Member Function Documentation

def tag.ExtendedTagHeader._syncsafeCRC (   self) [private]

Definition at line 249 of file tag.py.

00249 
00250    def _syncsafeCRC(self):
00251        bites = ""
00252        bites += chr((self.crc >> 28) & 0x7f);
00253        bites += chr((self.crc >> 21) & 0x7f);
00254        bites += chr((self.crc >> 14) & 0x7f);
00255        bites += chr((self.crc >>  7) & 0x7f);
00256        bites += chr((self.crc >>  0) & 0x7f);
00257        return bites;
00258 

Definition at line 224 of file tag.py.

00224 
00225    def getImageEncodingRestrictions(self):
      return self.restrictions & 0x04;

Here is the caller graph for this function:

Definition at line 226 of file tag.py.

00226 
00227    def getImageEncodingRestrictionsString(self):
00228       if self.getImageEncodingRestrictions():
00229          return "Images are encoded only with PNG [PNG] or JPEG [JFIF].";
00230       else:
00231          return "None";

Here is the call graph for this function:

Definition at line 235 of file tag.py.

00235 
00236    def getImageSizeRestrictions(self):
      return self.restrictions & 0x03;

Here is the caller graph for this function:

Definition at line 237 of file tag.py.

00237 
00238    def getImageSizeRestrictionsString(self):
00239       val = self.getImageSizeRestrictions();
00240       if val == 0x00:
00241          return "None";
00242       elif val == 0x01:
00243          return "All images are 256x256 pixels or smaller.";
00244       elif val == 0x02:
00245          return "All images are 64x64 pixels or smaller.";
00246       elif val == 0x03:
00247          return "All images are exactly 64x64 pixels, unless required "\
00248                 "otherwise.";

Here is the call graph for this function:

Definition at line 180 of file tag.py.

00180 
00181    def getSizeRestrictions(self):
      return self.restrictions >> 6;

Here is the caller graph for this function:

Definition at line 182 of file tag.py.

00182 
00183    def getSizeRestrictionsString(self):
00184       val = self.getSizeRestrictions();
00185       if val == 0x00:
00186          return "No more than 128 frames and 1 MB total tag size.";
00187       elif val == 0x01:
00188          return "No more than 64 frames and 128 KB total tag size.";
00189       elif val == 0x02:
00190          return "No more than 32 frames and 40 KB total tag size.";
00191       elif val == 0x03:
00192          return "No more than 32 frames and 4 KB total tag size.";

Here is the call graph for this function:

Definition at line 196 of file tag.py.

00196 
00197    def getTextEncodingRestrictions(self):
      return self.restrictions & 0x20;

Here is the caller graph for this function:

Definition at line 198 of file tag.py.

00198 
00199    def getTextEncodingRestrictionsString(self):
00200       if self.getTextEncodingRestrictions():
00201          return "Strings are only encoded with ISO-8859-1 [ISO-8859-1] or "\
00202                 "UTF-8 [UTF-8].";
00203       else:
00204          return "None";

Here is the call graph for this function:

Definition at line 208 of file tag.py.

00208 
00209    def getTextFieldSizeRestrictions(self):
      return (self.restrictions >> 3) & 0x03;

Here is the caller graph for this function:

Definition at line 210 of file tag.py.

00210 
00211    def getTextFieldSizeRestrictionsString(self):
00212       val = self.getTextFieldSizeRestrictions();
00213       if val == 0x00:
00214          return "None";
00215       elif val == 0x01:
00216          return "No string is longer than 1024 characters.";
00217       elif val == 0x02:
00218          return "No string is longer than 128 characters.";
00219       elif val == 0x03:
00220          return "No string is longer than 30 characters.";

Here is the call graph for this function:

Definition at line 172 of file tag.py.

00172 
00173    def hasCRC(self):
       return self.flags & 0x20;

Here is the caller graph for this function:

def tag.ExtendedTagHeader.hasRestrictions (   self,
  minor_version = None 
)

Definition at line 174 of file tag.py.

00174 
00175    def hasRestrictions(self, minor_version = None):
00176        return self.flags & 0x10;

Definition at line 170 of file tag.py.

00170 
00171    def isUpdate(self):
       return self.flags & 0x40;

Here is the caller graph for this function:

def tag.ExtendedTagHeader.parse (   self,
  fp,
  header 
)

Definition at line 321 of file tag.py.

00321 
00322    def parse(self, fp, header):
00323       assert(header.majorVersion == 2);
00324 
00325       TRACE_MSG("Parsing extended header @ 0x%x" % fp.tell());
00326       # First 4 bytes is the size of the extended header.
00327       data = fp.read(4);
00328       if header.minorVersion == 4:
00329          # sync-safe
00330          sz = bin2dec(bytes2bin(data, 7));
00331          self.size = sz
00332          TRACE_MSG("Extended header size (includes the 4 size bytes): %d" % sz);
00333          data = fp.read(sz - 4);
00334 
00335          if ord(data[0]) != 1 or (ord(data[1]) & 0x8f):
00336             # As of 2.4 the first byte is 1 and the second can only have
00337             # bits 6, 5, and 4 set.
00338             raise TagException("Invalid Extended Header");
00339 
00340          offset = 2;
00341          self.flags = ord(data[1]);
00342          TRACE_MSG("Extended header flags: %x" % self.flags);
00343 
00344          if self.isUpdate():
00345             TRACE_MSG("Extended header has update bit set");
00346             assert(ord(data[offset]) == 0);
00347             offset += 1;
00348          if self.hasCRC():
00349             TRACE_MSG("Extended header has CRC bit set");
00350             assert(ord(data[offset]) == 5);
00351             offset += 1;
00352             crcData = data[offset:offset + 5];
00353             # This is sync-safe.
00354             self.crc = bin2dec(bytes2bin(crcData, 7));
00355             TRACE_MSG("Extended header CRC: %d" % self.crc);
00356             offset += 5;
00357          if self.hasRestrictions():
00358             TRACE_MSG("Extended header has restrictions bit set");
00359             assert(ord(data[offset]) == 5);
00360             offset += 1;
00361             self.restrictions = ord(data[offset]);
00362             offset += 1;
00363       else:
00364          # v2.3 is totally different... *sigh*
00365          sz = bin2dec(bytes2bin(data));
00366          TRACE_MSG("Extended header size (not including 4 size bytes): %d" % sz)
00367          self.size = sz + 4  # +4 to include size bytes
00368          tmpFlags = fp.read(2);
00369          # Read the padding size, but it'll be computed during the parse.
00370          ps = fp.read(4);
00371          TRACE_MSG("Extended header says there is %d bytes of padding" %
00372                    bin2dec(bytes2bin(ps)));
00373          # Make this look like a v2.4 mask.
00374          self.flags = ord(tmpFlags[0]) >> 2;
00375          if self.hasCRC():
00376             TRACE_MSG("Extended header has CRC bit set");
00377             crcData = fp.read(4);
00378             self.crc = bin2dec(bytes2bin(crcData));
00379             TRACE_MSG("Extended header CRC: %d" % self.crc);
00380 

Here is the call graph for this function:

def tag.ExtendedTagHeader.render (   self,
  header,
  frameData,
  padding = 0 
)

Definition at line 259 of file tag.py.

00259 
00260    def render(self, header, frameData, padding=0):
00261       assert(header.majorVersion == 2);
00262 
00263       data = "";
00264       crc = None;
00265       if header.minorVersion == 4:
00266          # Version 2.4
00267          size = 6;
00268          # Extended flags.
00269          if self.isUpdate():
00270             data += "\x00";
00271          if self.hasCRC():
00272             data += "\x05";
00273             # XXX: Using the absolute value of the CRC.  The spec is unclear
00274             # about the type of this data.
00275             self.crc = int(math.fabs(binascii.crc32(frameData +\
00276                                                     ("\x00" * padding))));
00277             crc_data = self._syncsafeCRC();
00278             if len(crc_data) < 5:
00279                 crc_data = ("\x00" * (5 - len(crc_data))) + crc_data
00280             assert(len(crc_data) == 5)
00281             data += crc_data
00282          if self.hasRestrictions():
00283             data += "\x01";
00284             assert(len(self.restrictions) == 1);
00285             data += self.restrictions;
00286          TRACE_MSG("Rendered extended header data (%d bytes)" % len(data));
00287 
00288          # Extended header size.
00289          size = bin2bytes(bin2synchsafe(dec2bin(len(data) + 6, 32)))
00290          assert(len(size) == 4);
00291 
00292          data = size + "\x01" + bin2bytes(dec2bin(self.flags)) + data;
00293          TRACE_MSG("Rendered extended header of size %d" % len(data));
00294       else:
00295          # Version 2.3
00296          size = 6;  # Note, the 4 size bytes are not included in the size
00297          # Extended flags.
00298          f = [0] * 16;
00299          if self.hasCRC():
00300             f[0] = 1;
00301             # XXX: Using the absolute value of the CRC.  The spec is unclear
00302             # about the type of this value.
00303             self.crc = int(math.fabs(binascii.crc32(frameData +\
00304                                                     ("\x00" * padding))));
00305             crc = bin2bytes(dec2bin(self.crc));
00306             assert(len(crc) == 4);
00307             size += 4;
00308          flags = bin2bytes(f);
00309          assert(len(flags) == 2);
00310          # Extended header size.
00311          size = bin2bytes(dec2bin(size, 32))
00312          assert(len(size) == 4);
00313          # Padding size
00314          paddingSize = bin2bytes(dec2bin(padding, 32));
00315 
00316          data = size + flags + paddingSize;
00317          if crc:
00318             data += crc;
00319       return data;

Here is the call graph for this function:

Definition at line 221 of file tag.py.

00221 
00222    def setImageEncodingRestrictions(self, v):
00223       assert(v == 0 or v == 1);
      self.restrictions ^= 0x04;

Definition at line 232 of file tag.py.

00232 
00233    def setImageSizeRestrictions(self, v):
00234       assert(v >= 0 and v <= 3);
      self.restrictions = v | (self.restrictions & 0xfc);

Definition at line 177 of file tag.py.

00177 
00178    def setSizeRestrictions(self, v):
00179       assert(v >= 0 and v <= 3);
      self.restrictions = (v << 6) | (self.restrictions & 0x3f);

Definition at line 193 of file tag.py.

00193 
00194    def setTextEncodingRestrictions(self, v):
00195       assert(v == 0 or v == 1);
      self.restrictions ^= 0x20;

Definition at line 205 of file tag.py.

00205 
00206    def setTextFieldSizeRestrictions(self, v):
00207       assert(v >= 0 and v <= 3);
      self.restrictions = (v << 3) | (self.restrictions & 0xe7);

Member Data Documentation

int tag.ExtendedTagHeader.crc = 0 [static]

Definition at line 167 of file tag.py.

Definition at line 274 of file tag.py.

int tag.ExtendedTagHeader.flags = 0 [static]

Definition at line 166 of file tag.py.

Definition at line 340 of file tag.py.

Definition at line 168 of file tag.py.

Definition at line 179 of file tag.py.

int tag.ExtendedTagHeader.size = 0 [static]

Definition at line 165 of file tag.py.

Definition at line 330 of file tag.py.


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