Back to index

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

List of all members.

Public Member Functions

def __init__
def clear
def parse
def getSize
def setTagHeader
def addFrame
def setTextFrame
def setURLFrame
def setCommentFrame
def setLyricsFrame
def setUniqueFileIDFrame
def setUserTextFrame
def setUserURLFrame
def removeFramesByID
def removeFrameByIndex
def __getitem__

Public Attributes

 extendedHeader

Static Public Attributes

 tagHeader = None;

Detailed Description

Definition at line 1737 of file frames.py.


Constructor & Destructor Documentation

def frames.FrameSet.__init__ (   self,
  tagHeader,
  l = None 
)

Definition at line 1740 of file frames.py.

01740 
01741    def __init__(self, tagHeader, l = None):
01742       self.tagHeader = tagHeader;
01743       if l:
01744          for f in l:
01745             if not isinstance(f, Frame):
01746                raise TypeError("Invalid type added to FrameSet: " +\
01747                                f.__class__);
01748             self.append(f);


Member Function Documentation

def frames.FrameSet.__getitem__ (   self,
  key 
)

Definition at line 2146 of file frames.py.

02146 
02147    def __getitem__(self, key):
02148       if isinstance(key, int):
02149          if key >= 0 and key < len(self):
02150             return list.__getitem__(self, key)
02151          else:
02152             raise IndexError("FrameSet index out of range")
02153       elif isinstance(key, str):
02154          retList = list()
02155          for f in self:
02156             if f.header.id == key:
02157                retList.append(f)
02158          return retList
02159       else:
02160          raise TypeError("FrameSet key must be type int or string")

def frames.FrameSet.addFrame (   self,
  frame 
)

Definition at line 1837 of file frames.py.

01837 
01838    def addFrame(self, frame):
01839       fid = frame.header.id;
01840 
01841       # Text frame restrictions.
01842       # No multiples except for TXXX which must have unique descriptions.
01843       if strictID3() and TEXT_FRAME_RX.match(fid) and self[fid]:
01844          if not USERTEXT_FRAME_RX.match(fid):
01845             raise FrameException("Multiple %s frames not allowed." % fid);
01846          userTextFrames = self[fid];
01847          for frm in userTextFrames:
01848             if frm.description == frame.description:
01849                raise FrameException("Multiple %s frames with the same\
01850                                      description not allowed." % fid);
01851 
01852       # Comment frame restrictions.
01853       # Multiples must have a unique description/language combination.
01854       if strictID3() and COMMENT_FRAME_RX.match(fid) and self[fid]:
01855          commentFrames = self[fid];
01856          for frm in commentFrames:
01857             if frm.description == frame.description and\
01858                frm.lang == frame.lang:
01859                raise FrameException("Multiple %s frames with the same\
01860                                      language and description not allowed." %\
01861                                      fid);
01862 
01863       # Lyrics frame restrictions.
01864       # Multiples must have a unique description/language combination.
01865       if strictID3() and LYRICS_FRAME_RX.match(fid) and self[fid]:
01866          lyricsFrames = self[fid];
01867          for frm in lyricsFrames:
01868             if frm.description == frame.description and\
01869                frm.lang == frame.lang:
01870                raise FrameException("Multiple %s frames with the same\
01871                                      language and description not allowed." %\
01872                                      fid);
01873 
01874       # URL frame restrictions.
01875       # No multiples except for TXXX which must have unique descriptions.
01876       if strictID3() and URL_FRAME_RX.match(fid) and self[fid]:
01877          if not USERURL_FRAME_RX.match(fid):
01878             raise FrameException("Multiple %s frames not allowed." % fid);
01879          userUrlFrames = self[fid];
01880          for frm in userUrlFrames:
01881             if frm.description == frame.description:
01882                raise FrameException("Multiple %s frames with the same\
01883                                      description not allowed." % fid);
01884 
01885       # Music CD ID restrictions.
01886       # No multiples.
01887       if strictID3() and CDID_FRAME_RX.match(fid) and self[fid]:
01888          raise FrameException("Multiple %s frames not allowed." % fid);
01889 
01890       # Image (attached picture) frame restrictions.
01891       # Multiples must have a unique content desciptor.  I'm assuming that
01892       # the spec means the picture type.....
01893       if IMAGE_FRAME_RX.match(fid) and self[fid] and strictID3():
01894          imageFrames = self[fid];
01895          for frm in imageFrames:
01896             if frm.pictureType == frame.pictureType:
01897                raise FrameException("Multiple %s frames with the same "\
01898                                     "content descriptor not allowed." % fid);
01899 
01900       # Object (GEOB) frame restrictions.
01901       # Multiples must have a unique content desciptor.
01902       if OBJECT_FRAME_RX.match(fid) and self[fid] and strictID3():
01903          objectFrames = self[fid];
01904          for frm in objectFrames:
01905             if frm.description == frame.description:
01906                raise FrameException("Multiple %s frames with the same "\
01907                                     "content descriptor not allowed." % fid);
01908 
01909       # Play count frame (PCNT).  There may be only one
01910       if PLAYCOUNT_FRAME_RX.match(fid) and self[fid]:
01911          raise FrameException("Multiple %s frames not allowed." % fid);
01912 
01913       # Unique File identifier frame.  There may be only one with the same
01914       # owner_id
01915       if UNIQUE_FILE_ID_FRAME_RX.match(fid) and self[fid]:
01916           ufid_frames = self[fid];
01917           for frm in ufid_frames:
01918               if frm.owner_id == frame.owner_id:
01919                   raise FrameException("Multiple %s frames not allowed with "\
01920                                        "the same owner ID (%s)" %\
01921                                        (fid, frame.owner_id));
01922 
01923       self.append(frame);

Here is the call graph for this function:

Here is the caller graph for this function:

def frames.FrameSet.clear (   self)

Definition at line 1751 of file frames.py.

01751 
01752    def clear(self):
01753       del self[0:];

Here is the caller graph for this function:

def frames.FrameSet.getSize (   self)

Definition at line 1825 of file frames.py.

01825 
01826    def getSize(self):
01827       sz = 0;
01828       for f in self:
01829          sz += len(f.render());
01830       return sz;

def frames.FrameSet.parse (   self,
  f,
  tagHeader,
  extendedHeader 
)

Definition at line 1757 of file frames.py.

01757 
01758    def parse(self, f, tagHeader, extendedHeader):
01759       self.tagHeader = tagHeader;
01760       self.extendedHeader = extendedHeader
01761       paddingSize = 0;
01762       sizeLeft = tagHeader.tagSize - extendedHeader.size
01763       start_size = sizeLeft
01764       consumed_size = 0
01765 
01766       # Handle a tag-level unsync.  Some frames may have their own unsync bit
01767       # set instead.
01768       tagData = f.read(sizeLeft)
01769 
01770       # If the tag is 2.3 and the tag header unsync bit is set then all the
01771       # frame data is deunsync'd at once, otherwise it will happen on a per
01772       # frame basis.
01773       from eyeD3 import ID3_V2_3
01774       if tagHeader.unsync and tagHeader.version <= ID3_V2_3:
01775           TRACE_MSG("De-unsynching %d bytes at once (<= 2.3 tag)" %
01776                     len(tagData))
01777           og_size = len(tagData)
01778           tagData = deunsyncData(tagData)
01779           sizeLeft = len(tagData)
01780           TRACE_MSG("De-unsynch'd %d bytes at once (<= 2.3 tag) to %d bytes" %
01781                     (og_size, sizeLeft))
01782 
01783       # Adding bytes to simulate the tag header(s) in the buffer.  This keeps 
01784       # f.tell() values matching the file offsets.
01785       prepadding = '\x00' * 10  # Tag header
01786       prepadding += '\x00' * extendedHeader.size
01787       tagBuffer = StringIO(prepadding + tagData);
01788       tagBuffer.seek(len(prepadding));
01789 
01790       while sizeLeft > 0:
01791          TRACE_MSG("sizeLeft: " + str(sizeLeft));
01792          if sizeLeft < (10 + 1): # The size of the smallest frame.
01793             TRACE_MSG("FrameSet: Implied padding (sizeLeft < minFrameSize)");
01794             paddingSize = sizeLeft
01795             break;
01796 
01797          TRACE_MSG("+++++++++++++++++++++++++++++++++++++++++++++++++");
01798          TRACE_MSG("FrameSet: Reading Frame #" + str(len(self) + 1));
01799          frameHeader = FrameHeader(tagHeader);
01800          if not frameHeader.parse(tagBuffer):
01801             TRACE_MSG("No frame found, implied padding of %d bytes" % sizeLeft)
01802             paddingSize = sizeLeft
01803             break;
01804 
01805          # Frame data.
01806          if frameHeader.dataSize:
01807              TRACE_MSG("FrameSet: Reading %d (0x%X) bytes of data from byte "
01808                        "pos %d (0x%X)" % (frameHeader.dataSize,
01809                                           frameHeader.dataSize,
01810                                           tagBuffer.tell(),
01811                                           tagBuffer.tell()));
01812              data = tagBuffer.read(frameHeader.dataSize);
01813 
01814              TRACE_MSG("FrameSet: %d bytes of data read" % len(data));
01815 
01816              consumed_size += (frameHeader.FRAME_HEADER_SIZE +
01817                                frameHeader.dataSize)
01818              self.addFrame(createFrame(frameHeader, data, tagHeader))
01819 
01820          # Each frame contains dataSize + headerSize bytes.
01821          sizeLeft -= (frameHeader.FRAME_HEADER_SIZE + frameHeader.dataSize);
01822 
01823       return paddingSize

def frames.FrameSet.removeFrameByIndex (   self,
  index 
)

Definition at line 2128 of file frames.py.

02128 
02129    def removeFrameByIndex(self, index):
02130       if not isinstance(index, int):
02131          raise\
02132            FrameException("removeFrameByIndex only operates on a frame index")
02133       try:
02134          del self.frames[key]
02135          return 1
02136       except:
02137          return 0

def frames.FrameSet.removeFramesByID (   self,
  fid 
)

Definition at line 2112 of file frames.py.

02112 
02113    def removeFramesByID(self, fid):
02114       if not isinstance(fid, str):
02115          raise FrameException("removeFramesByID only operates on frame IDs")
02116 
02117       i = 0
02118       count = 0
02119       while i < len(self):
02120          if self[i].header.id == fid:
02121             del self[i]
02122             count += 1
02123          else:
02124             i += 1
02125       return count

def frames.FrameSet.setCommentFrame (   self,
  comment,
  description,
  lang = DEFAULT_LANG,
  encoding = None 
)

Definition at line 1968 of file frames.py.

01968 
01969                        encoding = None):
01970       assert(isinstance(comment, unicode) and isinstance(description, unicode))
01971 
01972       if self[COMMENT_FID]:
01973          found = 0
01974          for f in self[COMMENT_FID]:
01975             if f.lang == lang and f.description == description:
01976                f.comment = comment
01977                if encoding:
01978                    f.encoding = encoding
01979                found = 1
01980                break
01981          if not found:
01982             h = FrameHeader(self.tagHeader)
01983             h.id = COMMENT_FID
01984             if not encoding:
01985                 encoding = DEFAULT_ENCODING
01986             self.addFrame(CommentFrame(h, encoding = encoding, lang = lang,
01987                                        description = description,
01988                                        comment = comment))
01989       else:
01990         if not encoding:
01991             encoding = DEFAULT_ENCODING
01992         h = FrameHeader(self.tagHeader)
01993         h.id = COMMENT_FID
01994         self.addFrame(CommentFrame(h, encoding = encoding, lang = lang,
01995                                    description = description,
01996                                    comment = comment))

Here is the call graph for this function:

Here is the caller graph for this function:

def frames.FrameSet.setLyricsFrame (   self,
  lyrics,
  description,
  lang = DEFAULT_LANG,
  encoding = None 
)

Definition at line 2000 of file frames.py.

02000 
02001                        encoding = None):
02002       assert(isinstance(lyrics, unicode) and isinstance(description, unicode));
02003 
02004       if self[LYRICS_FID]:
02005          found = 0;
02006          for f in self[LYRICS_FID]:
02007             if f.lang == lang and f.description == description:
02008                f.lyrics = lyrics;
02009                if encoding:
02010                    f.encoding = encoding;
02011                found = 1;
02012                break;
02013          if not found:
02014             h = FrameHeader(self.tagHeader);
02015             h.id = LYRICS_FID;
02016             if not encoding:
02017                 encoding = DEFAULT_ENCODING;
02018             self.addFrame(LyricsFrame(h, encoding = encoding, lang = lang,
02019                                        description = description,
02020                                        lyrics = lyrics));
02021       else:
02022         if not encoding:
02023             encoding = DEFAULT_ENCODING;
02024         h = FrameHeader(self.tagHeader);
02025         h.id = LYRICS_FID;
02026         self.addFrame(LyricsFrame(h, encoding = encoding, lang = lang,
02027                                    description = description,
02028                                    lyrics = lyrics))

Here is the call graph for this function:

Here is the caller graph for this function:

def frames.FrameSet.setTagHeader (   self,
  tagHeader 
)

Definition at line 1831 of file frames.py.

01831 
01832    def setTagHeader(self, tagHeader):
01833       self.tagHeader = tagHeader;
01834       for f in self:
01835          f.header.setVersion(tagHeader);

def frames.FrameSet.setTextFrame (   self,
  frameId,
  text,
  encoding = None 
)

Definition at line 1927 of file frames.py.

01927 
01928    def setTextFrame(self, frameId, text, encoding=None):
01929       assert(type(text) == unicode)
01930 
01931       if not TEXT_FRAME_RX.match(frameId):
01932          raise FrameException("Invalid Frame ID: " + frameId)
01933 
01934       if self[frameId]:
01935           curr = self[frameId][0]
01936           if encoding:
01937               curr.encoding = encoding
01938 
01939           if isinstance(curr, DateFrame):
01940               curr.setDate(text)
01941           else:
01942               curr.text = text
01943       else:
01944           h = FrameHeader(self.tagHeader)
01945           h.id = frameId
01946           if not encoding:
01947               encoding = DEFAULT_ENCODING
01948           if frameId in DATE_FIDS:
01949               self.addFrame(DateFrame(h, encoding = encoding, date_str = text))
01950           else:
01951               self.addFrame(TextFrame(h, encoding = encoding, text = text))

Here is the call graph for this function:

Here is the caller graph for this function:

def frames.FrameSet.setUniqueFileIDFrame (   self,
  owner_id,
  id 
)

Definition at line 2029 of file frames.py.

02029 
02030    def setUniqueFileIDFrame(self, owner_id, id):
02031       assert(isinstance(owner_id, str) and isinstance(id, str))
02032 
02033       if self[UNIQUE_FILE_ID_FID]:
02034          found = 0
02035          for f in self[UNIQUE_FILE_ID_FID]:
02036              if f.owner_id == owner_id:
02037                  f.id = id
02038                  found = 1
02039                  break
02040          if not found:
02041             h = FrameHeader(self.tagHeader)
02042             h.id = UNIQUE_FILE_ID_FID
02043             self.addFrame(UniqueFileIDFrame(h, owner_id = owner_id, id = id))
02044       else:
02045         h = FrameHeader(self.tagHeader)
02046         h.id = UNIQUE_FILE_ID_FID
02047         self.addFrame(UniqueFileIDFrame(h, owner_id = owner_id, id = id))

Here is the call graph for this function:

def frames.FrameSet.setURLFrame (   self,
  frame_id,
  url 
)

Definition at line 1952 of file frames.py.

01952 
01953    def setURLFrame(self, frame_id, url):
01954       assert(type(url) == str)
01955 
01956       if frame_id not in URL_FIDS:
01957          raise FrameException("Invalid URL frame ID: %s" % frame_id)
01958 
01959       if self[frame_id]:
01960           self[frame_id][0].url = url
01961       else:
01962           h = FrameHeader(self.tagHeader)
01963           h.id = frame_id
01964           self.addFrame(URLFrame(h, url=url))

Here is the call graph for this function:

def frames.FrameSet.setUserTextFrame (   self,
  txt,
  description,
  encoding = None 
)

Definition at line 2050 of file frames.py.

02050 
02051    def setUserTextFrame(self, txt, description, encoding=None):
02052       assert(isinstance(txt, unicode))
02053       assert(isinstance(description, unicode));
02054 
02055       if self[USERTEXT_FID]:
02056          found = 0;
02057          for f in self[USERTEXT_FID]:
02058             if f.description == description:
02059                f.text = txt;
02060                if encoding:
02061                    f.encoding = encoding;
02062                found = 1;
02063                break;
02064          if not found:
02065              if not encoding:
02066                  encoding = DEFAULT_ENCODING;
02067              h = FrameHeader(self.tagHeader);
02068              h.id = USERTEXT_FID;
02069              self.addFrame(UserTextFrame(h, encoding = encoding,
02070                                          description = description,
02071                                          text = txt));
02072       else:
02073           if not encoding:
02074               encoding = DEFAULT_ENCODING;
02075           h = FrameHeader(self.tagHeader);
02076           h.id = USERTEXT_FID;
02077           self.addFrame(UserTextFrame(h, encoding = encoding,
02078                                       description = description,
02079                                       text = txt));

Here is the call graph for this function:

def frames.FrameSet.setUserURLFrame (   self,
  url,
  description,
  encoding = None 
)

Definition at line 2080 of file frames.py.

02080 
02081    def setUserURLFrame(self, url, description, encoding=None):
02082       assert(isinstance(url, str))
02083       assert(isinstance(description, unicode))
02084 
02085       if self[USERURL_FID]:
02086          found = 0
02087          for f in self[USERURL_FID]:
02088             if f.description == description:
02089                f.url = url
02090                if encoding:
02091                    f.encoding = encoding
02092                found = 1
02093                break
02094          if not found:
02095              if not encoding:
02096                  encoding = DEFAULT_ENCODING
02097              h = FrameHeader(self.tagHeader)
02098              h.id = USERURL_FID
02099              self.addFrame(UserURLFrame(h, encoding=encoding,
02100                                         description=description, url=url))
02101       else:
02102           if not encoding:
02103               encoding = DEFAULT_ENCODING
02104           h = FrameHeader(self.tagHeader)
02105           h.id = USERURL_FID
02106           self.addFrame(UserURLFrame(h, encoding=encoding,
02107                                      description=description, url=url))

Here is the call graph for this function:


Member Data Documentation

Definition at line 1759 of file frames.py.

frames.FrameSet.tagHeader = None; [static]

Definition at line 1738 of file frames.py.


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