def list_tags_disk(self): """ List all the tags directly from file metadata. Can be slow, use with caution. """ try: f = metadata.get_format(self.get_loc()) except Exception: # TODO: What exception? return None if not f: return None return f._get_raw().keys()
def get_tag_disk(self, tag): """ Read a tag directly from disk. Can be slow, use with caution. Intended for use with large fields like covers and lyrics that shouldn't be loaded to the in-mem db. """ try: f = metadata.get_format(self.get_loc()) except Exception: # TODO: What exception? return None if not f: return None return f.read_tags([tag]).get(tag)
def write_tags(self): """ Writes tags to the file for this Track. Returns False if unsuccessful, and a Format object from 'metadata' otherwise. """ try: f = metadata.get_format(self.get_loc()) if f is None: return False # not a supported type f.write_tags(self.__tags) return f except IOError: return False except Exception: return False
def write_tags(self): """ Writes tags to the file for this Track. Returns False if unsuccessful, and a Format object from `xl.metadata` otherwise. """ try: f = metadata.get_format(self.get_loc()) if f is None: return False # not a supported type f.write_tags(self.__tags) return f except IOError: return False except Exception: return False
def set_tags(self): """ Reads tags from the file and set for this Track. Returns False if unsuccessful, otherwise returns Format object from 'src.metadata'. """ try: f = metadata.get_format(self.get_loc()) if f is None: self._scan_valid = False return False # not a supported type ntags = f.read_all() for k, v in ntags.iteritems(): self.set_tag_raw(k, v) # remove tags that have been deleted in the file, while # taking into account that the db may have tags not # supported by the file's tag format. if f.others: supported_tags = [ t for t in self.list_tags() if not t.startswith("__") ] else: supported_tags = f.tag_mapping.keys() for tag in supported_tags: if tag not in ntags.keys(): self.set_tag_raw(tag, None) # fill out file specific items mtime = unicode( datetime.fromtimestamp(os.stat( self.get_loc()).st_mtime).strftime(datetime_format)) self.set_tag_raw('__modified', mtime) # TODO: this probably breaks on non-local files self.set_tag_raw('__basedir', self.get_basedir()) self.set_tag_raw('__basename', self.get_basename()) self._scan_valid = True return f except Exception, e: print e self._scan_valid = False return False
def set_tags(self): """ Reads tags from the file and set for this Track. Returns False if unsuccessful, otherwise returns Format object from 'src.metadata'. """ try: f = metadata.get_format(self.get_loc()) if f is None: self._scan_valid = False return False # not a supported type ntags = f.read_all() for k, v in ntags.iteritems(): self.set_tag_raw(k, v) # remove tags that have been deleted in the file, while # taking into account that the db may have tags not # supported by the file's tag format. if f.others: supported_tags = [t for t in self.list_tags() if not t.startswith("__")] else: supported_tags = f.tag_mapping.keys() for tag in supported_tags: if tag not in ntags.keys(): self.set_tag_raw(tag, None) # fill out file specific items mtime = unicode(datetime.fromtimestamp( os.stat(self.get_loc()).st_mtime).strftime(datetime_format)) self.set_tag_raw('__modified', mtime) # TODO: this probably breaks on non-local files self.set_tag_raw('__basedir', self.get_basedir()) self.set_tag_raw('__basename', self.get_basename()) self._scan_valid = True return f except Exception, e: print e self._scan_valid = False return False
def read_tags(self): """ Reads tags from the file for this Track. Returns False if unsuccessful, and a Format object from `xl.metadata` otherwise. """ try: f = metadata.get_format(self.get_loc()) if f is None: self._scan_valid = False return False # not a supported type ntags = f.read_all() for k, v in ntags.iteritems(): self.__tags[k] = v # remove tags that have been deleted in the file, while # taking into account that the db may have tags not # supported by the file's tag format. if f.others: supported_tags = [ t for t in self.list_tags() \ if not t.startswith("__") ] else: supported_tags = f.tag_mapping.keys() for tag in supported_tags: if tag not in ntags.keys(): self.__tags[tag] = None # fill out file specific items mtime = time.ctime(os.path.getmtime(self.get_loc())) self.__tags['__modified'] = mtime # TODO: this probably breaks on non-local files path = os.path.dirname(self.get_loc()) self.__tags['__basedir'] = path self._scan_valid = True return f except Exception: self._scan_valid = False return False