def tagmp3(filename, title=None, artist=None, album=None, track=None, tracktotal=None, year=None): """ use eyeD3 directly from inside kaa.metadata to set the tag. We default to 2.3 since even though 2.4 is the accepted standard now, more players support 2.3 """ import kaa.metadata.audio.eyeD3 as eyeD3 try: tag = eyeD3.Tag() tag.link(String(filename)) tag.header.setVersion(eyeD3.ID3_V2_3) if artist: tag.setArtist(String(artist)) if album: tag.setAlbum(String(album)) if title: tag.setTitle(String(title)) if track: tag.setTrackNum( (track, tracktotal)) # eyed3 accepts None for tracktotal if year: tag.setDate(year) tag.update() except: print 'Cannot tag \"%s\"' % (String(filename)) return
def __init__(self, dirname, force=False, rescan=False): self.artist = '' self.album = '' self.year = '' self.length = 0 self.changed = False self.force = force self.tag = eyeD3.Tag() cachefile = vfs.getoverlay(os.path.join(dirname, '..', 'freevo.cache')) subdirs = util.getdirnames(dirname, softlinks=False) filelist = None if not rescan: for subdir in subdirs: d = AudioParser(subdir, rescan) if d.changed: break else: # no changes in all subdirs, looks good if os.path.isfile(cachefile) and \ os.stat(dirname)[stat.ST_MTIME] <= os.stat(cachefile)[stat.ST_MTIME]: # and no changes in here. Do not parse everything again if force: # forces? We need to load our current values info = mediainfo.get(dirname) if info: for type in ('artist', 'album', 'year', 'length'): if info.has_key(type): setattr(self, type, info[type]) return if not filelist: filelist = util.match_files(dirname, config.AUDIO_SUFFIX) if not filelist and not subdirs: # no files in here? We are done return # ok, something changed here, too bad :-( self.changed = True self.force = False # scan all subdirs for subdir in subdirs: d = AudioParser(subdir, force=True, rescan=rescan) for type in ('artist', 'album', 'year'): setattr(self, type, self.strcmp(getattr(self, type), getattr(d, type))) self.length += d.length # cache dir first mediainfo.cache_dir(dirname) use_tracks = True for song in filelist: try: data = mediainfo.get(song) for type in ('artist', 'album'): setattr(self, type, self.strcmp(getattr(self, type), data[type])) self.year = self.strcmp(self.year, data['date']) if data['length']: self.length += int(data['length']) use_tracks = use_tracks and data['trackno'] except OSError: pass if use_tracks and (self.album or self.artist): mediainfo.set(dirname, 'audio_advanced_sort', True) if not self.length: return for type in ('artist', 'album', 'year', 'length'): if getattr(self, type): mediainfo.set(dirname, type, getattr(self, type)) data = mediainfo.get(dirname) modtime = os.stat(dirname)[stat.ST_MTIME] if not data['coverscan'] or data['coverscan'] != modtime: data.store('coverscan', modtime) self.extract_image(dirname)