diff --git a/tests/test_utils.py b/tests/test_utils.py index 9b6b5555..9c2526a0 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -12,6 +12,8 @@ def test_slugify(): (' LOOK AT MY WHITESPACE ', 'look-at-my-whitespace'), ("Marvel's Agents of S.H.I.E.L.D.", 'marvel-s-agents-of-s-h-i-e-l-d'), ('Naruto Shippūden', 'naruto-shippuden'), + ('Re:ZERO -Starting Life in Another World-', 're-zero-starting-life-in-another-world'), + ('So I’m a Spider, So What?', 'so-i-m-a-spider-so-what'), ] for inp, expected in test_data: diff --git a/trakt/utils.py b/trakt/utils.py index fbf54dc5..f9785b4e 100644 --- a/trakt/utils.py +++ b/trakt/utils.py @@ -14,10 +14,16 @@ def slugify(value): Adapted from django.utils.text.slugify """ - nfkd_form = unicodedata.normalize('NFKD', value) - decoded = nfkd_form.encode('ascii', 'ignore').decode('utf-8') - value = re.sub(r'[^\w\s-]', ' ', decoded).strip().lower() - return re.sub(r'[-\s]+', '-', value) + value = unicodedata.normalize('NFKD', value) + # special case, "ascii" encode would just remove it + value = value.replace("’", '-') + value = value.encode('ascii', 'ignore').decode('utf-8') + value = value.lower() + value = re.sub(r'[^\w\s-]', ' ', value) + value = re.sub(r'[-\s]+', '-', value) + value = value.strip('-') + + return value def airs_date(airs_at):