Пример #1
0
 def test_parens_have_lower_weight(self):
     dist1 = string_dist(u'One .Two.', u'One')
     dist2 = string_dist(u'One (Two)', u'One')
     self.assertTrue(dist2 < dist1)
Пример #2
0
 def test_ep_label_has_zero_weight(self):
     dist = string_dist(u'My Song (EP)', u'My Song')
     self.assertEqual(dist, 0.0)
Пример #3
0
 def test_different_strings(self):
     dist = string_dist(u'Some String', u'Totally Different')
     self.assertNotEqual(dist, 0.0)
Пример #4
0
 def test_case_ignored(self):
     dist = string_dist(u'Some String', u'sOME sTring')
     self.assertEqual(dist, 0.0)
Пример #5
0
 def compare_func(track_info):
     track_title = getattr(track_info, "title", None)
     dist = string_dist(track_title, title)
     return (track_title and dist < dist_threshold)
Пример #6
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])
Пример #7
0
 def test_punctuation_ignored(self):
     dist = string_dist(u'Some String', u'Some.String!')
     self.assertEqual(dist, 0.0)
Пример #8
0
 def test_solo_pattern(self):
     # Just make sure these don't crash.
     string_dist(u'The ', u'')
     string_dist(u'(EP)', u'(EP)')
     string_dist(u', An', u'')
Пример #9
0
 def test_equal_strings(self):
     dist = string_dist(u'Some String', u'Some String')
     self.assertEqual(dist, 0.0)
Пример #10
0
 def test_different_strings(self):
     dist = string_dist(u'Some String', u'Totally Different')
     self.assertNotEqual(dist, 0.0)
Пример #11
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])
Пример #12
0
 def test_accented_characters(self):
     dist = string_dist(u'\xe9\xe1\xf1', u'ean')
     self.assertEqual(dist, 0.0)
Пример #13
0
    def fetch_item_lyrics(self, item):
        """Fetch track lyrics from Metal Archives
        """
        lyrics = ''

        # Skip if lyrics are already present
        if item.lyrics:
            return

        # If this track was matched from metal archives, we can just use
        # the track id
        if _is_source_id(item.mb_albumid):
            self._log.debug(u'fetching lyrics: {0.artist} - {0.title}', item)

            track_id = _strip_prefix(item.mb_trackid)
            try:
                lyrics = metallum.lyrics_for_id(track_id)
            except metallum.NetworkError as e:
                self._log.debug('network error: {0}', e)
                return

        # Otherwise perform an album search
        elif self.config['lyrics_search'].get(bool):
            self._log.debug(u'searching for lyrics: {0.artist} - {0.title}',
                            item)

            try:
                results = metallum.album_search(item.album,
                                                band=item.artist,
                                                strict=False,
                                                year_from=item.year,
                                                year_to=item.year)
            except metallum.NetworkError as e:
                self._log.debug('network error: {0}', e)
                return

            for result in results:
                # TODO: use Distance object to calculate actual album distance
                # using all data fields (title, year, number of tracks, etc)
                album = result.get()
                if len(album.tracks) >= item.track:
                    track = album.tracks[item.track - 1]
                    dist = string_dist(item.title, unicode(track.title))
                    # TODO: make threshold config key
                    if dist > 0.1:
                        continue

                    try:
                        lyrics = track.lyrics
                    except metallum.NetworkError as e:
                        self._log.debug('network error: {0}', e)
                        return
        else:
            return

        if lyrics:
            message = ui.colorize('text_success', 'found lyrics')
            if lyrics == u'(<em>Instrumental</em>)':
                lyrics = self.config['instrumental'].get()
            item.lyrics = unicode(lyrics)
            if config['import']['write'].get(bool):
                item.try_write()
            item.store()
        else:
            message = ui.colorize('text_error', 'no lyrics found')

        self._log.info(u'{0.artist} - {0.album} - {0.title}: {1}', item,
                       message)
Пример #14
0
 def test_postfix_the(self):
     dist = string_dist(u'The Song Title', u'Song Title, The')
     self.assertEqual(dist, 0.0)
Пример #15
0
 def test_case_ignored(self):
     dist = string_dist(u'Some String', u'sOME sTring')
     self.assertEqual(dist, 0.0)
Пример #16
0
 def test_postfix_an(self):
     dist = string_dist(u'An Album Title', u'Album Title, An')
     self.assertEqual(dist, 0.0)
Пример #17
0
 def test_leading_the_has_lower_weight(self):
     dist1 = string_dist(u'XXX Band Name', u'Band Name')
     dist2 = string_dist(u'The Band Name', u'Band Name')
     self.assert_(dist2 < dist1)
Пример #18
0
 def test_ampersand_expansion(self):
     dist = string_dist(u'And', u'&')
     self.assertEqual(dist, 0.0)
Пример #19
0
 def test_parens_have_lower_weight(self):
     dist1 = string_dist(u'One .Two.', u'One')
     dist2 = string_dist(u'One (Two)', u'One')
     self.assert_(dist2 < dist1)
Пример #20
0
 def test_ampersand_expansion(self):
     dist = string_dist(u'And', u'&')
     self.assertEqual(dist, 0.0)
Пример #21
0
 def test_brackets_have_lower_weight(self):
     dist1 = string_dist(u'One .Two.', u'One')
     dist2 = string_dist(u'One [Two]', u'One')
     self.assert_(dist2 < dist1)
Пример #22
0
 def test_equal_strings(self):
     dist = string_dist(u'Some String', u'Some String')
     self.assertEqual(dist, 0.0)
Пример #23
0
 def test_ep_label_has_zero_weight(self):
     dist = string_dist(u'My Song (EP)', u'My Song')
     self.assertEqual(dist, 0.0)
Пример #24
0
 def test_punctuation_ignored(self):
     dist = string_dist(u'Some String', u'Some.String!')
     self.assertEqual(dist, 0.0)
Пример #25
0
 def test_featured_has_lower_weight(self):
     dist1 = string_dist(u'My Song blah Someone', u'My Song')
     dist2 = string_dist(u'My Song feat Someone', u'My Song')
     self.assert_(dist2 < dist1)
Пример #26
0
 def test_leading_the_has_lower_weight(self):
     dist1 = string_dist(u'XXX Band Name', u'Band Name')
     dist2 = string_dist(u'The Band Name', u'Band Name')
     self.assertTrue(dist2 < dist1)
Пример #27
0
 def test_postfix_the(self):
     dist = string_dist(u'The Song Title', u'Song Title, The')
     self.assertEqual(dist, 0.0)
Пример #28
0
 def test_brackets_have_lower_weight(self):
     dist1 = string_dist(u'One .Two.', u'One')
     dist2 = string_dist(u'One [Two]', u'One')
     self.assertTrue(dist2 < dist1)
Пример #29
0
 def test_postfix_a(self):
     dist = string_dist(u'A Song Title', u'Song Title, A')
     self.assertEqual(dist, 0.0)
Пример #30
0
 def test_featured_has_lower_weight(self):
     dist1 = string_dist(u'My Song blah Someone', u'My Song')
     dist2 = string_dist(u'My Song feat Someone', u'My Song')
     self.assertTrue(dist2 < dist1)
Пример #31
0
 def test_postfix_an(self):
     dist = string_dist(u'An Album Title', u'Album Title, An')
     self.assertEqual(dist, 0.0)
Пример #32
0
 def test_postfix_a(self):
     dist = string_dist(u'A Song Title', u'Song Title, A')
     self.assertEqual(dist, 0.0)
Пример #33
0
 def test_empty_strings(self):
     dist = string_dist(u'', u'')
     self.assertEqual(dist, 0.0)
Пример #34
0
 def test_empty_strings(self):
     dist = string_dist(u'', u'')
     self.assertEqual(dist, 0.0)
Пример #35
0
 def test_solo_pattern(self):
     # Just make sure these don't crash.
     string_dist(u'The ', u'')
     string_dist(u'(EP)', u'(EP)')
     string_dist(u', An', u'')
Пример #36
0
 def test_heuristic_does_not_harm_distance(self):
     dist = string_dist(u'Untitled', u'[Untitled]')
     self.assertEqual(dist, 0.0)
Пример #37
0
 def test_heuristic_does_not_harm_distance(self):
     dist = string_dist(u'Untitled', u'[Untitled]')
     self.assertEqual(dist, 0.0)
Пример #38
0
 def test_accented_characters(self):
     dist = string_dist(u'\xe9\xe1\xf1', u'ean')
     self.assertEqual(dist, 0.0)
Пример #39
0
    def fetch_item_lyrics(self, item):
        """Fetch track lyrics from Metal Archives
        """
        lyrics = ''

        # Skip if lyrics are already present
        if item.lyrics:
            return

        # If this track was matched from metal archives, we can just use
        # the track id
        if _is_source_id(item.mb_albumid):
            self._log.debug(u'fetching lyrics: {0.artist} - {0.title}', item)

            track_id = _strip_prefix(item.mb_trackid)
            try:
                lyrics = metallum.lyrics_for_id(track_id)
            except metallum.NetworkError as e:
                self._log.debug('network error: {0}', e)
                return

        # Otherwise perform an album search
        elif self.config['lyrics_search'].get(bool):
            self._log.debug(u'searching for lyrics: {0.artist} - {0.title}', item)

            try:
                results = metallum.album_search(item.album, band=item.artist, strict=False,
                                                year_from=item.year, year_to=item.year)
            except metallum.NetworkError as e:
                self._log.debug('network error: {0}', e)
                return

            for result in results:
                # TODO: use Distance object to calculate actual album distance
                # using all data fields (title, year, number of tracks, etc)
                album = result.get()
                if len(album.tracks) >= item.track:
                    track = album.tracks[item.track - 1]
                    dist = string_dist(item.title, track.title)
                    # TODO: make threshold config key
                    if dist > 0.1:
                        continue

                    try:
                        lyrics = track.lyrics
                    except metallum.NetworkError as e:
                        self._log.debug('network error: {0}', e)
                        return
        else:
            return

        if lyrics:
            lyrics = str(lyrics)
            message = ui.colorize('text_success', 'found lyrics')
            if lyrics == '(<em>Instrumental</em>)':
                lyrics = self.config['instrumental'].get()
            item.lyrics = lyrics
            if config['import']['write'].get(bool):
                item.try_write()
            item.store()
        else:
            message = ui.colorize('text_error', 'no lyrics found')

        self._log.info(u'{0.artist} - {0.album} - {0.title}: {1}', item, message)