Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 10 additions & 4 deletions trakt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down