From baa8d8f616cf533f40e5485334b03ddbc3037052 Mon Sep 17 00:00:00 2001 From: Marcin Jenczmyk Date: Tue, 17 Mar 2020 17:28:10 +0100 Subject: [PATCH] =?UTF-8?q?Whitelist=20+,=20#,=20.,=20-=20and=20=E2=80=93?= =?UTF-8?q?=20special=20characters?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup.py | 2 +- src/downloader.py | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 5954809..18b3bea 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ 'click==7.0', 'google-api-python-client==1.6.3', 'requests==2.20.0', - 'python-slugify==1.2.6' + 'python-slugify==4.0.0' ] dev_requirements = [ diff --git a/src/downloader.py b/src/downloader.py index 58b3968..61e988c 100644 --- a/src/downloader.py +++ b/src/downloader.py @@ -1,4 +1,5 @@ import os +import re import sys import time @@ -23,7 +24,13 @@ class PacktConnectionError(ConnectionError): def slugify_product_name(title): """Return book title with spaces replaced by underscore and unicodes replaced by characters valid in filenames.""" - return slugify(title, separator='_', lowercase=False) + return slugify( + title, + separator='_', + lowercase=False, + regex_pattern=re.compile(r'[^-a-zA-Z0-9\+\#\.\-\–]+'), + replacements=[['–', '-']] + ) def wait_for_computation(predicate, timeout, retry_after):