Back to index

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

List of all members.

Public Member Functions

def __init__
def getId
def getName
def setId
def setName
def set
def parse
def __str__

Static Public Attributes

 id = None;
 name = None;

Detailed Description

Definition at line 1424 of file tag.py.


Constructor & Destructor Documentation

def tag.Genre.__init__ (   self,
  id = None,
  name = None 
)

Definition at line 1428 of file tag.py.

01428 
01429    def __init__(self, id = None, name = None):
01430       if id is not None:
01431          self.setId(id);
01432       elif name is not None:
01433          self.setName(name);

Here is the call graph for this function:


Member Function Documentation

def tag.Genre.__str__ (   self)

Definition at line 1578 of file tag.py.

01578 
01579    def __str__(self):
01580       s = "";
01581       if (self.id != None and
01582               ((not utils.itunesCompat()) or
01583                (self.id <= GenreMap.ITUNES_GENRE_MAX))):
01584          s += "(" + str(self.id) + ")"
01585       if self.name:
01586          s += self.name;
01587       return s;

Here is the call graph for this function:

def tag.Genre.getId (   self)

Definition at line 1434 of file tag.py.

01434 
01435    def getId(self):
      return self.id;
def tag.Genre.getName (   self)

Definition at line 1436 of file tag.py.

01436 
01437    def getName(self):
01438       return self.name;

def tag.Genre.parse (   self,
  genreStr 
)

Definition at line 1514 of file tag.py.

01514 
01515    def parse(self, genreStr):
01516       genreStr =\
01517           str(genreStr.encode('utf-8')).strip(string.whitespace + '\x00');
01518       self.id = None;
01519       self.name = None;
01520 
01521       if not genreStr:
01522          return;
01523 
01524       # XXX: Utf-16 conversions leave a null byte at the end of the string.
01525       while genreStr[len(genreStr) - 1] == "\x00":
01526          genreStr = genreStr[:len(genreStr) - 1];
01527          if len(genreStr) == 0:
01528             break;
01529 
01530       # ID3 v1 style.
01531       # Match 03, 34, 129.
01532       regex = re.compile("[0-9][0-9]?[0-9]?$");
01533       if regex.match(genreStr):
01534          if len(genreStr) != 1 and genreStr[0] == '0':
01535             genreStr = genreStr[1:];
01536 
01537          self.setId(int(genreStr));
01538          return;
01539 
01540       # ID3 v2 style.
01541       # Match (03), (0)Blues, (15) Rap
01542       regex = re.compile("\(([0-9][0-9]?[0-9]?)\)(.*)$");
01543       m = regex.match(genreStr);
01544       if m:
01545          (id, name) = m.groups();
01546          if len(id) != 1 and id[0] == '0':
01547             id = id[1:];
01548 
01549          if id and name:
01550             self.set(int(id), name.strip());
01551          else:
01552             self.setId(int(id));
01553          return;
01554 
01555       # Non standard, but witnessed.
01556       # Match genre alone. e.g. Rap, Rock, blues, 'Rock|Punk|Pop-Punk', etc
01557       '''
01558       regex = re.compile("^[A-Z 0-9+/\-\|!&'\.]+\00*$", re.IGNORECASE)
01559       if regex.match(genreStr):
01560          print "boo"
01561          self.setName(genreStr);
01562          return;
01563      '''
01564 
01565       # non standard, but witnessed. 
01566       # Match delimited-separated list of genres alone.
01567       # e.g. 'breaks, electronic', 'hardcore|nyhc' 
01568       regex = re.compile(
01569               r"^([A-Z 0-9+/\-\|!&'\.]+)([,;|][A-Z 0-9+/\-\|!&'\.]+)*$",
01570               re.IGNORECASE)
01571       if regex.match(genreStr):
01572          print "boo"
01573          self.setName(genreStr);
01574          return;
01575 
01576       raise GenreException("Genre string cannot be parsed with '%s': %s" %\
01577                            (regex.pattern, genreStr));

Here is the call graph for this function:

def tag.Genre.set (   self,
  id,
  name 
)

Definition at line 1487 of file tag.py.

01487 
01488    def set(self, id, name):
01489       if not isinstance(id, int):
01490          raise GenreException("Invalid genre id: " + id);
01491       if not isinstance(name, str):
01492          raise GenreException("Invalid genre name: " + str(name));
01493 
01494       if not utils.strictID3():
01495          self.id = id;
01496          self.name = name;
01497       else:
01498          try:
01499             if genres[name] != id:
01500                raise GenreException("eyeD3.genres[" + str(id) + "] " +\
01501                                     "does not match " + name);
01502             self.id = id;
01503             self.name = name;
01504          except:
01505             raise GenreException("eyeD3.genres[" + str(id) + "] " +\
01506                                  "does not match " + name);

Here is the call graph for this function:

Here is the caller graph for this function:

def tag.Genre.setId (   self,
  id 
)

Definition at line 1444 of file tag.py.

01444 
01445    def setId(self, id):
01446       if not isinstance(id, int):
01447          raise TypeError("Invalid genre id: " + str(id));
01448 
01449       try:
01450           name = genres[id];
01451       except Exception, ex:
01452           if utils.strictID3():
01453               raise GenreException("Invalid genre id: " + str(id));
01454 
01455       if utils.strictID3() and not name:
01456           raise GenreException("Genre id maps to a null name: " + str(id));
01457 
01458       self.id = id;
01459       self.name = name;

Here is the call graph for this function:

Here is the caller graph for this function:

def tag.Genre.setName (   self,
  name 
)

Definition at line 1465 of file tag.py.

01465 
01466    def setName(self, name):
01467       if not isinstance(name, str):
01468          raise GenreException("Invalid genre name: " + str(name));
01469 
01470       try:
01471          id = genres[name];
01472          if (not utils.itunesCompat()) or (id <= GenreMap.ITUNES_GENRE_MAX):
01473             # Get titled case.
01474             name = genres[id];
01475       except:
01476           if utils.strictID3():
01477               raise GenreException("Invalid genre name: " + name);
01478           id = None;
01479 
01480       self.id = id;
01481       self.name = name;
01482 

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

tag.Genre.id = None; [static]

Definition at line 1425 of file tag.py.

tag.Genre.name = None; [static]

Definition at line 1426 of file tag.py.


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