Exemple #1
0
    def tag_album(self, items, **kwargs):
        artist = (items[0].artist or '') + ' tag'
        album = (items[0].album or '') + ' tag'
        mapping = {}
        dist = Distance()
        dist.tracks = {}
        for item in items:
            title = (item.title or '') + ' tag'
            track_info = TrackInfo(title=title,
                                   track_id=self.nextid(),
                                   index=1)
            mapping[item] = track_info
            dist.tracks[track_info] = Distance()

        album_info = AlbumInfo(album='album',
                               album_id=self.nextid(),
                               artist='artist',
                               artist_id=self.nextid(),
                               tracks=mapping.values())
        match = AlbumMatch(distance=dist,
                           info=album_info,
                           mapping=mapping,
                           extra_items=[],
                           extra_tracks=[])
        return artist, album, Proposal([match], Recommendation.strong)
Exemple #2
0
 def album_distance(self, items, album_info, mapping):
     """Returns the album distance.
     """
     dist = Distance()
     if album_info.data_source == 'VGMdb':
         dist.add('source', self.source_weight)
     return dist
Exemple #3
0
def album_distance(items, album_info, mapping):
    """Returns the album distance calculated by plugins."""
    from beets.autotag.hooks import Distance
    dist = Distance()
    for plugin in find_plugins():
        dist.update(plugin.album_distance(items, album_info, mapping))
    return dist
Exemple #4
0
 def album_distance(self, items, album_info, mapping):
     """Returns the album distance.
     """
     dist = Distance()
     if album_info.data_source == 'Amazon':
         dist.add('source', self.config['source_weight'].as_number())
     return dist
Exemple #5
0
def album_distance(items, album_info, mapping):
    """Returns the album distance calculated by plugins."""
    from beets.autotag.hooks import Distance
    dist = Distance()
    for plugin in find_plugins():
        dist.update(plugin.album_distance(items, album_info, mapping))
    return dist
Exemple #6
0
 def album_distance(self, items, album_info, mapping):
     """Returns the album distance.
     """
     dist = Distance()
     if hasattr(album_info, 'data_source') and album_info.data_source == 'bandcamp':
         dist.add('source', self.config['source_weight'].as_number())
     return dist
Exemple #7
0
 def test_max_distance(self):
     config['match']['distance_weights']['album'] = 3.0
     config['match']['distance_weights']['medium'] = 1.0
     dist = Distance()
     dist.add('album', 0.5)
     dist.add('medium', 0.0)
     dist.add('medium', 0.0)
     self.assertEqual(dist.max_distance, 5.0)
Exemple #8
0
 def album_distance(self, items, album_info, mapping):
     """Returns the beatport source weight and the maximum source weight
     for albums.
     """
     dist = Distance()
     if album_info.data_source == 'Beatport':
         dist.add('source', self.config['source_weight'].as_number())
     return dist
Exemple #9
0
 def track_distance(self, item, track_info):
     """Returns the beatport source weight and the maximum source weight
     for individual tracks.
     """
     dist = Distance()
     if track_info.data_source == 'Beatport':
         dist.add('source', self.config['source_weight'].as_number())
     return dist
Exemple #10
0
 def track_distance(self, item, track_info):
     """Returns the beatport source weight and the maximum source weight
     for individual tracks.
     """
     dist = Distance()
     if track_info.data_source == 'Beatport':
         dist.add('source', self.config['source_weight'].as_number())
     return dist
Exemple #11
0
 def album_distance(self, items, album_info, mapping):
     """Returns the beatport source weight and the maximum source weight
     for albums.
     """
     dist = Distance()
     if album_info.data_source == 'Beatport':
         dist.add('source', self.config['source_weight'].as_number())
     return dist
Exemple #12
0
def track_distance(item, info):
    """Gets the track distance calculated by all loaded plugins.
    Returns a Distance object.
    """
    from beets.autotag.hooks import Distance
    dist = Distance()
    for plugin in find_plugins():
        dist.update(plugin.track_distance(item, info))
    return dist
Exemple #13
0
def track_distance(item, info):
    """Gets the track distance calculated by all loaded plugins.
    Returns a Distance object.
    """
    from beets.autotag.hooks import Distance
    dist = Distance()
    for plugin in find_plugins():
        dist.update(plugin.track_distance(item, info))
    return dist
Exemple #14
0
    def test_distance(self):
        config['match']['distance_weights']['album'] = 2.0
        config['match']['distance_weights']['medium'] = 1.0
        dist = Distance()
        dist.add('album', 0.5)
        dist.add('media', 0.25)
        dist.add('media', 0.75)
        self.assertEqual(dist.distance, 0.5)

        # __getitem__()
        self.assertEqual(dist['album'], 0.25)
        self.assertEqual(dist['media'], 0.25)
Exemple #15
0
    def test_add_ratio(self):
        dist = Distance()
        dist.add_ratio('ratio', 25, 100)
        self.assertEqual(dist._penalties['ratio'], [0.25])

        dist.add_ratio('ratio', 10, 5)
        self.assertEqual(dist._penalties['ratio'], [0.25, 1.0])

        dist.add_ratio('ratio', -5, 5)
        self.assertEqual(dist._penalties['ratio'], [0.25, 1.0, 0.0])

        dist.add_ratio('ratio', 5, 0)
        self.assertEqual(dist._penalties['ratio'], [0.25, 1.0, 0.0, 0.0])
Exemple #16
0
    def test_items(self):
        config['match']['distance_weights']['album'] = 4.0
        config['match']['distance_weights']['medium'] = 2.0
        dist = Distance()
        dist.add('album', 0.1875)
        dist.add('medium', 0.75)
        self.assertEqual(dist.items(), [('medium', 0.25), ('album', 0.125)])

        # Sort by key if distance is equal.
        dist = Distance()
        dist.add('album', 0.375)
        dist.add('medium', 0.75)
        self.assertEqual(dist.items(), [('album', 0.25), ('medium', 0.25)])
Exemple #17
0
 def test_raw_distance(self):
     config['match']['distance_weights']['album'] = 3.0
     config['match']['distance_weights']['medium'] = 1.0
     dist = Distance()
     dist.add('album', 0.5)
     dist.add('medium', 0.25)
     dist.add('medium', 0.5)
     self.assertEqual(dist.raw_distance, 2.25)
Exemple #18
0
    def test_add_priority(self):
        dist = Distance()
        dist.add_priority('priority', 'abc', 'abc')
        self.assertEqual(dist._penalties['priority'], [0.0])

        dist.add_priority('priority', 'def', ['abc', 'def'])
        self.assertEqual(dist._penalties['priority'], [0.0, 0.5])

        dist.add_priority('priority', 'gh', ['ab', 'cd', 'ef',
                                             re.compile('GH', re.I)])
        self.assertEqual(dist._penalties['priority'], [0.0, 0.5, 0.75])

        dist.add_priority('priority', 'xyz', ['abc', 'def'])
        self.assertEqual(dist._penalties['priority'], [0.0, 0.5, 0.75,
                                                       1.0])
Exemple #19
0
    def test_add_number(self):
        dist = Distance()
        # Add a full penalty for each number of difference between two numbers.

        dist.add_number('number', 1, 1)
        self.assertEqual(dist._penalties['number'], [0.0])

        dist.add_number('number', 1, 2)
        self.assertEqual(dist._penalties['number'], [0.0, 1.0])

        dist.add_number('number', 2, 1)
        self.assertEqual(dist._penalties['number'], [0.0, 1.0, 1.0])

        dist.add_number('number', -1, 2)
        self.assertEqual(dist._penalties['number'], [0.0, 1.0, 1.0, 1.0,
                                                     1.0, 1.0])
Exemple #20
0
    def test_add_equality(self):
        dist = Distance()
        dist.add_equality('equality', 'ghi', ['abc', 'def', 'ghi'])
        self.assertEqual(dist._penalties['equality'], [0.0])

        dist.add_equality('equality', 'xyz', ['abc', 'def', 'ghi'])
        self.assertEqual(dist._penalties['equality'], [0.0, 1.0])

        dist.add_equality('equality', 'abc', re.compile(r'ABC', re.I))
        self.assertEqual(dist._penalties['equality'], [0.0, 1.0, 0.0])
Exemple #21
0
    def tag_album(self, items, **kwargs):
        artist = (items[0].artist or '') + ' tag'
        album  = (items[0].album or '') + ' tag'
        mapping = {}
        dist = Distance()
        dist.tracks = {}
        for item in items:
            title = (item.title or '') + ' tag'
            track_info = TrackInfo(title=title, track_id=self.nextid())
            mapping[item] = track_info
            dist.tracks[track_info] = Distance()

        album_info = AlbumInfo(album='album', album_id=self.nextid(),
                               artist='artist', artist_id=self.nextid(),
                               tracks=mapping.values())
        match = AlbumMatch(distance=dist, info=album_info, mapping=mapping,
                           extra_items=[], extra_tracks=[])
        return artist, album, [match], Recommendation.strong
Exemple #22
0
 def test_raw_distance(self):
     config['match']['distance_weights']['album'] = 3.0
     config['match']['distance_weights']['medium'] = 1.0
     dist = Distance()
     dist.add('album', 0.5)
     dist.add('medium', 0.25)
     dist.add('medium', 0.5)
     self.assertEqual(dist.raw_distance, 2.25)
Exemple #23
0
    def test_add_expr(self):
        dist = Distance()
        dist.add_expr('expr', True)
        self.assertEqual(dist._penalties['expr'], [1.0])

        dist.add_expr('expr', False)
        self.assertEqual(dist._penalties['expr'], [1.0, 0.0])
Exemple #24
0
 def test_max_distance(self):
     config['match']['distance_weights']['album'] = 3.0
     config['match']['distance_weights']['medium'] = 1.0
     dist = Distance()
     dist.add('album', 0.5)
     dist.add('medium', 0.0)
     dist.add('medium', 0.0)
     self.assertEqual(dist.max_distance, 5.0)
Exemple #25
0
 def test_operators(self):
     config['match']['distance_weights']['source'] = 1.0
     config['match']['distance_weights']['album'] = 2.0
     config['match']['distance_weights']['medium'] = 1.0
     dist = Distance()
     dist.add('source', 0.0)
     dist.add('album', 0.5)
     dist.add('medium', 0.25)
     dist.add('medium', 0.75)
     self.assertEqual(len(dist), 2)
     self.assertEqual(list(dist), [('album', 0.2), ('medium', 0.2)])
     self.assertTrue(dist == 0.4)
     self.assertTrue(dist < 1.0)
     self.assertTrue(dist > 0.0)
     self.assertEqual(dist - 0.4, 0.0)
     self.assertEqual(0.4 - dist, 0.0)
     self.assertEqual(float(dist), 0.4)
Exemple #26
0
    def test_distance(self):
        config['match']['distance_weights']['album'] = 2.0
        config['match']['distance_weights']['medium'] = 1.0
        dist = Distance()
        dist.add('album', 0.5)
        dist.add('media', 0.25)
        dist.add('media', 0.75)
        self.assertEqual(dist.distance, 0.5)

        # __getitem__()
        self.assertEqual(dist['album'], 0.25)
        self.assertEqual(dist['media'], 0.25)
Exemple #27
0
 def test_operators(self):
     config['match']['distance_weights']['source'] = 1.0
     config['match']['distance_weights']['album'] = 2.0
     config['match']['distance_weights']['medium'] = 1.0
     dist = Distance()
     dist.add('source', 0.0)
     dist.add('album', 0.5)
     dist.add('medium', 0.25)
     dist.add('medium', 0.75)
     self.assertEqual(len(dist), 2)
     self.assertEqual(list(dist), [('album', 0.2), ('medium', 0.2)])
     self.assertTrue(dist == 0.4)
     self.assertTrue(dist < 1.0)
     self.assertTrue(dist > 0.0)
     self.assertEqual(dist - 0.4, 0.0)
     self.assertEqual(0.4 - dist, 0.0)
     self.assertEqual(float(dist), 0.4)
Exemple #28
0
    def test_update(self):
        dist1 = Distance()
        dist1.add('album', 0.5)
        dist1.add('media', 1.0)

        dist2 = Distance()
        dist2.add('album', 0.75)
        dist2.add('album', 0.25)
        dist2.add('media', 0.05)

        dist1.update(dist2)

        self.assertEqual(dist1._penalties, {'album': [0.5, 0.75, 0.25],
                                            'media': [1.0, 0.05]})
Exemple #29
0
    def test_items(self):
        config['match']['distance_weights']['album'] = 4.0
        config['match']['distance_weights']['medium'] = 2.0
        _clear_weights()

        dist = Distance()
        dist.add('album', 0.1875)
        dist.add('medium', 0.75)
        self.assertEqual(dist.items(), [('medium', 0.25), ('album', 0.125)])

        # Sort by key if distance is equal.
        dist = Distance()
        dist.add('album', 0.375)
        dist.add('medium', 0.75)
        self.assertEqual(dist.items(), [('album', 0.25), ('medium', 0.25)])
Exemple #30
0
 def test_add_string_both_none(self):
     dist = Distance()
     dist.add_string('string', None, None)
     self.assertEqual(dist._penalties['string'], [0])
Exemple #31
0
 def test_add_string(self):
     dist = Distance()
     sdist = string_dist(u'abc', u'bcd')
     dist.add_string('string', u'abc', u'bcd')
     self.assertEqual(dist._penalties['string'], [sdist])
     self.assertNotEqual(dist._penalties['string'], [0])
Exemple #32
0
 def tag_item(self, item, **kwargs):
     title = (item.title or '') + ' tag'
     track_info = TrackInfo(title=title, track_id=self.nextid())
     match = TrackMatch(distance=Distance(), info=track_info)
     return [match], Recommendation.strong
Exemple #33
0
 def test_add(self):
     dist = Distance()
     dist.add('add', 1.0)
     self.assertEqual(dist._penalties, {'add': [1.0]})