def _finalize_loading_track(self, track_node, metadata, artists, va, absolutetracknumber, discpregap): track = Track(track_node.recording[0].id, self) self._new_tracks.append(track) # Get track metadata tm = track.metadata tm.copy(metadata) track_to_metadata(track_node, track) track.metadata["~absolutetracknumber"] = absolutetracknumber track._customize_metadata() self._new_metadata.length += tm.length artists.add(tm["artist"]) if va: tm["compilation"] = "1" if discpregap: tm["~discpregap"] = "1" # Run track metadata plugins try: run_track_metadata_processors(self, tm, self._release_node, track_node) except: self.error_append(traceback.format_exc()) return track
def test_1(self): class Track: pass node = XmlNode(children={ 'title': [XmlNode(text='Foo')], 'length': [XmlNode(text='180000')], 'position': [XmlNode(text='1')], 'recording': [XmlNode(attribs={'id': '123'})], 'artist_credit': [XmlNode(children={ 'name_credit': [XmlNode(attribs={'joinphrase': ' & '}, children={ 'artist': [XmlNode(attribs={'id': '456'}, children={ 'name': [XmlNode(text='Foo Bar')], 'sort_name': [XmlNode(text='Bar, Foo')] })] }), XmlNode(children={ 'artist': [XmlNode(attribs={'id': '789'}, children={ 'name': [XmlNode(text='Baz')], 'sort_name': [XmlNode(text='Baz')] })] })] })] }) track = Track() m = track.metadata = Metadata() track_to_metadata(node, track, config) self.failUnlessEqual('123', m['musicbrainz_trackid']) self.failUnlessEqual('456; 789', m['musicbrainz_artistid']) self.failUnlessEqual('Foo', m['title']) self.failUnlessEqual('Foo Bar & Baz', m['artist']) self.failUnlessEqual('Bar, Foo & Baz', m['artistsort'])
def _finalize_loading_track(self, track_node, metadata, artists, va, absolutetracknumber, discpregap): track = Track(track_node.recording[0].id, self) self._new_tracks.append(track) # Get track metadata tm = track.metadata tm.copy(metadata) track_to_metadata(track_node, track) track.metadata["~absolutetracknumber"] = absolutetracknumber track._customize_metadata() self._new_metadata.length += tm.length artists.add(tm["artist"]) if va: tm["compilation"] = "1" if discpregap: tm["~discpregap"] = "1" # Run track metadata plugins try: run_track_metadata_processors(self, tm, self._release_node, track_node) except: self.error_append(traceback.format_exc()) return track
def test_1(self): class Track: pass node = XmlNode(children={ 'title': [XmlNode(text='Foo')], 'length': [XmlNode(text='180000')], 'position': [XmlNode(text='1')], 'recording': [XmlNode(attribs={'id': '123'})], 'artist_credit': [XmlNode(children={ 'name_credit': [XmlNode(attribs={'joinphrase': ' & '}, children={ 'artist': [XmlNode(attribs={'id': '456'}, children={ 'name': [XmlNode(text='Foo Bar')], 'sort_name': [XmlNode(text='Bar, Foo')] })] }), XmlNode(children={ 'artist': [XmlNode(attribs={'id': '789'}, children={ 'name': [XmlNode(text='Baz')], 'sort_name': [XmlNode(text='Baz')] })] })] })] }) track = Track() m = track.metadata = Metadata() track_to_metadata(node, track, config) self.failUnlessEqual('123', m['musicbrainz_trackid']) self.failUnlessEqual('456; 789', m['musicbrainz_artistid']) self.failUnlessEqual('Foo', m['title']) self.failUnlessEqual('Foo Bar & Baz', m['artist']) self.failUnlessEqual('Bar, Foo & Baz', m['artistsort'])
def _track_to_metadata(self, track_node, track): # that's pretty ugly, but v1.2 requires the config argument # as it seems it was removed in v1.3 try: track_to_metadata(track_node, track) except TypeError: # noinspection PyArgumentList track_to_metadata(track_node, track, self.config)
def _track_to_metadata(self, track_node, track): # that's pretty ugly, but v1.2 requires the config argument # as it seems it was removed in v1.3 try: track_to_metadata(track_node, track) except TypeError: # noinspection PyArgumentList track_to_metadata(track_node, track, self.config)
def test_1(self): class Track: pass node = XmlNode( children={ "title": [XmlNode(text="Foo")], "length": [XmlNode(text="180000")], "position": [XmlNode(text="1")], "recording": [XmlNode(attribs={"id": "123"})], "artist_credit": [ XmlNode( children={ "name_credit": [ XmlNode( attribs={"joinphrase": " & "}, children={ "artist": [ XmlNode( attribs={"id": "456"}, children={ "name": [XmlNode(text="Foo Bar")], "sort_name": [XmlNode(text="Bar, Foo")], }, ) ] }, ), XmlNode( children={ "artist": [ XmlNode( attribs={"id": "789"}, children={ "name": [XmlNode(text="Baz")], "sort_name": [XmlNode(text="Baz")], }, ) ] } ), ] } ) ], } ) track = Track() m = track.metadata = Metadata() track_to_metadata(node, track, config) self.failUnlessEqual("123", m["musicbrainz_trackid"]) self.failUnlessEqual("456; 789", m["musicbrainz_artistid"]) self.failUnlessEqual("Foo", m["title"]) self.failUnlessEqual("Foo Bar & Baz", m["artist"]) self.failUnlessEqual("Bar, Foo & Baz", m["artistsort"])
def test_1(self): config.setting = settings class Track: pass node = XmlNode(attribs={'id': '321'}, children={ 'title': [XmlNode(text='Foo')], 'length': [XmlNode(text='180000')], 'position': [XmlNode(text='1')], 'recording': [XmlNode(attribs={'id': '123'}, children={ 'relation_list': [XmlNode(attribs={'target_type': 'work'}, children={ 'relation': [XmlNode(attribs={'type': 'performance'}, children={ 'work': [XmlNode(attribs={'id': 'workid123'}, children={ 'title': [XmlNode(text='Bar')], 'language': [XmlNode(text='eng')] })] })] })] })], 'artist_credit': [XmlNode(children={ 'name_credit': [XmlNode(attribs={'joinphrase': ' & '}, children={ 'artist': [XmlNode(attribs={'id': '456'}, children={ 'name': [XmlNode(text='Foo Bar')], 'sort_name': [XmlNode(text='Bar, Foo')] })] }), XmlNode(children={ 'artist': [XmlNode(attribs={'id': '789'}, children={ 'name': [XmlNode(text='Baz')], 'sort_name': [XmlNode(text='Baz')] })] })] })] }) track = Track() m = track.metadata = Metadata() track_to_metadata(node, track) self.assertEqual('123', m['musicbrainz_recordingid']) self.assertEqual('321', m['musicbrainz_trackid']) self.assertEqual('456; 789', m['musicbrainz_artistid']) self.assertEqual('Foo', m['title']) self.assertEqual('Foo Bar & Baz', m['artist']) self.assertEqual('Bar, Foo & Baz', m['artistsort']) self.assertEqual('workid123', m['musicbrainz_workid']) self.assertEqual('Bar', m['work']) self.assertEqual('eng', m['language'])
def test_1(self): config.setting = settings class Track: pass node = XmlNode(attribs={'id': u'321'}, children={ 'title': [XmlNode(text=u'Foo')], 'length': [XmlNode(text=u'180000')], 'position': [XmlNode(text=u'1')], 'recording': [XmlNode(attribs={'id': u'123'}, children={ 'relation_list': [XmlNode(attribs={'target_type': u'work'}, children={ 'relation': [XmlNode(attribs={'type': u'performance'}, children={ 'work': [XmlNode(attribs={'id': u'workid123'}, children={ 'title': [XmlNode(text=u'Bar')], 'language': [XmlNode(text=u'eng')] })] })] })] })], 'artist_credit': [XmlNode(children={ 'name_credit': [XmlNode(attribs={'joinphrase': u' & '}, children={ 'artist': [XmlNode(attribs={'id': u'456'}, children={ 'name': [XmlNode(text=u'Foo Bar')], 'sort_name': [XmlNode(text=u'Bar, Foo')] })] }), XmlNode(children={ 'artist': [XmlNode(attribs={'id': u'789'}, children={ 'name': [XmlNode(text=u'Baz')], 'sort_name': [XmlNode(text=u'Baz')] })] })] })] }) track = Track() m = track.metadata = Metadata() track_to_metadata(node, track) self.assertEqual(u'123', m['musicbrainz_recordingid']) self.assertEqual(u'321', m['musicbrainz_trackid']) self.assertEqual(u'456; 789', m['musicbrainz_artistid']) self.assertEqual(u'Foo', m['title']) self.assertEqual(u'Foo Bar & Baz', m['artist']) self.assertEqual(u'Bar, Foo & Baz', m['artistsort']) self.assertEqual(u'workid123', m['musicbrainz_workid']) self.assertEqual(u'Bar', m['work']) self.assertEqual(u'eng', m['language'])
def _finalize_loading(self, error): if error: self.metadata.clear() self.metadata['album'] = _("[could not load album %s]") % self.id del self._new_metadata del self._new_tracks self.update() return if self._requests > 0: return if not self._tracks_loaded: artists = set() totalalbumtracks = 0 djmix_ars = {} if hasattr(self._new_metadata, "_djmix_ars"): djmix_ars = self._new_metadata._djmix_ars for medium_node in self._release_node.medium_list[0].medium: mm = Metadata() mm.copy(self._new_metadata) medium_to_metadata(medium_node, mm) totalalbumtracks += int(mm["totaltracks"]) for dj in djmix_ars.get(mm["discnumber"], []): mm.add("djmixer", dj) for track_node in medium_node.track_list[0].track: track = Track(track_node.recording[0].id, self) self._new_tracks.append(track) # Get track metadata tm = track.metadata tm.copy(mm) track_to_metadata(track_node, track, self.config) track._customize_metadata() self._new_metadata.length += tm.length artists.add(tm["musicbrainz_artistid"]) # Run track metadata plugins try: run_track_metadata_processors(self, tm, self._release_node, track_node) except: self.log.error(traceback.format_exc()) totalalbumtracks = str(totalalbumtracks) for track in self._new_tracks: track.metadata["~totalalbumtracks"] = totalalbumtracks if len(artists) > 1: track.metadata["compilation"] = "1" del self._release_node self._tracks_loaded = True if not self._requests: # Prepare parser for user's script if self.config.setting["enable_tagger_script"]: script = self.config.setting["tagger_script"] if script: parser = ScriptParser() for track in self._new_tracks: # Run tagger script for each track try: parser.eval(script, track.metadata) except: self.log.error(traceback.format_exc()) # Strip leading/trailing whitespace track.metadata.strip_whitespace() # Run tagger script for the album itself try: parser.eval(script, self._new_metadata) except: self.log.error(traceback.format_exc()) self._new_metadata.strip_whitespace() for track in self.tracks: for file in list(track.linked_files): file.move(self.unmatched_files) self.metadata = self._new_metadata self.tracks = self._new_tracks del self._new_metadata del self._new_tracks self.loaded = True self.match_files(self.unmatched_files.files) self.update() self.tagger.window.set_statusbar_message(_('Album %s loaded'), self.id, timeout=3000) while self._after_load_callbacks.qsize() > 0: func = self._after_load_callbacks.get() func()
def _finalize_loading(self, error): if error: self.metadata.clear() self.metadata['album'] = _("[could not load album %s]") % self.id del self._new_metadata del self._new_tracks self.update() return if self._requests > 0: return if not self._tracks_loaded: artists = set() totalalbumtracks = 0 djmix_ars = {} if hasattr(self._new_metadata, "_djmix_ars"): djmix_ars = self._new_metadata._djmix_ars for medium_node in self._release_node.medium_list[0].medium: mm = Metadata() mm.copy(self._new_metadata) medium_to_metadata(medium_node, mm) totalalbumtracks += int(mm["totaltracks"]) for dj in djmix_ars.get(mm["discnumber"], []): mm.add("djmixer", dj) for track_node in medium_node.track_list[0].track: track = Track(track_node.recording[0].id, self) self._new_tracks.append(track) # Get track metadata tm = track.metadata tm.copy(mm) track_to_metadata(track_node, track, self.config) track._customize_metadata() self._new_metadata.length += tm.length artists.add(tm["musicbrainz_artistid"]) # Run track metadata plugins try: run_track_metadata_processors(self, tm, self._release_node, track_node) except: self.log.error(traceback.format_exc()) totalalbumtracks = str(totalalbumtracks) for track in self._new_tracks: track.metadata["~totalalbumtracks"] = totalalbumtracks if len(artists) > 1: track.metadata["compilation"] = "1" del self._release_node self._tracks_loaded = True if not self._requests: # Prepare parser for user's script if self.config.setting["enable_tagger_script"]: script = self.config.setting["tagger_script"] if script: parser = ScriptParser() for track in self._new_tracks: # Run tagger script for each track try: parser.eval(script, track.metadata) except: self.log.error(traceback.format_exc()) # Strip leading/trailing whitespace track.metadata.strip_whitespace() # Run tagger script for the album itself try: parser.eval(script, self._new_metadata) except: self.log.error(traceback.format_exc()) self._new_metadata.strip_whitespace() for track in self.tracks: for file in list(track.linked_files): file.move(self.unmatched_files) self.metadata = self._new_metadata self.tracks = self._new_tracks del self._new_metadata del self._new_tracks self.loaded = True self.match_files(self.unmatched_files.files) self.update() self.tagger.window.set_statusbar_message('Album %s loaded', self.id, timeout=3000) while self._after_load_callbacks.qsize() > 0: func = self._after_load_callbacks.get() func()
def test_1(self): config.setting = settings class Track: pass node = XmlNode( attribs={"id": u"321"}, children={ "title": [XmlNode(text=u"Foo")], "length": [XmlNode(text=u"180000")], "position": [XmlNode(text=u"1")], "recording": [ XmlNode( attribs={"id": u"123"}, children={ "relation_list": [ XmlNode( attribs={"target_type": u"work"}, children={ "relation": [ XmlNode( attribs={"type": u"performance"}, children={ "work": [ XmlNode( attribs={"id": u"workid123"}, children={ "title": [XmlNode(text=u"Bar")], "language": [XmlNode(text=u"eng")], }, ) ] }, ) ] }, ) ] }, ) ], "artist_credit": [ XmlNode( children={ "name_credit": [ XmlNode( attribs={"joinphrase": u" & "}, children={ "artist": [ XmlNode( attribs={"id": u"456"}, children={ "name": [XmlNode(text=u"Foo Bar")], "sort_name": [XmlNode(text=u"Bar, Foo")], }, ) ] }, ), XmlNode( children={ "artist": [ XmlNode( attribs={"id": u"789"}, children={ "name": [XmlNode(text=u"Baz")], "sort_name": [XmlNode(text=u"Baz")], }, ) ] } ), ] } ) ], }, ) track = Track() m = track.metadata = Metadata() track_to_metadata(node, track) self.assertEqual(u"123", m["musicbrainz_recordingid"]) self.assertEqual(u"321", m["musicbrainz_trackid"]) self.assertEqual(u"456; 789", m["musicbrainz_artistid"]) self.assertEqual(u"Foo", m["title"]) self.assertEqual(u"Foo Bar & Baz", m["artist"]) self.assertEqual(u"Bar, Foo & Baz", m["artistsort"]) self.assertEqual(u"workid123", m["musicbrainz_workid"]) self.assertEqual(u"Bar", m["work"]) self.assertEqual(u"eng", m["language"])
def _parse_release(self, document): self.log.debug("Loading release %r", self.id) release_node = document.metadata[0].release[0] if release_node.id != self.id: album = self.tagger.get_album_by_id(release_node.id) self.tagger.albumids[self.id] = release_node.id self.id = release_node.id if album: album.match_files(self.unmatched_files.files) album.update() self.tagger.remove_album(self) self.log.debug("Release %r already loaded", self.id) return False # 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 # 'Translate' artist name if self.config.setting['translate_artist_names']: m['albumartist'] = translate_artist(m['albumartist'], m['albumartistsort']) # Custom VA name if m['musicbrainz_albumartistid'] == VARIOUS_ARTISTS_ID: m['albumartistsort'] = m['albumartist'] = self.config.setting['va_name'] ignore_tags = [s.strip() for s in self.config.setting['ignore_tags'].split(',')] first_artist = None compilation = False track_counts = [] m['totaldiscs'] = release_node.medium_list[0].count self._metadata_processors = [partial(run_album_metadata_processors, self, m, release_node)] for medium_node in release_node.medium_list[0].medium: mm = Metadata() mm.copy(m) medium_to_metadata(medium_node, mm) track_counts.append(mm['totaltracks']) for track_node in medium_node.track_list[0].track: t = Track(track_node.recording[0].id, self) self._new_tracks.append(t) # Get track metadata tm = t.metadata tm.copy(mm) track_to_metadata(track_node, t, self.config) m.length += tm.length artist_id = tm['musicbrainz_artistid'] if compilation is False: if first_artist is None: first_artist = artist_id if first_artist != artist_id: compilation = True for track in self._new_tracks: track.metadata['compilation'] = '1' else: tm['compilation'] = '1' t._customize_metadata(ignore_tags) plugins = partial(run_track_metadata_processors, self, tm, release_node, track_node) self._metadata_processors.append(plugins) m["~totalalbumtracks"] = str(sum(map(int, track_counts))) self.tracks_str = " + ".join(track_counts) return True