Back to index

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

List of all members.

Public Member Functions

def __init__
def create
def writeFile
def getDefaultFileName
def render
def __str__
def unsync
def deunsync
def decompress
def compress
def decrypt
def encrypt
def disassembleFrame
def assembleFrame
def getFrameDesc
def getTextDelim

Public Attributes

 description
 filename
 encoding
 header
 decompressedSize
 groupId
 encryptionMethod
 dataLen
 unsync_default

Static Public Attributes

 mimeType = None
string description = u""
string filename = u""
 objectData = None
tuple create = staticmethod(create)

Private Member Functions

def _set

Detailed Description

Definition at line 1494 of file frames.py.


Constructor & Destructor Documentation

def frames.ObjectFrame.__init__ (   self,
  frameHeader,
  data = None,
  desc = u"",
  filename = u"",
  objectData = None,
  mimeType = None,
  encoding = DEFAULT_ENCODING,
  unsync_default = False 
)

Definition at line 1503 of file frames.py.

01503 
01504                 encoding=DEFAULT_ENCODING, unsync_default=False):
01505        Frame.__init__(self, frameHeader, unsync_default)
01506        if data != None:
01507            self._set(data, frameHeader)
01508        else:
01509            assert(isinstance(desc, unicode))
01510            self.description = desc
01511            assert(isinstance(filename, unicode))
01512            self.filename = filename
01513            self.encoding = encoding
01514            assert(mimeType)
01515            self.mimeType = mimeType
01516            assert(objectData)
01517            self.objectData = objectData

Here is the call graph for this function:


Member Function Documentation

def frames.Frame.__str__ (   self) [inherited]

Reimplemented in frames.URLFrame.

Definition at line 586 of file frames.py.

00586 
00587    def __str__(self):
00588       desc = self.getFrameDesc();
00589       return '<%s Frame (%s)>' % (desc, self.header.id);

Here is the call graph for this function:

def frames.ObjectFrame._set (   self,
  data,
  frameHeader = None 
) [private]

Definition at line 1558 of file frames.py.

01558 
01559    def _set(self, data, frameHeader = None):
01560       assert(frameHeader);
01561       if not OBJECT_FRAME_RX.match(frameHeader.id):
01562          raise FrameException("Invalid frame id for ObjectFrame: " +\
01563                               frameHeader.id);
01564 
01565       data = self.disassembleFrame(data);
01566 
01567       input = StringIO(data);
01568       TRACE_MSG("GEOB frame data size: " + str(len(data)));
01569       self.encoding = input.read(1);
01570       TRACE_MSG("GEOB encoding: " + id3EncodingToString(self.encoding));
01571 
01572       # Mime type
01573       self.mimeType = ""
01574       if self.header.minorVersion != 2:
01575           ch = input.read(1)
01576           while ch and ch != "\x00":
01577               self.mimeType += ch
01578               ch = input.read(1)
01579           if not ch:
01580               raise FrameException("GEOB frame mime type is not NULL terminated")
01581 
01582       else:
01583           # v2.2 (OBSOLETE) special case
01584           self.mimeType = input.read(3)
01585       TRACE_MSG("GEOB mime type: " + self.mimeType)
01586       if strictID3() and not self.mimeType:
01587          raise FrameException("GEOB frame does not contain a mime type")
01588       if strictID3() and self.mimeType.find("/") == -1:
01589          raise FrameException("GEOB frame does not contain a valid mime type")
01590 
01591       self.filename = u""
01592       self.description = u""
01593 
01594       # Remaining data is a NULL separated filename, description and object data
01595       buffer = input.read()
01596       input.close()
01597 
01598       try:
01599           (filename, buffer) = splitUnicode(buffer, self.encoding)
01600           (desc, obj) = splitUnicode(buffer, self.encoding)
01601       except ValueError:
01602           raise FrameException("GEOB frame appears to be missing requisite NULL "
01603                                "terminators");
01604       TRACE_MSG("filename len: %d" % len(filename))
01605       TRACE_MSG("description len: %d" % len(desc))
01606       TRACE_MSG("data len: %d" % len(obj))
01607       self.filename = encodeUnicode(filename,
01608                                     id3EncodingToString(self.encoding))
01609       self.description = encodeUnicode(desc, id3EncodingToString(self.encoding))
01610       TRACE_MSG("GEOB filename: " + self.filename)
01611       TRACE_MSG("GEOB description: " + self.description)
01612 
01613       self.objectData = obj
01614       TRACE_MSG("GEOB data: " + str(len(self.objectData)) + " bytes")
01615       if strictID3() and not self.objectData:
01616          raise FrameException("GEOB frame does not contain any data")
01617 

Here is the call graph for this function:

Here is the caller graph for this function:

def frames.Frame.assembleFrame (   self,
  data 
) [inherited]

Definition at line 659 of file frames.py.

00659 
00660    def assembleFrame (self, data):
00661       formatFlagData = "";
00662       if self.header.minorVersion == 3:
00663          if self.header.compressed:
00664             formatFlagData += bin2bytes(dec2bin(len(data), 32));
00665          if self.header.encrypted:
00666             formatFlagData += bin2bytes(dec2bin(self.encryptionMethod, 8));
00667          if self.header.grouped:
00668             formatFlagData += bin2bytes(dec2bin(self.groupId, 8));
00669       else:
00670          if self.header.grouped:
00671             formatFlagData += bin2bytes(dec2bin(self.groupId, 8));
00672          if self.header.encrypted:
00673             formatFlagData += bin2bytes(dec2bin(self.encryptionMethod, 8));
00674          if self.header.compressed or self.header.dataLenIndicator:
00675             # Just in case, not sure about this?
00676             self.header.dataLenIndicator = 1;
00677             formatFlagData += bin2bytes(dec2bin(len(data), 32));
00678 
00679       if self.header.compressed:
00680           data = self.compress(data);
00681       if self.header.encrypted:
00682           data = self.encrypt(data);
00683       if self.header.unsync or self.unsync_default:
00684           data = self.unsync(data)
00685 
00686       data = formatFlagData + data;
00687       return self.header.render(len(data)) + data;

Here is the call graph for this function:

Here is the caller graph for this function:

def frames.Frame.compress (   self,
  data 
) [inherited]

Definition at line 604 of file frames.py.

00604 
00605    def compress(self, data):
00606       TRACE_MSG("before compression: %d bytes" % len(data));
00607       data = zlib.compress(data);
00608       TRACE_MSG("after compression: %d bytes" % len(data));
00609       return data;

Here is the call graph for this function:

Here is the caller graph for this function:

def frames.ObjectFrame.create (   objFile,
  mime = u"",
  desc = u"",
  filename = None,
  encoding = DEFAULT_ENCODING 
)

Definition at line 1520 of file frames.py.

01520 
01521               encoding = DEFAULT_ENCODING):
01522        if filename == None:
01523            filename = encodeUnicode(os.path.basename(objFile),
01524                                     sys.getfilesystemencoding())
01525        if not isinstance(desc, unicode) or \
01526           (not isinstance(filename, unicode) and filename != ""):
01527            raise FrameException("Wrong description and/or filename type.")
01528        # Load file
01529        fp = file(objFile, "rb")
01530        objData = fp.read()
01531        if mime:
01532            TRACE_MSG("Using specified mime type %s" % mime)
01533        else:
01534            mime = guess_mime_type(objFile);
01535            if not mime:
01536                raise FrameException("Unable to guess mime-type for %s" %
01537                                     objFile)
01538            TRACE_MSG("Guessed mime type %s" % mime)
01539 
01540        frameData = DEFAULT_ENCODING
01541        frameData += mime + "\x00"
01542        frameData += filename.encode(id3EncodingToString(encoding)) + "\x00"
01543        frameData += desc.encode(id3EncodingToString(encoding)) + "\x00"
01544        frameData += objData
01545 
01546        frameHeader = FrameHeader()
01547        frameHeader.id = OBJECT_FID
       return ObjectFrame(frameHeader, data = frameData)

Here is the call graph for this function:

def frames.Frame.decompress (   self,
  data 
) [inherited]

Definition at line 598 of file frames.py.

00598 
00599    def decompress(self, data):
00600       TRACE_MSG("before decompression: %d bytes" % len(data));
00601       data = zlib.decompress(data, 15, self.decompressedSize);
00602       TRACE_MSG("after decompression: %d bytes" % len(data));
00603       return data;

Here is the call graph for this function:

Here is the caller graph for this function:

def frames.Frame.decrypt (   self,
  data 
) [inherited]

Definition at line 610 of file frames.py.

00610 
00611    def decrypt(self, data):
00612       raise FrameException("Encryption not supported");

Here is the caller graph for this function:

def frames.Frame.deunsync (   self,
  data 
) [inherited]

Definition at line 594 of file frames.py.

00594 
00595    def deunsync(self, data):
00596        data = deunsyncData(data)
00597        return data

Here is the call graph for this function:

Here is the caller graph for this function:

def frames.Frame.disassembleFrame (   self,
  data 
) [inherited]

Definition at line 616 of file frames.py.

00616 
00617    def disassembleFrame(self, data):
00618       # Format flags in the frame header may add extra data to the
00619       # beginning of this data.
00620       if self.header.minorVersion <= 3:
00621          # 2.3:  compression(4), encryption(1), group(1) 
00622          if self.header.compressed:
00623             self.decompressedSize = bin2dec(bytes2bin(data[:4]));
00624             data = data[4:];
00625             TRACE_MSG("Decompressed Size: %d" % self.decompressedSize);
00626          if self.header.encrypted:
00627             self.encryptionMethod = bin2dec(bytes2bin(data[0]));
00628             data = data[1:];
00629             TRACE_MSG("Encryption Method: %d" % self.encryptionMethod);
00630          if self.header.grouped:
00631             self.groupId = bin2dec(bytes2bin(data[0]));
00632             data = data[1:];
00633             TRACE_MSG("Group ID: %d" % self.groupId);
00634       else:
00635          # 2.4:  group(1), encrypted(1), dataLenIndicator(4,7)
00636          if self.header.grouped:
00637             self.groupId = bin2dec(bytes2bin(data[0]));
00638             data = data[1:];
00639          if self.header.encrypted:
00640             self.encryptionMethod = bin2dec(bytes2bin(data[0]));
00641             data = data[1:];
00642             TRACE_MSG("Encryption Method: %d" % self.encryptionMethod);
00643             TRACE_MSG("Group ID: %d" % self.groupId);
00644          if self.header.dataLenIndicator:
00645             self.dataLen = bin2dec(bytes2bin(data[:4], 7));
00646             data = data[4:];
00647             TRACE_MSG("Data Length: %d" % self.dataLen);
00648             if self.header.compressed:
00649                self.decompressedSize = self.dataLen;
00650                TRACE_MSG("Decompressed Size: %d" % self.decompressedSize);
00651 
00652       if self.header.unsync or self.unsync_default:
00653          data = self.deunsync(data)
00654       if self.header.encrypted:
00655          data = self.decrypt(data);
00656       if self.header.compressed:
00657          data = self.decompress(data);
00658       return data;

Here is the call graph for this function:

Here is the caller graph for this function:

def frames.Frame.encrypt (   self,
  data 
) [inherited]

Definition at line 613 of file frames.py.

00613 
00614    def encrypt(self, data):
00615       raise FrameException("Encryption not supported");

Here is the caller graph for this function:

def frames.ObjectFrame.getDefaultFileName (   self,
  suffix = "" 
)

Definition at line 1629 of file frames.py.

01629 
01630    def getDefaultFileName(self, suffix = ""):
01631       nameStr = self.filename
01632       if suffix:
01633           nameStr += suffix
01634       nameStr = nameStr +  "." + self.mimeType.split("/")[1]
01635       return nameStr

Here is the caller graph for this function:

def frames.Frame.getFrameDesc (   self) [inherited]

Definition at line 688 of file frames.py.

00688 
00689    def getFrameDesc(self):
00690       try:
00691          return frameDesc[self.header.id];
00692       except KeyError:
00693          try:
00694             return obsoleteFrames[self.header.id];
00695          except KeyError:
00696             return "UNKOWN FRAME";

Here is the caller graph for this function:

def frames.Frame.getTextDelim (   self) [inherited]

Definition at line 697 of file frames.py.

00697 
00698    def getTextDelim(self):
00699        if self.encoding == UTF_16_ENCODING or \
00700           self.encoding == UTF_16BE_ENCODING:
00701            return "\x00\x00";
00702        else:
00703            return "\x00";

Here is the caller graph for this function:

def frames.ObjectFrame.render (   self)

Definition at line 1636 of file frames.py.

01636 
01637    def render(self):
01638       data = self.encoding + self.mimeType + "\x00" +\
01639              self.filename.encode(id3EncodingToString(self.encoding)) +\
01640              self.getTextDelim() +\
01641              self.description.encode(id3EncodingToString(self.encoding)) +\
01642              self.getTextDelim() +\
01643              self.objectData
01644       return self.assembleFrame(data)

Here is the call graph for this function:

def frames.Frame.unsync (   self,
  data 
) [inherited]

Definition at line 590 of file frames.py.

00590 
00591    def unsync(self, data):
00592        data = unsyncData(data)
00593        return data

Here is the call graph for this function:

Here is the caller graph for this function:

def frames.ObjectFrame.writeFile (   self,
  path = "./",
  name = None 
)

Definition at line 1618 of file frames.py.

01618 
01619    def writeFile(self, path = "./", name = None):
01620       if not self.objectData:
01621          raise IOError("Fetching remote object files is not implemented.")
01622       if not name:
01623          name = self.getDefaultFileName()
01624       objectFile = os.path.join(path, name)
01625 
01626       f = file(objectFile, "wb")
01627       f.write(self.objectData)
01628       f.flush()
      f.close()

Here is the call graph for this function:


Member Data Documentation

tuple frames.ObjectFrame.create = staticmethod(create) [static]

Definition at line 1549 of file frames.py.

frames.Frame.dataLen [inherited]

Definition at line 581 of file frames.py.

Definition at line 578 of file frames.py.

string frames.ObjectFrame.description = u"" [static]

Definition at line 1496 of file frames.py.

Definition at line 1509 of file frames.py.

Reimplemented from frames.Frame.

Definition at line 1512 of file frames.py.

Definition at line 580 of file frames.py.

string frames.ObjectFrame.filename = u"" [static]

Definition at line 1497 of file frames.py.

Definition at line 1511 of file frames.py.

frames.Frame.groupId [inherited]

Definition at line 579 of file frames.py.

frames.Frame.header [inherited]

Definition at line 577 of file frames.py.

frames.ObjectFrame.mimeType = None [static]

Definition at line 1495 of file frames.py.

Definition at line 1498 of file frames.py.

Definition at line 584 of file frames.py.


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