Ejemplo n.º 1
0
 def test_compare_to_track(self):
     track_json = load_test_json('track.json')
     track = Track(track_json['id'])
     track_to_metadata(track_json, track)
     match = track.metadata.compare_to_track(track_json, File.comparison_weights)
     self.assertEqual(1.0, match.similarity)
     self.assertEqual(track_json, match.track)
Ejemplo n.º 2
0
    def _finalize_loading_track(self, track_node, metadata, artists, va,
                                absolutetracknumber, discpregap):
        track = Track(track_node['recording']['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
Ejemplo n.º 3
0
    def _finalize_loading_track(self, track_node, metadata, artists, va, absolutetracknumber, discpregap):
        track = Track(track_node['recording']['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
Ejemplo n.º 4
0
    def _finalize_loading_track(self, track_node, metadata, artists, extra_metadata=None):
        # As noted in `_parse_release` above, the release artist nodes
        # may contain supplementary data that isn't present in track
        # artist nodes. Similarly, the track artists may contain
        # information which the recording artists don't. Copy this
        # information across to wherever the artist IDs match.
        _copy_artist_nodes(self._release_artist_nodes, track_node)
        _copy_artist_nodes(self._release_artist_nodes, track_node['recording'])
        _copy_artist_nodes(_create_artist_node_dict(track_node), track_node['recording'])

        track = Track(track_node['recording']['id'], self)
        self._new_tracks.append(track)

        # Get track metadata
        tm = track.metadata
        tm.copy(metadata)
        track_to_metadata(track_node, track)
        track._customize_metadata()

        self._new_metadata.length += tm.length
        artists.add(tm["artist"])
        if extra_metadata:
            tm.update(extra_metadata)

        # Run track metadata plugins
        try:
            run_track_metadata_processors(self, tm, track_node, self._release_node)
        except BaseException:
            self.error_append(traceback.format_exc())

        return track
Ejemplo n.º 5
0
 def test_track(self):
     t = Track("1")
     m = t.metadata
     track_to_metadata(self.json_doc, t)
     self.assertEqual(m['title'], 'Lady')
     self.assertEqual(m['tracknumber'], '0')
     self.assertEqual(m['~musicbrainz_tracknumber'], '0')
Ejemplo n.º 6
0
 def test_compare_to_track_with_score(self):
     track_json = load_test_json('track.json')
     track = Track(track_json['id'])
     track_to_metadata(track_json, track)
     for score, sim in ((42, 0.42), ('42', 0.42), ('foo', 1.0), (None, 1.0)):
         track_json['score'] = score
         match = track.metadata.compare_to_track(track_json, File.comparison_weights)
         self.assertEqual(sim, match.similarity)
Ejemplo n.º 7
0
 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)
Ejemplo n.º 8
0
 def test_track(self):
     t = Track("1")
     m = t.metadata
     track_to_metadata(self.json_doc, t)
     self.assertEqual(m['title'], 'Speak to Me')
     self.assertEqual(m['musicbrainz_recordingid'], 'bef3fddb-5aca-49f5-b2fd-d56a23268d63')
     self.assertEqual(m['musicbrainz_trackid'], 'd4156411-b884-368f-a4cb-7c0101a557a2')
     self.assertEqual(m['~length'], '1:08')
     self.assertEqual(m['tracknumber'], '1')
     self.assertEqual(m['~musicbrainz_tracknumber'], 'A1')
     self.assertEqual(m['~recordingcomment'], 'original stereo mix')
     self.assertEqual(m['~recordingtitle'], 'Speak to Me')
Ejemplo n.º 9
0
 def test_track(self):
     t = Track("1")
     m = t.metadata
     track_to_metadata(self.json_doc, t)
     self.assertEqual(m['title'], 'Speak to Me')
     self.assertEqual(m['musicbrainz_recordingid'], 'bef3fddb-5aca-49f5-b2fd-d56a23268d63')
     self.assertEqual(m['musicbrainz_trackid'], 'd4156411-b884-368f-a4cb-7c0101a557a2')
     self.assertEqual(m['title'], 'Speak to Me')
     self.assertEqual(m['~length'], '1:08')
     self.assertEqual(m['tracknumber'], '1')
     self.assertEqual(m['~musicbrainz_tracknumber'], 'A1')
     self.assertEqual(m['~recordingcomment'], 'original stereo mix')
     self.assertEqual(m['~recordingtitle'], 'Speak to Me')
Ejemplo n.º 10
0
 def _load_tracks(self, release_node, album):
     # this happens after the album metadata processor in picard
     self.tracks = []
     for medium_node in release_node['media']:
         mm = Metadata()
         mm.copy(album._new_metadata)  # noqa
         medium_to_metadata(medium_node, mm)
         for track_node in medium_node['tracks']:
             track = Track(track_node['recording']['id'], album)
             self.tracks.append(track)
             # Get track metadata
             tm = track.metadata
             tm.copy(mm)
             track_to_metadata(track_node, track)
             track._customize_metadata()  # noqa
Ejemplo n.º 11
0
    def _finalize_loading_track(self, track_node, metadata, artists, va,
                                absolutetracknumber, discpregap):
        # As noted in `_parse_release` above, the release artist nodes
        # may contain supplementary data that isn't present in track
        # artist nodes. Similarly, the track artists may contain
        # information which the recording artists don't. Copy this
        # information across to wherever the artist IDs match.
        _copy_artist_nodes(self._release_artist_nodes, track_node)
        _copy_artist_nodes(self._release_artist_nodes, track_node['recording'])
        _copy_artist_nodes(_create_artist_node_dict(track_node),
                           track_node['recording'])

        track = Track(track_node['recording']['id'], self)
        self._new_tracks.append(track)

        # Get track metadata
        tm = track.metadata
        tm.copy(metadata)
        track_to_metadata(track_node, track)
        tm["~absolutetracknumber"] = absolutetracknumber
        track.orig_metadata.copy(tm)
        track._customize_metadata()

        self._new_metadata.length += tm.length
        artists.add(tm["artist"])
        if va:
            tm["compilation"] = "1"
        else:
            del tm["compilation"]
        if discpregap:
            tm["~discpregap"] = "1"

        # Run track metadata plugins
        try:
            run_track_metadata_processors(self, tm, self._release_node,
                                          track_node)
        except BaseException:
            self.error_append(traceback.format_exc())

        return track
Ejemplo n.º 12
0
    def _finalize_loading_track(self, track_node, metadata, artists, va, absolutetracknumber, discpregap):
        # As noted in `_parse_release` above, the release artist nodes
        # may contain supplementary data that isn't present in track
        # artist nodes. Similarly, the track artists may contain
        # information which the recording artists don't. Copy this
        # information across to wherever the artist IDs match.
        _copy_artist_nodes(self._release_artist_nodes, track_node)
        _copy_artist_nodes(self._release_artist_nodes, track_node['recording'])
        _copy_artist_nodes(_create_artist_node_dict(track_node), track_node['recording'])

        track = Track(track_node['recording']['id'], self)
        self._new_tracks.append(track)

        # Get track metadata
        tm = track.metadata
        tm.copy(metadata)
        track_to_metadata(track_node, track)
        tm["~absolutetracknumber"] = absolutetracknumber
        track.orig_metadata.copy(tm)
        track._customize_metadata()

        self._new_metadata.length += tm.length
        artists.add(tm["artist"])
        if va:
            tm["compilation"] = "1"
        else:
            del tm["compilation"]
        if discpregap:
            tm["~discpregap"] = "1"

        # Run track metadata plugins
        try:
            run_track_metadata_processors(self, tm, self._release_node, track_node)
        except BaseException:
            self.error_append(traceback.format_exc())

        return track
Ejemplo n.º 13
0
 def test_track(self):
     t = Track("1")
     m = t.metadata
     track_to_metadata(self.json_doc, t)
     self.assertEqual(m, {})
Ejemplo n.º 14
0
 def test_track(self):
     t = Track("1")
     m = t.metadata
     track_to_metadata(self.json_doc, t)
     self.assertEqual(m, {})