Back to index

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

List of all members.

Public Member Functions

def __init__
def create
def writeFile
def getDefaultFileName
def render
def stringToPicType
def picTypeToString
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
 encoding
 desciption
 header
 decompressedSize
 groupId
 encryptionMethod
 dataLen
 unsync_default

Static Public Attributes

 mimeType = None
 pictureType = None
string description = u""
 imageData = None
 imageURL = None
int OTHER = 0x00
int ICON = 0x01
int OTHER_ICON = 0x02
int FRONT_COVER = 0x03
int BACK_COVER = 0x04
int LEAFLET = 0x05
int MEDIA = 0x06
int LEAD_ARTIST = 0x07
int ARTIST = 0x08
int CONDUCTOR = 0x09
int BAND = 0x0A
int COMPOSER = 0x0B
int LYRICIST = 0x0C
int RECORDING_LOCATION = 0x0D
int DURING_RECORDING = 0x0E
int DURING_PERFORMANCE = 0x0F
int VIDEO = 0x10
int BRIGHT_COLORED_FISH = 0x11
int ILLUSTRATION = 0x12
int BAND_LOGO = 0x13
int PUBLISHER_LOGO = 0x14
 MIN_TYPE = OTHER
 MAX_TYPE = PUBLISHER_LOGO
tuple create = staticmethod(create)
tuple stringToPicType = staticmethod(stringToPicType)
tuple picTypeToString = staticmethod(picTypeToString)

Private Member Functions

def _set

Detailed Description

Definition at line 1211 of file frames.py.


Constructor & Destructor Documentation

def frames.ImageFrame.__init__ (   self,
  frameHeader,
  data = None,
  description = u"",
  imageData = None,
  imageURL = None,
  pictureType = None,
  mimeType = None,
  encoding = DEFAULT_ENCODING,
  unsync_default = False 
)

Definition at line 1250 of file frames.py.

01250 
01251                 encoding=DEFAULT_ENCODING, unsync_default=False):
01252        Frame.__init__(self, frameHeader, unsync_default)
01253        if data != None:
01254            self._set(data, frameHeader)
01255        else:
01256            assert(isinstance(description, unicode))
01257            self.description = description
01258            self.encoding = encoding
01259            assert(mimeType)
01260            self.mimeType = mimeType
01261            assert(pictureType != None)
01262            self.pictureType = pictureType
01263            if imageData:
01264                self.imageData = imageData
01265            else:
01266                self.imageURL = imageURL
01267            assert(self.imageData or self.imageURL)
01268 

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.ImageFrame._set (   self,
  data,
  frameHeader = None 
) [private]

Definition at line 1300 of file frames.py.

01300 
01301    def _set(self, data, frameHeader = None):
01302       assert(frameHeader);
01303       if not IMAGE_FRAME_RX.match(frameHeader.id):
01304          raise FrameException("Invalid frame id for ImageFrame: " +\
01305                               frameHeader.id);
01306 
01307       data = self.disassembleFrame(data);
01308 
01309       input = StringIO(data);
01310       TRACE_MSG("APIC frame data size: " + str(len(data)));
01311       self.encoding = input.read(1);
01312       TRACE_MSG("APIC encoding: " + id3EncodingToString(self.encoding));
01313 
01314       # Mime type
01315       self.mimeType = "";
01316       if self.header.minorVersion != 2:
01317           ch = input.read(1)
01318           while ch and ch != "\x00":
01319               self.mimeType += ch
01320               ch = input.read(1)
01321       else:
01322           # v2.2 (OBSOLETE) special case
01323           self.mimeType = input.read(3);
01324       TRACE_MSG("APIC mime type: " + self.mimeType);
01325       if strictID3() and not self.mimeType:
01326          raise FrameException("APIC frame does not contain a mime type");
01327       if self.mimeType.find("/") == -1:
01328          self.mimeType = "image/" + self.mimeType;
01329 
01330       pt = ord(input.read(1));
01331       TRACE_MSG("Initial APIC picture type: " + str(pt));
01332       if pt < self.MIN_TYPE or pt > self.MAX_TYPE:
01333           if strictID3():
01334               raise FrameException("Invalid APIC picture type: %d" % (pt));
01335           # Rather than force this to UNKNOWN, let's assume that they put a
01336           # character literal instead of it's byte value.
01337           try:
01338               pt = int(chr(pt))
01339           except:
01340               pt = self.OTHER
01341           if pt < self.MIN_TYPE or pt > self.MAX_TYPE:
01342               self.pictureType = self.OTHER
01343       self.pictureType = pt
01344       TRACE_MSG("APIC picture type: " + str(self.pictureType))
01345 
01346       self.desciption = u""
01347 
01348       # Remaining data is a NULL separated description and image data
01349       buffer = input.read()
01350       input.close()
01351 
01352       (desc, img) = splitUnicode(buffer, self.encoding)
01353       TRACE_MSG("description len: %d" % len(desc))
01354       TRACE_MSG("image len: %d" % len(img))
01355       self.description = encodeUnicode(desc, id3EncodingToString(self.encoding))
01356       TRACE_MSG("APIC description: " + self.description);
01357 
01358       if self.mimeType.find("-->") != -1:
01359          self.imageData = None
01360          self.imageURL = img
01361          TRACE_MSG("APIC image data: %d bytes" % 0)
01362       else:
01363          self.imageData = img
01364          self.imageURL = None
01365          TRACE_MSG("APIC image data: %d bytes" % len(self.imageData))
01366       if strictID3() and not self.imageData and not self.imageURL:
01367          raise FrameException("APIC frame does not contain any image data")
01368 

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.ImageFrame.create (   type,
  imgFile,
  desc = u"",
  encoding = DEFAULT_ENCODING 
)

Definition at line 1270 of file frames.py.

01270 
01271    def create(type, imgFile, desc = u"", encoding = DEFAULT_ENCODING):
01272        if not isinstance(desc, unicode) or \
01273           not isinstance(type, int):
01274            raise FrameException("Wrong description and/or image-type type.");
01275        # Load img
01276        fp = file(imgFile, "rb");
01277        imgData = fp.read();
01278        mt = guess_mime_type(imgFile);
01279        if not mt:
01280            raise FrameException("Unable to guess mime-type for %s" % (imgFile));
01281 
01282        frameData = DEFAULT_ENCODING;
01283        frameData += mt + "\x00";
01284        frameData += bin2bytes(dec2bin(type, 8));
01285        frameData += desc.encode(id3EncodingToString(encoding)) + "\x00";
01286        frameData += imgData;
01287 
01288        frameHeader = FrameHeader();
01289        frameHeader.id = IMAGE_FID;
       return ImageFrame(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.ImageFrame.getDefaultFileName (   self,
  suffix = "" 
)

Definition at line 1380 of file frames.py.

01380 
01381    def getDefaultFileName(self, suffix = ""):
01382       nameStr = self.picTypeToString(self.pictureType)
01383       if suffix:
01384           nameStr += suffix
01385       nameStr = nameStr +  "." + self.mimeType.split("/")[1]
01386       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:

Definition at line 1445 of file frames.py.

01445 
01446    def picTypeToString(t):
01447       if t == ImageFrame.OTHER:
01448          return "OTHER";
01449       elif t == ImageFrame.ICON:
01450          return "ICON";
01451       elif t == ImageFrame.OTHER_ICON:
01452          return "OTHER_ICON";
01453       elif t == ImageFrame.FRONT_COVER:
01454          return "FRONT_COVER";
01455       elif t == ImageFrame.BACK_COVER:
01456          return "BACK_COVER";
01457       elif t == ImageFrame.LEAFLET:
01458          return "LEAFLET";
01459       elif t == ImageFrame.MEDIA:
01460          return "MEDIA";
01461       elif t == ImageFrame.LEAD_ARTIST:
01462          return "LEAD_ARTIST";
01463       elif t == ImageFrame.ARTIST:
01464          return "ARTIST";
01465       elif t == ImageFrame.CONDUCTOR:
01466          return "CONDUCTOR";
01467       elif t == ImageFrame.BAND:
01468          return "BAND";
01469       elif t == ImageFrame.COMPOSER:
01470          return "COMPOSER";
01471       elif t == ImageFrame.LYRICIST:
01472          return "LYRICIST";
01473       elif t == ImageFrame.RECORDING_LOCATION:
01474          return "RECORDING_LOCATION";
01475       elif t == ImageFrame.DURING_RECORDING:
01476          return "DURING_RECORDING";
01477       elif t == ImageFrame.DURING_PERFORMANCE:
01478          return "DURING_PERFORMANCE";
01479       elif t == ImageFrame.VIDEO:
01480          return "VIDEO";
01481       elif t == ImageFrame.BRIGHT_COLORED_FISH:
01482          return "BRIGHT_COLORED_FISH";
01483       elif t == ImageFrame.ILLUSTRATION:
01484          return "ILLUSTRATION";
01485       elif t == ImageFrame.BAND_LOGO:
01486          return "BAND_LOGO";
01487       elif t == ImageFrame.PUBLISHER_LOGO:
01488          return "PUBLISHER_LOGO";
01489       else:
         raise FrameException("Invalid APIC picture type: %d" % t);
def frames.ImageFrame.render (   self)

Definition at line 1387 of file frames.py.

01387 
01388    def render(self):
01389       data = self.encoding + self.mimeType + "\x00" +\
01390              bin2bytes(dec2bin(self.pictureType, 8)) +\
01391              self.description.encode(id3EncodingToString(self.encoding)) +\
01392              self.getTextDelim()
01393       if self.imageURL:
01394           data += self.imageURL.encode("ascii");
01395       else:
01396           data += self.imageData;
01397       return self.assembleFrame(data);

Here is the call graph for this function:

Definition at line 1398 of file frames.py.

01398 
01399    def stringToPicType(s):
01400        if s == "OTHER":
01401            return ImageFrame.OTHER;
01402        elif s == "ICON":
01403            return ImageFrame.ICON;
01404        elif s == "OTHER_ICON":
01405            return ImageFrame.OTHER_ICON;
01406        elif s == "FRONT_COVER":
01407            return ImageFrame.FRONT_COVER
01408        elif s == "BACK_COVER":
01409            return ImageFrame.BACK_COVER;
01410        elif s == "LEAFLET":
01411            return ImageFrame.LEAFLET;
01412        elif s == "MEDIA":
01413            return ImageFrame.MEDIA;
01414        elif s == "LEAD_ARTIST":
01415            return ImageFrame.LEAD_ARTIST;
01416        elif s == "ARTIST":
01417            return ImageFrame.ARTIST;
01418        elif s == "CONDUCTOR":
01419            return ImageFrame.CONDUCTOR;
01420        elif s == "BAND":
01421            return ImageFrame.BAND;
01422        elif s == "COMPOSER":
01423            return ImageFrame.COMPOSER;
01424        elif s == "LYRICIST":
01425            return ImageFrame.LYRICIST;
01426        elif s == "RECORDING_LOCATION":
01427            return ImageFrame.RECORDING_LOCATION;
01428        elif s == "DURING_RECORDING":
01429            return ImageFrame.DURING_RECORDING;
01430        elif s == "DURING_PERFORMANCE":
01431            return ImageFrame.DURING_PERFORMANCE;
01432        elif s == "VIDEO":
01433            return ImageFrame.VIDEO;
01434        elif s == "BRIGHT_COLORED_FISH":
01435            return ImageFrame.BRIGHT_COLORED_FISH;
01436        elif s == "ILLUSTRATION":
01437            return ImageFrame.ILLUSTRATION;
01438        elif s == "BAND_LOGO":
01439            return ImageFrame.BAND_LOGO;
01440        elif s == "PUBLISHER_LOGO":
01441            return ImageFrame.PUBLISHER_LOGO;
01442        else:
         raise FrameException("Invalid APIC picture type: %s" % s);
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.ImageFrame.writeFile (   self,
  path = "./",
  name = None 
)

Definition at line 1369 of file frames.py.

01369 
01370    def writeFile(self, path = "./", name = None):
01371       if not self.imageData:
01372          raise IOError("Fetching remote image files is not implemented.")
01373       if not name:
01374          name = self.getDefaultFileName()
01375       imageFile = os.path.join(path, name)
01376 
01377       f = file(imageFile, "wb");
01378       f.write(self.imageData);
01379       f.flush();
      f.close();

Here is the call graph for this function:


Member Data Documentation

int frames.ImageFrame.ARTIST = 0x08 [static]

Definition at line 1230 of file frames.py.

int frames.ImageFrame.BACK_COVER = 0x04 [static]

Definition at line 1226 of file frames.py.

int frames.ImageFrame.BAND = 0x0A [static]

Definition at line 1232 of file frames.py.

int frames.ImageFrame.BAND_LOGO = 0x13 [static]

Definition at line 1241 of file frames.py.

Definition at line 1239 of file frames.py.

int frames.ImageFrame.COMPOSER = 0x0B [static]

Definition at line 1233 of file frames.py.

int frames.ImageFrame.CONDUCTOR = 0x09 [static]

Definition at line 1231 of file frames.py.

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

Definition at line 1291 of file frames.py.

frames.Frame.dataLen [inherited]

Definition at line 581 of file frames.py.

Definition at line 578 of file frames.py.

Definition at line 1345 of file frames.py.

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

Definition at line 1214 of file frames.py.

Definition at line 1256 of file frames.py.

Definition at line 1237 of file frames.py.

Definition at line 1236 of file frames.py.

Reimplemented from frames.Frame.

Definition at line 1257 of file frames.py.

Definition at line 580 of file frames.py.

int frames.ImageFrame.FRONT_COVER = 0x03 [static]

Definition at line 1225 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.

int frames.ImageFrame.ICON = 0x01 [static]

Definition at line 1223 of file frames.py.

int frames.ImageFrame.ILLUSTRATION = 0x12 [static]

Definition at line 1240 of file frames.py.

frames.ImageFrame.imageData = None [static]

Definition at line 1217 of file frames.py.

frames.ImageFrame.imageURL = None [static]

Definition at line 1220 of file frames.py.

int frames.ImageFrame.LEAD_ARTIST = 0x07 [static]

Definition at line 1229 of file frames.py.

int frames.ImageFrame.LEAFLET = 0x05 [static]

Definition at line 1227 of file frames.py.

int frames.ImageFrame.LYRICIST = 0x0C [static]

Definition at line 1234 of file frames.py.

Definition at line 1244 of file frames.py.

int frames.ImageFrame.MEDIA = 0x06 [static]

Definition at line 1228 of file frames.py.

frames.ImageFrame.mimeType = None [static]

Definition at line 1212 of file frames.py.

Definition at line 1243 of file frames.py.

int frames.ImageFrame.OTHER = 0x00 [static]

Definition at line 1222 of file frames.py.

int frames.ImageFrame.OTHER_ICON = 0x02 [static]

Definition at line 1224 of file frames.py.

Definition at line 1213 of file frames.py.

tuple frames.ImageFrame.picTypeToString = staticmethod(picTypeToString) [static]

Definition at line 1490 of file frames.py.

int frames.ImageFrame.PUBLISHER_LOGO = 0x14 [static]

Definition at line 1242 of file frames.py.

Definition at line 1235 of file frames.py.

tuple frames.ImageFrame.stringToPicType = staticmethod(stringToPicType) [static]

Definition at line 1443 of file frames.py.

Definition at line 584 of file frames.py.

int frames.ImageFrame.VIDEO = 0x10 [static]

Definition at line 1238 of file frames.py.


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