本文整理汇总了Python中picard.cluster.Cluster类的典型用法代码示例。如果您正苦于以下问题:Python Cluster类的具体用法?Python Cluster怎么用?Python Cluster使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Cluster类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_cluster_list
def get_cluster_list(patterns):
cl = ClusterList()
for pattern in patterns:
c = Cluster(pattern)
c.files = [File(f) for f in glob(pattern)]
cl.append(c)
return cl
示例2: test_add_to_cluster
def test_add_to_cluster(self):
cluster = Cluster('Test')
cluster.files = [self.test_files[0]]
update_metadata_images(cluster)
cluster.files += self.test_files[1:]
add_metadata_images(cluster, self.test_files[1:])
self.assertEqual(set(self.test_images), set(cluster.metadata.images))
self.assertFalse(cluster.metadata.has_common_images)
示例3: test_remove_from_cluster_with_common_images
def test_remove_from_cluster_with_common_images(self):
cluster = Cluster('Test')
cluster.files = list(self.test_files[1:])
update_metadata_images(cluster)
cluster.files.remove(self.test_files[1])
remove_metadata_images(cluster, [self.test_files[1]])
self.assertEqual(set(self.test_images[1:]), set(cluster.metadata.images))
self.assertTrue(cluster.metadata.has_common_images)
示例4: cluster
def cluster(self, objs):
"""Group files with similar metadata to 'clusters'."""
log.debug("Clustering %r", objs)
if len(objs) <= 1 or self.unclustered_files in objs:
files = list(self.unclustered_files.files)
else:
files = self.get_files_from_objects(objs)
for name, artist, files in Cluster.cluster(files, 1.0):
QtCore.QCoreApplication.processEvents()
cluster = self.load_cluster(name, artist)
for file in sorted(files, key=attrgetter('discnumber', 'tracknumber', 'base_filename')):
file.move(cluster)
示例5: test_update_cluster_images
def test_update_cluster_images(self):
cluster = Cluster('Test')
cluster.files = list(self.test_files)
update_metadata_images(cluster)
self.assertEqual(set(self.test_images), set(cluster.metadata.images))
self.assertFalse(cluster.metadata.has_common_images)
cluster.files.remove(self.test_files[2])
update_metadata_images(cluster)
self.assertEqual(set(self.test_images), set(cluster.metadata.images))
self.assertFalse(cluster.metadata.has_common_images)
cluster.files.remove(self.test_files[0])
update_metadata_images(cluster)
self.assertEqual(set(self.test_images[1:]), set(cluster.metadata.images))
self.assertTrue(cluster.metadata.has_common_images)
cluster.files.append(self.test_files[2])
update_metadata_images(cluster)
self.assertEqual(set(self.test_images[1:]), set(cluster.metadata.images))
self.assertTrue(cluster.metadata.has_common_images)
示例6: __init__
def __init__(self, id, discid=None):
DataObject.__init__(self, id)
self.metadata = Metadata()
self.tracks = []
self.loaded = False
self.load_task = None
self.release_group = None
self._files = 0
self._requests = 0
self._tracks_loaded = False
self._discid = discid
self._after_load_callbacks = queue.Queue()
self.unmatched_files = Cluster(_("Unmatched Files"), special=True, related_album=self, hide_if_empty=True)
示例7: __init__
def __init__(self, album_id, discid=None):
self.tracks = []
self.loaded = False
self.load_task = None
self.release_group = None
self._files = 0
self._requests = 0
self._tracks_loaded = False
self._discid = discid
self._after_load_callbacks = []
self.unmatched_files = Cluster(_("Unmatched Files"), special=True, related_album=self, hide_if_empty=True)
self.errors = []
self.status = None
示例8: cluster
def cluster(self, objs):
"""Group files with similar metadata to 'clusters'."""
log.debug("Clustering %r", objs)
if len(objs) <= 1 or self.unmatched_files in objs:
files = list(self.unmatched_files.files)
else:
files = self.get_files_from_objects(objs)
fcmp = lambda a, b: (
cmp(a.discnumber, b.discnumber) or
cmp(a.tracknumber, b.tracknumber) or
cmp(a.base_filename, b.base_filename))
for name, artist, files in Cluster.cluster(files, 1.0):
QtCore.QCoreApplication.processEvents()
cluster = self.load_cluster(name, artist)
for file in sorted(files, fcmp):
file.move(cluster)
示例9: __init__
def __init__(self, id, discid=None):
DataObject.__init__(self, id)
self.metadata = Metadata()
self.tracks = []
self.format_str = ""
self.tracks_str = ""
self.loaded = False
self.load_task = None
self.rgloaded = False
self.rgid = None
self._files = 0
self._requests = 0
self._discid = discid
self._after_load_callbacks = queue.Queue()
self._metadata_processors = None
self.other_versions = []
self.unmatched_files = Cluster(_("Unmatched Files"), special=True, related_album=self, hide_if_empty=True)
示例10: __init__
def __init__(self, album_id, discid=None):
DataObject.__init__(self, album_id)
self.metadata = Metadata()
self.orig_metadata = Metadata()
self.tracks = []
self.loaded = False
self.load_task = None
self.release_group = None
self._files = 0
self._requests = 0
self._tracks_loaded = False
self._discid = discid
self._after_load_callbacks = []
self.unmatched_files = Cluster(_("Unmatched Files"), special=True, related_album=self, hide_if_empty=True)
self.errors = []
self.status = None
self._album_artists = []
self.update_metadata_images_enabled = True
示例11: Album
class Album(object):
release_group_loaded = QtCore.pyqtSignal()
def __init__(self, album_id, discid=None):
self.tracks = []
self.loaded = False
self.load_task = None
self.release_group = None
self._files = 0
self._requests = 0
self._tracks_loaded = False
self._discid = discid
self._after_load_callbacks = []
self.unmatched_files = Cluster(_("Unmatched Files"), special=True, related_album=self, hide_if_empty=True)
self.errors = []
self.status = None
def __repr__(self):
return '<Album %s MetadataAlbum>' % (self.id)
def iterfiles(self, save=False):
for track in self.tracks:
for f in track.iterfiles():
yield f
if not save:
for f in self.unmatched_files.iterfiles():
yield f
示例12: Album
class Album(DataObject, Item):
release_group_loaded = QtCore.pyqtSignal()
def __init__(self, id, discid=None):
DataObject.__init__(self, id)
self.metadata = Metadata()
self.tracks = []
self.format_str = ""
self.loaded = False
self.load_task = None
self.rgloaded = False
self.rgid = None
self._files = 0
self._requests = 0
self._tracks_loaded = False
self._discid = discid
self._after_load_callbacks = queue.Queue()
self.other_versions = []
self.unmatched_files = Cluster(_("Unmatched Files"), special=True, related_album=self, hide_if_empty=True)
def __repr__(self):
return '<Album %s %r>' % (self.id, self.metadata[u"album"])
def iterfiles(self, save=False):
for track in self.tracks:
for file in track.iterfiles():
yield file
if not save:
for file in self.unmatched_files.iterfiles():
yield file
def _parse_release(self, document):
self.log.debug("Loading release %r", self.id)
self._tracks_loaded = False
release_node = document.metadata[0].release[0]
if release_node.id != self.id:
self.tagger.mbid_redirects[self.id] = release_node.id
album = self.tagger.albums.get(release_node.id)
if album:
self.log.debug("Release %r already loaded", release_node.id)
album.match_files(self.unmatched_files.files)
album.update()
self.tagger.remove_album(self)
return False
else:
del self.tagger.albums[self.id]
self.tagger.albums[release_node.id] = self
self.id = release_node.id
# Get release metadata
m = self._new_metadata
m.length = 0
release_to_metadata(release_node, m, config=self.config, album=self)
self.format_str = media_formats_from_node(release_node.medium_list[0])
self.rgid = release_node.release_group[0].id
if self._discid:
m['musicbrainz_discid'] = self._discid
# Custom VA name
if m['musicbrainz_albumartistid'] == VARIOUS_ARTISTS_ID:
m['albumartistsort'] = m['albumartist'] = self.config.setting['va_name']
# Convert Unicode punctuation
if self.config.setting['convert_punctuation']:
m.apply_func(asciipunct)
m['totaldiscs'] = release_node.medium_list[0].count
# Run album metadata plugins
try:
run_album_metadata_processors(self, m, release_node)
except:
self.log.error(traceback.format_exc())
self._release_node = release_node
return True
def _release_request_finished(self, document, http, error):
if self.load_task is None:
return
self.load_task = None
parsed = False
try:
if error:
self.log.error("%r", unicode(http.errorString()))
# Fix for broken NAT releases
if error == QtNetwork.QNetworkReply.ContentNotFoundError:
nats = False
nat_name = self.config.setting["nat_name"]
files = list(self.unmatched_files.files)
for file in files:
trackid = file.metadata["musicbrainz_trackid"]
if mbid_validate(trackid) and file.metadata["album"] == nat_name:
nats = True
self.tagger.move_file_to_nat(file, trackid)
self.tagger.nats.update()
if nats and not self.get_num_unmatched_files():
#.........这里部分代码省略.........
示例13: Album
class Album(DataObject, Item):
release_group_loaded = QtCore.pyqtSignal()
def __init__(self, album_id, discid=None):
DataObject.__init__(self, album_id)
self.metadata = Metadata()
self.orig_metadata = Metadata()
self.tracks = []
self.loaded = False
self.load_task = None
self.release_group = None
self._files = 0
self._requests = 0
self._tracks_loaded = False
self._discids = set()
if discid:
self._discids.add(discid)
self._after_load_callbacks = []
self.unmatched_files = Cluster(_("Unmatched Files"), special=True, related_album=self, hide_if_empty=True)
self.errors = []
self.status = None
self._album_artists = []
self.update_metadata_images_enabled = True
def __repr__(self):
return '<Album %s %r>' % (self.id, self.metadata["album"])
def iterfiles(self, save=False):
for track in self.tracks:
for file in track.iterfiles():
yield file
if not save:
for file in self.unmatched_files.iterfiles():
yield file
def enable_update_metadata_images(self, enabled):
self.update_metadata_images_enabled = enabled
def append_album_artist(self, album_artist_id):
"""Append artist id to the list of album artists
and return an AlbumArtist instance"""
album_artist = AlbumArtist(album_artist_id)
self._album_artists.append(album_artist)
return album_artist
def add_discid(self, discid):
if not discid:
return
self._discids.add(discid)
for track in self.tracks:
medium_discids = track.metadata.getall('~musicbrainz_discids')
track_discids = list(self._discids.intersection(medium_discids))
if track_discids:
track.metadata['musicbrainz_discid'] = track_discids
track.update()
for file in track.linked_files:
file.metadata['musicbrainz_discid'] = track_discids
file.update()
def get_album_artists(self):
"""Returns the list of album artists (as AlbumArtist objects)"""
return self._album_artists
def _parse_release(self, release_node):
log.debug("Loading release %r ...", self.id)
self._tracks_loaded = False
release_id = release_node['id']
if release_id != self.id:
self.tagger.mbid_redirects[self.id] = release_id
album = self.tagger.albums.get(release_id)
if album:
log.debug("Release %r already loaded", release_id)
album.match_files(self.unmatched_files.files)
album.update()
self.tagger.remove_album(self)
return False
else:
del self.tagger.albums[self.id]
self.tagger.albums[release_id] = self
self.id = release_id
# Make the release artist nodes available, since they may
# contain supplementary data (aliases, tags, genres, ratings)
# which aren't present in the release group, track, or
# recording artist nodes. We can copy them into those places
# wherever the IDs match, so that the data is shared and
# available for use in mbjson.py and external plugins.
self._release_artist_nodes = _create_artist_node_dict(release_node)
# Get release metadata
m = self._new_metadata
m.length = 0
rg_node = release_node['release-group']
rg = self.release_group = self.tagger.get_release_group_by_id(rg_node['id'])
rg.loaded_albums.add(self.id)
rg.refcount += 1
_copy_artist_nodes(self._release_artist_nodes, rg_node)
#.........这里部分代码省略.........
示例14: Album
class Album(DataObject, Item):
release_group_loaded = QtCore.pyqtSignal()
def __init__(self, id, discid=None):
DataObject.__init__(self, id)
self.metadata = Metadata()
self.tracks = []
self.loaded = False
self.load_task = None
self.release_group = None
self._files = 0
self._requests = 0
self._tracks_loaded = False
self._discid = discid
self._after_load_callbacks = []
self.unmatched_files = Cluster(_("Unmatched Files"), special=True, related_album=self, hide_if_empty=True)
self.errors = []
self.status = None
self._album_artists = []
def __repr__(self):
return '<Album %s %r>' % (self.id, self.metadata[u"album"])
def iterfiles(self, save=False):
for track in self.tracks:
for file in track.iterfiles():
yield file
if not save:
for file in self.unmatched_files.iterfiles():
yield file
def append_album_artist(self, id):
"""Append artist id to the list of album artists
and return an AlbumArtist instance"""
album_artist = AlbumArtist(id)
self._album_artists.append(album_artist)
return album_artist
def get_album_artists(self):
"""Returns the list of album artists (as AlbumArtist objects)"""
return self._album_artists
def _parse_release(self, document):
log.debug("Loading release %r ...", self.id)
self._tracks_loaded = False
release_node = document.metadata[0].release[0]
if release_node.id != self.id:
self.tagger.mbid_redirects[self.id] = release_node.id
album = self.tagger.albums.get(release_node.id)
if album:
log.debug("Release %r already loaded", release_node.id)
album.match_files(self.unmatched_files.files)
album.update()
self.tagger.remove_album(self)
return False
else:
del self.tagger.albums[self.id]
self.tagger.albums[release_node.id] = self
self.id = release_node.id
# Get release metadata
m = self._new_metadata
m.length = 0
rg_node = release_node.release_group[0]
rg = self.release_group = self.tagger.get_release_group_by_id(rg_node.id)
rg.loaded_albums.add(self.id)
rg.refcount += 1
release_group_to_metadata(rg_node, rg.metadata, rg)
m.copy(rg.metadata)
release_to_metadata(release_node, m, album=self)
if self._discid:
m['musicbrainz_discid'] = self._discid
# Custom VA name
if m['musicbrainz_albumartistid'] == VARIOUS_ARTISTS_ID:
m['albumartistsort'] = m['albumartist'] = config.setting['va_name']
# Convert Unicode punctuation
if config.setting['convert_punctuation']:
m.apply_func(asciipunct)
m['totaldiscs'] = release_node.medium_list[0].count
# Add album to collections
if "collection_list" in release_node.children:
for node in release_node.collection_list[0].collection:
if node.editor[0].text.lower() == config.persist["oauth_username"].lower():
if node.id not in user_collections:
user_collections[node.id] = \
Collection(node.id, node.name[0].text, node.release_list[0].count)
user_collections[node.id].releases.add(self.id)
# Run album metadata plugins
try:
run_album_metadata_processors(self, m, release_node)
#.........这里部分代码省略.........
示例15: Album
class Album(DataObject, Item):
release_group_loaded = QtCore.pyqtSignal()
def __init__(self, id, discid=None):
DataObject.__init__(self, id)
self.metadata = Metadata()
self.tracks = []
self.loaded = False
self.load_task = None
self.release_group = None
self._files = 0
self._requests = 0
self._tracks_loaded = False
self._discid = discid
self._after_load_callbacks = []
self.unmatched_files = Cluster(_("Unmatched Files"), special=True, related_album=self, hide_if_empty=True)
self.errors = []
def __repr__(self):
return "<Album %s %r>" % (self.id, self.metadata[u"album"])
def iterfiles(self, save=False):
for track in self.tracks:
for file in track.iterfiles():
yield file
if not save:
for file in self.unmatched_files.iterfiles():
yield file
def _parse_release(self, document):
log.debug("Loading release %r", self.id)
self._tracks_loaded = False
release_node = document.metadata[0].release[0]
if release_node.id != self.id:
self.tagger.mbid_redirects[self.id] = release_node.id
album = self.tagger.albums.get(release_node.id)
if album:
log.debug("Release %r already loaded", release_node.id)
album.match_files(self.unmatched_files.files)
album.update()
self.tagger.remove_album(self)
return False
else:
del self.tagger.albums[self.id]
self.tagger.albums[release_node.id] = self
self.id = release_node.id
# Get release metadata
m = self._new_metadata
m.length = 0
rg_node = release_node.release_group[0]
rg = self.release_group = self.tagger.get_release_group_by_id(rg_node.id)
rg.loaded_albums.add(self.id)
rg.refcount += 1
release_group_to_metadata(rg_node, rg.metadata, rg)
m.copy(rg.metadata)
release_to_metadata(release_node, m, album=self)
if self._discid:
m["musicbrainz_discid"] = self._discid
# Custom VA name
if m["musicbrainz_albumartistid"] == VARIOUS_ARTISTS_ID:
m["albumartistsort"] = m["albumartist"] = config.setting["va_name"]
# Convert Unicode punctuation
if config.setting["convert_punctuation"]:
m.apply_func(asciipunct)
m["totaldiscs"] = release_node.medium_list[0].count
# Add album to collections
if "collection_list" in release_node.children:
for node in release_node.collection_list[0].collection:
if node.editor[0].text.lower() == config.setting["username"].lower():
if node.id not in user_collections:
user_collections[node.id] = Collection(node.id, node.name[0].text, node.release_list[0].count)
user_collections[node.id].releases.add(self.id)
# Run album metadata plugins
try:
run_album_metadata_processors(self, m, release_node)
except:
self.error_append(traceback.format_exc())
self._release_node = release_node
return True
def _release_request_finished(self, document, http, error):
if self.load_task is None:
return
self.load_task = None
parsed = False
try:
if error:
self.error_append(unicode(http.errorString()))
#.........这里部分代码省略.........