From 19b599daf5c320fe4813a986dc74a62287bd9af7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Mon, 17 Jan 2022 11:29:22 +0200 Subject: [PATCH 1/2] Refactor slugify to handle special cases --- trakt/utils.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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): From 9a391e372c258ae0c5d30e1dec7608c3acb28582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Mon, 17 Jan 2022 11:29:33 +0200 Subject: [PATCH 2/2] Add two slugify special cases to test --- tests/test_utils.py | 2 ++ 1 file changed, 2 insertions(+) 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: