Ejemplo n.º 1
0
    def _split(text):  # TODO: make this logic common
        """Split an album title into parts.

        @param text: string to split into parts
        @return: name, kind, featuring
        """
        kind = featuring = None
        # Strip featured artists
        match = re.search(RE_FEATURING, text, re.IGNORECASE | re.VERBOSE)
        if match:
            featuring = match.group(1)
            logging.debug("match found: {0}".format(featuring))
            text = text.replace(
                match.group(0),
                '').strip()  # remove the match from the remaining text
        # Strip song kinds
        for kind in settings.KINDS:
            re_kind = RE_KIND.replace('<kind>', kind)
            match = re.search(re_kind, text, re.IGNORECASE | re.VERBOSE)
            if match:
                logging.debug("match found: {0}".format(kind))
                text = text.replace(
                    match.group(0),
                    '').strip()  # remove the match from the remaining text
                break
        else:
            kind = None
        # Return parts
        return TextTitle.fromstring(text), TextEnum.fromstring(
            kind), TextList.fromstring(featuring)
Ejemplo n.º 2
0
 def test_ep(self):
     """Verify an EP can be parsed."""
     album = Album("Tracks (feat. The Artist) [EP]")
     self.assertEqual(TextTitle("Tracks"), album.name)
     self.assertEqual(TextEnum("EP"), album.kind)
     self.assertEqual(TextList("The Artist"), album.featuring)
     self.assertEqual("Tracks [EP]", str(album))
Ejemplo n.º 3
0
    def _split(text):  # TODO: make this logic common
        """Split an album title into parts.

        @param text: string to split into parts
        @return: name, kind, featuring
        """
        kind = featuring = None
        # Strip featured artists
        match = re.search(RE_FEATURING, text, re.IGNORECASE | re.VERBOSE)
        if match:
            featuring = match.group(1)
            logging.debug("match found: {0}".format(featuring))
            text = text.replace(match.group(0), '').strip()  # remove the match from the remaining text
        # Strip song kinds
        for kind in settings.KINDS:
            re_kind = RE_KIND.replace('<kind>', kind)
            match = re.search(re_kind, text, re.IGNORECASE | re.VERBOSE)
            if match:
                logging.debug("match found: {0}".format(kind))
                text = text.replace(match.group(0), '').strip()  # remove the match from the remaining text
                break
        else:
            kind = None
        # Return parts
        return TextTitle.fromstring(text), TextEnum.fromstring(kind), TextList.fromstring(featuring)
Ejemplo n.º 4
0
 def test_nominal(self):
     """Verify a normal album name can be parsed."""
     album = Album("Album Name")
     self.assertEqual(TextTitle("Album Name"), album.name)
     self.assertEqual(None, album.year)
     self.assertEqual(None, album.kind)
     self.assertEqual(None, album.featuring)
     self.assertEqual("Album Name", str(album))
Ejemplo n.º 5
0
 def test_threshold(self):
     """Verify the TextTitle threshold is correct."""
     self.assertTrue(
         TextTitle("The Cat and the Hat") % TextTitle("cat an' the hat"))
     self.assertFalse(
         TextTitle("The Cat and the Hat") % TextTitle("cat and hat"))
Ejemplo n.º 6
0
 def test_close(self):
     """Verify two similar text titles can be compared."""
     a = TextTitle("The Cat and the Hat")
     b = TextTitle("The Cat & The Hat")
     self.assertComparison(a, b, False, True, 1.00)
Ejemplo n.º 7
0
 def test_different(self):
     """Verify two different text titles can be compared."""
     a = TextTitle("The Cat and the Hat")
     b = TextTitle("A Clockwork Orange")
     self.assertComparison(a, b, False, False, 0.32)
Ejemplo n.º 8
0
 def test_identical(self):
     """Verify two identical text titles can be compared."""
     a = TextTitle("The Cat and the Hat")
     b = TextTitle("The Cat and the Hat")
     self.assertComparison(a, b, True, True, 1.00)