Repository: moogar0880/PyTrakt

Issue:
Slugify bug?
There appears to be some differences in how your slugify function works in utils.py compared to the trakt slugs.  Are they supposed to match?  Without them matching the _get functions in movies.py and tv.py class inits are prone to error as these rely on the slug to pull the information.  Here's an example.

title:  Marvel's Agents of S.H.I.E.L.D.
pytrakt slug:  marvels-agents-of-shield
trakt slug:  marvel-s-agents-of-s-h-i-e-l-d

Also, I noticed that in movie.py your joining the year (if passed) to the slug but you don't have the same logic in tv.py.  Is there a reason to not include that?  TV Shows with the same title also use the year in the slug to differentiate the shows.

Discussion:

Patch:
diff --git a/.landscape.yaml b/.landscape.yaml
new file mode 100644
index 0000000..95d8d32
--- /dev/null
+++ b/.landscape.yaml
@@ -0,0 +1,2 @@
+doc-warnings: yes
+strictness: veryhigh
diff --git a/.travis.yml b/.travis.yml
index 0b1b7a0..18823c2 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -5,5 +5,4 @@ python:
   - 3.4
   - 3.5
 script:
-  - make travis
-after_success: coveralls
+  - make ci
diff --git a/HISTORY.rst b/HISTORY.rst
index 9ff86a6..0295563 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -1,5 +1,10 @@
 Release History
 ^^^^^^^^^^^^^^^
+2.4.4 (2016-03-19)
+++++++++++++++++++
+
+* Update `slugify` function to better match trakt slugs (#51)
+
 2.4.3 (2016-03-12)
 ++++++++++++++++++
 
diff --git a/Makefile b/Makefile
index 5ab43b9..8379202 100644
--- a/Makefile
+++ b/Makefile
@@ -14,11 +14,6 @@ coverage:
 
 ci: init style test
 
-coveralls:
-	pip install coveralls
-
-travis: coveralls ci
-
 publish:
 	python setup.py register
 	python setup.py sdist upload
diff --git a/README.rst b/README.rst
index 6b953ad..598a0ad 100644
--- a/README.rst
+++ b/README.rst
@@ -4,9 +4,9 @@ PyTrakt
     :target: https://travis-ci.org/moogar0880/PyTrakt
     :alt: Travis CI Status
 
-.. image:: https://coveralls.io/repos/moogar0880/PyTrakt/badge.svg
-    :target: https://coveralls.io/r/moogar0880/PyTrakt
-    :alt: Coverage
+.. image:: https://landscape.io/github/moogar0880/PyTrakt/master/landscape.svg?style=flat
+    :target: https://landscape.io/github/moogar0880/PyTrakt/master
+    :alt: Code Health
 
 .. image:: https://pypip.in/d/trakt/badge.svg?style=flat
     :target: https://pypi.python.org/pypi/trakt/
diff --git a/trakt/__init__.py b/trakt/__init__.py
index c53769b..4980572 100644
--- a/trakt/__init__.py
+++ b/trakt/__init__.py
@@ -5,6 +5,6 @@ try:
 except ImportError:
     pass
 
-version_info = (2, 4, 3)
+version_info = (2, 4, 4)
 __author__ = 'Jon Nappi'
 __version__ = '.'.join([str(i) for i in version_info])
diff --git a/trakt/utils.py b/trakt/utils.py
index d05b755..6b79fec 100644
--- a/trakt/utils.py
+++ b/trakt/utils.py
@@ -14,12 +14,11 @@ def slugify(value):
 
     Adapted from django.utils.text.slugify
     """
-    if sys.version_info[0] == 2:
-        value = unicode(value)  # NOQA
-    value = unicodedata.normalize('NFKD',
-                                  value).encode('ascii',
-                                                'ignore').decode('ascii')
-    value = re.sub('[^\w\s-]', '', value).strip().lower()
+    if sys.version_info[0] == 2 and isinstance(value, str):
+        value = unicode(value, 'utf-8')  # NOQA
+    nfkd_form = unicodedata.normalize('NFKD', value)
+    decoded = nfkd_form.encode('ascii', 'ignore').decode('utf-8')
+    value = re.sub('[^\w\s-]', ' ', decoded).strip().lower()
     return re.sub('[-\s]+', '-', value)
 
 


Test patch:
diff --git a/testing-requirements.txt b/testing-requirements.txt
index 35d8447..4c50c00 100644
--- a/testing-requirements.txt
+++ b/testing-requirements.txt
@@ -2,4 +2,3 @@
 flake8
 pytest
 pytest-cov
-coveralls
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 6b75c21..78b1af4 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -11,6 +11,8 @@ def test_slugify():
         ('IM AN ALL CAPS STRING', 'im-an-all-caps-string'),
         ('IM A BAD A$$ STRING!@', 'im-a-bad-a-string'),
         (' 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'),
     ]
 
     for inp, expected in test_data: