Skip to content

Commit

Permalink
removing quotes surrounding {title} if title has special characters
Browse files Browse the repository at this point in the history
  • Loading branch information
elgatito committed Dec 13, 2017
1 parent dec5dbd commit 146c869
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
14 changes: 11 additions & 3 deletions burst/burst.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
available_providers = 0
request_time = time.time()
timeout = get_setting("timeout", int)
special_chars = "()\"':.[]<>/\\?"


def search(payload, method="general"):
Expand All @@ -42,9 +43,16 @@ def search(payload, method="general"):

if method == 'general':
payload = {
'title': payload
'title': payload,
'titles': {
'Original': payload
}
}

payload['has_special'] = 'Original' in payload['titles'] and any(c in payload['titles']['Original'] for c in special_chars)
if payload['has_special']:
log.debug("Query title contains special chars, so removing any quotes in the search query")

global request_time
global provider_names
global provider_results
Expand Down Expand Up @@ -447,8 +455,8 @@ def run_provider(provider, payload, method):
filterInstance.use_general(provider, payload)

if 'is_api' in definitions[provider]:
results = process(provider=provider, generator=extract_from_api, filtering=filterInstance)
results = process(provider=provider, generator=extract_from_api, filtering=filterInstance, has_special=payload['has_special'])
else:
results = process(provider=provider, generator=extract_torrents, filtering=filterInstance)
results = process(provider=provider, generator=extract_torrents, filtering=filterInstance, has_special=payload['has_special'])

got_results(provider, results)
3 changes: 1 addition & 2 deletions burst/filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,7 @@ def process_keywords(self, provider, text):
title = self.normalize_name(title)
log.info("[%s] Using translated '%s' title %s" % (provider, use_language,
repr(title)))
log.debug("[%s] Translated titles from Elementum: %s" % (provider,
repr(self.info['titles'])))
log.debug("[%s] Translated titles from Elementum: %s" % (provider, repr(self.info['titles'])))
except Exception as e:
import traceback
log.error("%s failed with: %s" % (provider, repr(e)))
Expand Down
7 changes: 6 additions & 1 deletion burst/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ def generate_payload(provider, generator, filtering, verify_name=True, verify_si
return results


def process(provider, generator, filtering, verify_name=True, verify_size=True):
def process(provider, generator, filtering, has_special, verify_name=True, verify_size=True):
""" Method for processing provider results using its generator and Filtering class instance
Args:
provider (str): Provider ID
generator (function): Generator method, can be either ``extract_torrents`` or ``extract_from_api``
filtering (Filtering): Filtering class instance
has_special (bool): Whether title contains special chars
verify_name (bool): Whether to double-check the results' names match the query or not
verify_size (bool): Whether to check the results' file sizes
"""
Expand Down Expand Up @@ -93,6 +94,10 @@ def process(provider, generator, filtering, verify_name=True, verify_size=True):

for query, extra in zip(filtering.queries, filtering.extras):
log.debug("[%s] Before keywords - Query: %s - Extra: %s" % (provider, repr(query), repr(extra)))
if has_special:
# Removing quotes, surrounding {title*} keywords, when title contains special chars
query = re.sub("[\"']({title.*?})[\"']", '\\1', query)

query = filtering.process_keywords(provider, query)
extra = filtering.process_keywords(provider, extra)
log.debug("[%s] After keywords - Query: %s - Extra: %s" % (provider, repr(query), repr(extra)))
Expand Down

0 comments on commit 146c869

Please sign in to comment.