def test_known_fields(self): fields = list(ReadWriteTestBase.tag_fields) fields.extend( ('encoder', 'images', 'genres', 'albumtype', 'artists', 'albumartists', 'url', 'mb_artistids', 'mb_albumartistids') ) assertCountEqual(self, MediaFile.fields(), fields)
def transfer_tags(src: Pathish, dst: Pathish, remove_art: bool = False) -> None: src = Path(src).resolve() dst = Path(dst).resolve() f = MediaFile(src) g = MediaFile(dst) for field in f.fields(): if remove_art and field in ("art", "images"): continue try: setattr(g, field, getattr(f, field)) except: pass g.save()
def _set_pattern(self, field): """Populate `self.fields_to_progs` for a given field. Do some sanity checks then compile the regexes. """ if field not in MediaFile.fields(): self._log.error(u'invalid field: {0}', field) elif field in ('id', 'path', 'album_id'): self._log.warning( u'field \'{0}\' ignored, zeroing ' u'it would be dangerous', field) else: try: for pattern in self.config[field].as_str_seq(): prog = re.compile(pattern, re.IGNORECASE) self.fields_to_progs.setdefault(field, []).append(prog) except confuse.NotFoundError: # Matches everything self.fields_to_progs[field] = []
def list_albums_with_no_metadata(library): """no album title or no band information""" no_metadata_albums = OrderedDict({"issue_type": "no_metadata_albums"}) required_fields = ['title', 'album', 'artist', 'albumartist', 'length'] albums = [] for band in library.bands: for album in band.albums: for track in album.tracks: file = MediaFile(track.path) fields = file.fields() if not len([value for value in fields if value in required_fields]): albums.append({"band": band, "album": album}) break no_metadata_albums.update({"album": albums}) return no_metadata_albums
def __init__(self): super(ZeroPlugin, self).__init__() self.register_listener('write', self.write_event) self.register_listener('import_task_choice', self.import_task_choice_event) self.config.add({ 'auto': True, 'fields': [], 'keep_fields': [], 'update_database': False, }) self.fields_to_progs = {} self.warned = False """Read the bulk of the config into `self.fields_to_progs`. After construction, `fields_to_progs` contains all the fields that should be zeroed as keys and maps each of those to a list of compiled regexes (progs) as values. A field is zeroed if its value matches one of the associated progs. If progs is empty, then the associated field is always zeroed. """ if self.config['fields'] and self.config['keep_fields']: self._log.warning( u'cannot blacklist and whitelist at the same time') # Blacklist mode. elif self.config['fields']: for field in self.config['fields'].as_str_seq(): self._set_pattern(field) # Whitelist mode. elif self.config['keep_fields']: for field in MediaFile.fields(): if (field not in self.config['keep_fields'].as_str_seq() and # These fields should always be preserved. field not in ('id', 'path', 'album_id')): self._set_pattern(field)
def test_fields_in_readable_fields(self): readable = MediaFile.readable_fields() for field in MediaFile.fields(): self.assertIn(field, readable)
def test_properties_from_fields(self): path = os.path.join(_common.RSRC, b'full.mp3') mediafile = MediaFile(path) for field in MediaFile.fields(): self.assertTrue(hasattr(mediafile, field))
def test_known_fields(self): fields = list(ReadWriteTestBase.tag_fields) fields.extend(('encoder', 'images', 'genres', 'albumtype')) assertCountEqual(self, MediaFile.fields(), fields)