ApeTag (version 1.2)
index
/data/code/ape_tag_libs/python/ApeTag.py

Module for manipulating APE and ID3v1 tags
 
Public Function Arguments
-------------------------
fil: filename string OR already opened file or file-like object that supports
    flush, seek, read, truncate, tell, and write
fields: dictionary like object of tag fields that has an iteritems method
    which is an iterator of key, value tuples. 
    APE:
        key: must be a regular string with length 2-255 inclusive, containing
            only ASCII characters in the range 0x20-0x7f
        value: must be a string or a list or tuple of them, or an ApeItem
    ID3:
        key: must be title, artist, album, year, comment, genre, or track*
            (i.e. track or tracknumber)
        value: should be a string except for track* and genre
            track*: integer or sting representation of one
            genre: integer or string (if string, must be a case insensitive
                match for one of the strings in id3genres to be recognized)
removefields (updateape and updatetags): iterable of fields to remove from the
    APE tag (and set to blank in the ID3 tag).
 
Public Functions Return
-----------------------
0 on success of delete functions
bool on success of has functions
string on success of getraw functions
dict on success of create, update, replace, modify, or getfields
    key is the field name as a string
    (APE) value is an ApeItem, which is a list subclass with the field values
        stored in the list as strings, and the following special attributes:
        key: same as key of dict
        readonly: whether the field was marked read only
        type: type of tag field (utf8, binary, external, or reserved),
              utf8 type means values in list are unicode strings
    (ID3) value is a regular string
    
Public Functions Raise
----------------------
IOError on problem accessing file (make sure read/write access is allowed
    for the file if you are trying to modify the tag)
(APE functions only) UnicodeError on problems converting regular strings to
    UTF-8 (See note, or just use unicode strings)
TagError on other errors
 
Callback Functions
------------------
The modify* functions take callback functions and extra keyword arguments.
The callback functions are called with the tag dictionary and any extra keyword
arguments given in the call to modify*.  This dictionary should be modified and
must be returned by the callback functions.  There isn't much error checking
done after this stage, so incorrectly written callback functions may result in
corrupt tags or exceptions being raised elsewhere in the module.  The 
modifytags function takes two separate callback functions, one for the APE tag
and one for the ID3 tag.  See the _update*tagcallback functions for examples of
how callback functions should be written.
    
Notes
-----
When using functions that modify both tags, the accepted arguments and return
    value are the same for the APE funtion.
Raising errors other than IOError, UnicodeError, or TagError is considered a
    bug unless fields contains a non-basestring (or a list containing a
    non-basestring).
Only APEv2 tags are supported. APEv1 tags without a header are not supported.
Only writes ID3v1.1 tags.  Assumes all tags are ID3v1.1.  The only exception to
    this is when it detects an ID3v1.0 tag, it will return 0 as the track
    number in getfields.
The APE tag is appended to the end of the file.  If the file already has an 
    ID3v1 tag at the end, it is recognized and the APE tag is placed directly 
    before it.  
Default maximum size for the APE tag is 8192 bytes, as recommended by the APE
    spec.  This can be changed by modifying the _maxapesize variable.  
Read-only flags can be read, created, and modified (they are not respected).
If you are storing non 7-bit ASCII data in a tag, you should pass in unicode
    strings instead of regular strings, or pass in an already created ApeItem.
Inserting binary data into tags is "strongly unrecommended."
This library doesn't check to make sure that tag items marked as external are
    in the proper format.
APEv2 specification is here:
    http://wiki.hydrogenaudio.org/index.php?title=APEv2_specification

 
Classes
       
__builtin__.list(__builtin__.object)
ApeItem
exceptions.StandardError(exceptions.Exception)
TagError

 
class ApeItem(__builtin__.list)
    Contains individual APE tag items
 
 
Method resolution order:
ApeItem
__builtin__.list
__builtin__.object

Methods defined here:
__init__(self, key=None, values=[], type='utf8', readonly=False)
maketag(self)
Return on disk representation of tag item
 
parsetag(maketag(), 0) should result in no change to self
parsetag(self, data, curpos)
Parse next tag from data string, starting at current position
validkey(self, key)
Check key to make sure it is a valid ApeItem key

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Methods inherited from __builtin__.list:
__add__(...)
x.__add__(y) <==> x+y
__contains__(...)
x.__contains__(y) <==> y in x
__delitem__(...)
x.__delitem__(y) <==> del x[y]
__delslice__(...)
x.__delslice__(i, j) <==> del x[i:j]
 
Use of negative indices is not supported.
__eq__(...)
x.__eq__(y) <==> x==y
__ge__(...)
x.__ge__(y) <==> x>=y
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__gt__(...)
x.__gt__(y) <==> x>y
__hash__(...)
x.__hash__() <==> hash(x)
__iadd__(...)
x.__iadd__(y) <==> x+=y
__imul__(...)
x.__imul__(y) <==> x*=y
__iter__(...)
x.__iter__() <==> iter(x)
__le__(...)
x.__le__(y) <==> x<=y
__len__(...)
x.__len__() <==> len(x)
__lt__(...)
x.__lt__(y) <==> x<y
__mul__(...)
x.__mul__(n) <==> x*n
__ne__(...)
x.__ne__(y) <==> x!=y
__repr__(...)
x.__repr__() <==> repr(x)
__reversed__(...)
L.__reversed__() -- return a reverse iterator over the list
__rmul__(...)
x.__rmul__(n) <==> n*x
__setitem__(...)
x.__setitem__(i, y) <==> x[i]=y
__setslice__(...)
x.__setslice__(i, j, y) <==> x[i:j]=y
 
Use  of negative indices is not supported.
append(...)
L.append(object) -- append object to end
count(...)
L.count(value) -> integer -- return number of occurrences of value
extend(...)
L.extend(iterable) -- extend list by appending elements from the iterable
index(...)
L.index(value, [start, [stop]]) -> integer -- return first index of value
insert(...)
L.insert(index, object) -- insert object before index
pop(...)
L.pop([index]) -> item -- remove and return item at index (default last)
remove(...)
L.remove(value) -- remove first occurrence of value
reverse(...)
L.reverse() -- reverse *IN PLACE*
sort(...)
L.sort(cmp=None, key=None, reverse=False) -- stable sort *IN PLACE*;
cmp(x, y) -> -1, 0, 1

Data and other attributes inherited from __builtin__.list:
__new__ = <built-in method __new__ of type object at 0x207acbe20>
T.__new__(S, ...) -> a new object with type S, a subtype of T

 
class TagError(exceptions.StandardError)
    Raised when there is an error during a tagging operation
 
 
Method resolution order:
TagError
exceptions.StandardError
exceptions.Exception
exceptions.BaseException
__builtin__.object

Data descriptors defined here:
__weakref__
list of weak references to the object (if defined)

Methods inherited from exceptions.StandardError:
__init__(...)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Data and other attributes inherited from exceptions.StandardError:
__new__ = <built-in method __new__ of type object at 0x207ac37e0>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from exceptions.BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)
__str__(...)
x.__str__() <==> str(x)

Data descriptors inherited from exceptions.BaseException:
__dict__
args
message
exception message

 
Functions
       
createape(fil, fields={})
Create/update APE tag in fil with the information in fields
createid3(fil, fields={})
Create/update ID3v1 tag in fil with the information in fields
createtags(fil, fields={})
Create/update both APE and ID3v1 tags on fil with the information in fields
deleteape(fil)
Delete APE tag from fil if it exists
deleteid3(fil)
Delete ID3v1 tag from fil if it exists
deletetags(fil)
Delete APE and ID3v1 tags from fil if either exists
getapefields(fil)
Return fields from APE tag in fil
getid3fields(fil)
Return fields from ID3v1 tag in fil (including blank fields)
getrawape(fil)
Return raw APE tag from fil
getrawid3(fil)
Return raw ID3v1 tag from fil
getrawtags(fil)
Get raw APE and ID3v1 tag tuple
gettagfields(fil)
Get APE and ID3v1 tag fields tuple
hasapetag(fil)
Return raw APE tag from fil
hasid3tag(fil)
Return raw ID3v1 tag from fil
hastags(fil)
Get raw APE and ID3v1 tag tuple
modifyape(fil, callback, action='update', **kwargs)
Modify APE tag using user-defined callback and kwargs
modifyid3(fil, callback, action='update', **kwargs)
Modify ID3v1 tag using user-defined callback and kwargs
modifytags(fil, apecallback, id3callback=True, action='update', **kwargs)
Modify APE and ID3v1 tags using user-defined callbacks and kwargs
 
Both apecallback and id3callback receive the same kwargs provided, so they
need to have the same interface.
printapetag(fil)
Print APE tag fields for fil
printid3tag(fil)
Print ID3 tag fields for fil
printtags(fil)
Print APE and ID3 tag fields for fil
replaceape(fil, fields={})
Replace/create APE tag in fil with the information in fields
replaceid3(fil, fields={})
Replace/create ID3v1 tag in fil with the information in fields
replacetags(fil, fields={})
Replace/create both APE and ID3v1 tags on fil with the information in fields
updateape(fil, fields={}, removefields=[])
Update APE tag in fil with the information in fields
updateid3(fil, fields={})
Update ID3v1 tag in fil with the information in fields
updatetags(fil, fields={}, removefields=[])
Update both APE and ID3v1 tags on fil with the information in fields

 
Data
        __version__ = '1.2'
apeitemkeys = ['Title', 'Artist', 'Album', 'Year', 'Comment', 'Genre', 'Track', 'Debut Album', 'Subtitle', 'Publisher', 'Conductor', 'Composer', 'Copyright', 'Publicationright', 'File', 'EAN/UPC', 'ISBN', 'Catalog', 'LC', 'Record Date', ...]
id3genres = ['Blues', 'Classic Rock', 'Country', 'Dance', 'Disco', 'Funk', 'Grunge', 'Hip-Hop', 'Jazz', 'Metal', 'New Age', 'Oldies', 'Other', 'Pop', 'R & B', 'Rap', 'Reggae', 'Rock', 'Techno', 'Industrial', ...]