From 11dfd66efdac36ee8db46d7bf104abffd7d45ff6 Mon Sep 17 00:00:00 2001 From: Prinz23 Date: Wed, 24 Jan 2018 10:30:32 +0000 Subject: [PATCH] Fix ensure url unicode shownames are correctly 'UTF-8' and urlencoded. Refactor shownames list into generic provider method, reusable in multiple providers. Add remove English at the end of release names (drunkenslug). --- sickbeard/providers/generic.py | 9 ++++++++- sickbeard/providers/newznab.py | 18 ++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/sickbeard/providers/generic.py b/sickbeard/providers/generic.py index 1658eb3a..a472a81e 100644 --- a/sickbeard/providers/generic.py +++ b/sickbeard/providers/generic.py @@ -27,6 +27,7 @@ import re import time import urlparse import threading +import urllib from urllib import quote_plus import zlib from base64 import b16encode, b32decode @@ -39,7 +40,7 @@ from hachoir_parser import guessParser from hachoir_core.error import HachoirError from hachoir_core.stream import FileInputStream -from sickbeard import helpers, classes, logger, db, tvcache, encodingKludge as ek +from sickbeard import helpers, classes, logger, db, tvcache, scene_exceptions, encodingKludge as ek from sickbeard.common import Quality, MULTI_EP_RESULT, SEASON_RESULT, USER_AGENT from sickbeard.exceptions import SickBeardException, AuthException, ex from sickbeard.helpers import maybe_plural, remove_file_failed @@ -165,6 +166,12 @@ class GenericProvider: return helpers.getURL(url, post_data=post_data, params=params, headers=self.headers, timeout=timeout, session=self.session, json=json, hooks=dict(response=self.cb_response)) + @staticmethod + def get_show_names_url_encoded(ep_obj, spacer='.'): + return [urllib.quote_plus(n.replace('.', spacer).encode('utf-8', errors='replace')) for n in list( + set([helpers.sanitizeSceneName(a) for a in + scene_exceptions.get_scene_exceptions(ep_obj.show.indexerid) + [ep_obj.show.name]]))] + def download_result(self, result): """ Save the result to disk. diff --git a/sickbeard/providers/newznab.py b/sickbeard/providers/newznab.py index c6fd1a60..656da53c 100755 --- a/sickbeard/providers/newznab.py +++ b/sickbeard/providers/newznab.py @@ -27,7 +27,7 @@ from math import ceil from sickbeard.sbdatetime import sbdatetime from . import generic -from sickbeard import helpers, logger, scene_exceptions, tvcache, classes, db +from sickbeard import helpers, logger, tvcache, classes, db from sickbeard.common import neededQualities, Quality from sickbeard.exceptions import AuthException, MultipleShowObjectsException from sickbeard.indexers.indexer_config import * @@ -351,15 +351,12 @@ class NewznabProvider(generic.NZBProvider): use_id = True use_id and search_params.append(params) + spacer = 'nzbgeek.info' in self.url.lower() and ' ' or '.' # query search and exceptions - name_exceptions = list( - set([helpers.sanitizeSceneName(a) for a in - scene_exceptions.get_scene_exceptions(ep_obj.show.indexerid) + [ep_obj.show.name]])) + name_exceptions = self.get_show_names_url_encoded(ep_obj, spacer) - spacer = 'geek' in self.get_id() and ' ' or '.' for cur_exception in name_exceptions: params = base_params.copy() - cur_exception = cur_exception.replace('.', spacer) if 'q' in params: params['q'] = '%s%s%s' % (cur_exception, spacer, params['q']) search_params.append(params) @@ -408,17 +405,14 @@ class NewznabProvider(generic.NZBProvider): use_id = True use_id and search_params.append(params) + spacer = 'nzbgeek.info' in self.url.lower() and ' ' or '.' # query search and exceptions - name_exceptions = list( - set([helpers.sanitizeSceneName(a) for a in - scene_exceptions.get_scene_exceptions(ep_obj.show.indexerid) + [ep_obj.show.name]])) + name_exceptions = self.get_show_names_url_encoded(ep_obj, spacer) - spacer = 'geek' in self.get_id() and ' ' or '.' if sickbeard.scene_exceptions.has_abs_episodes(ep_obj): search_params.append({'q': '%s%s%s' % (ep_obj.show.name, spacer, base_params['ep'])}) for cur_exception in name_exceptions: params = base_params.copy() - cur_exception = cur_exception.replace('.', spacer) params['q'] = cur_exception search_params.append(params) @@ -444,7 +438,7 @@ class NewznabProvider(generic.NZBProvider): r_found = True while r_found: r_found = False - for pattern, repl in ((r'(?i)-Obfuscated$', ''), (r'(?i)-postbot$', '')): + for pattern, repl in ((r'(?i)-Obfuscated$', ''), (r'(?i)-postbot$', ''), (r'(?i)[-.]English$', '')): if re.search(pattern, title): r_found = True title = re.sub(pattern, repl, title)