<commit_before>## Subtitleseeker (Video)
#
# @website     http://www.subtitleseeker.com
# @provide-api no
#
# @using-api   no
# @results     HTML
# @stable      no (HTML can change)
# @parse       url, title, content

from cgi import escape
from urllib import quote_plus
from lxml import html

# engine dependent config
categories = ['videos']
paging = True
language = ""

# search-url
url = 'http://www.subtitleseeker.com/'
search_url = url+'search/TITLES/{query}&p={pageno}'

# specific xpath variables
results_xpath = '//div[@class="boxRows"]'


# do search-request
def request(query, params):
    params['url'] = search_url.format(query=quote_plus(query),
                                      pageno=params['pageno'])
    return params


# get response from search-request
def response(resp):
    results = []

    dom = html.fromstring(resp.text)

    # parse results
    for result in dom.xpath(results_xpath):
        link = result.xpath(".//a")[0]
        href = link.attrib.get('href')

        if language is not "":
            href = href + language + "/"

        title = escape(link.xpath(".//text()")[0])

        content = result.xpath('.//div[contains(@class,"red")]//text()')[0]
        content = content + " - "
        content = content + html.tostring(result.xpath('.//div[contains(@class,"grey-web")]')[0], method='text')

        if result.xpath(".//span") != []:
            content = content + " - (" + result.xpath(".//span//text()")[0].strip() + ")"

        # append result
        results.append({'url': href,
                        'title': title,
                        'content': escape(content)})

    # return results
    return results
<commit_msg>[enh] subtitleseeker: better language handling<commit_after>## Subtitleseeker (Video)
#
# @website     http://www.subtitleseeker.com
# @provide-api no
#
# @using-api   no
# @results     HTML
# @stable      no (HTML can change)
# @parse       url, title, content

from cgi import escape
from urllib import quote_plus
from lxml import html
from searx.languages import language_codes

# engine dependent config
categories = ['videos']
paging = True
language = ""

# search-url
url = 'http://www.subtitleseeker.com/'
search_url = url+'search/TITLES/{query}&p={pageno}'

# specific xpath variables
results_xpath = '//div[@class="boxRows"]'


# do search-request
def request(query, params):
    params['url'] = search_url.format(query=quote_plus(query),
                                      pageno=params['pageno'])
    return params


# get response from search-request
def response(resp):
    results = []

    dom = html.fromstring(resp.text)

    search_lang = ""

    if resp.search_params['language'] != 'all':
        search_lang = [lc[1]
                       for lc in language_codes
                       if lc[0][:2] == resp.search_params['language']][0]

    # parse results
    for result in dom.xpath(results_xpath):
        link = result.xpath(".//a")[0]
        href = link.attrib.get('href')

        if language is not "":
            href = href + language + '/'
        elif search_lang:
            href = href + search_lang + '/'

        title = escape(link.xpath(".//text()")[0])

        content = result.xpath('.//div[contains(@class,"red")]//text()')[0]
        content = content + " - "
        content = content + html.tostring(result.xpath('.//div[contains(@class,"grey-web")]')[0], method='text')

        if result.xpath(".//span") != []:
            content = content + " - (" + result.xpath(".//span//text()")[0].strip() + ")"

        # append result
        results.append({'url': href,
                        'title': title,
                        'content': escape(content)})

    # return results
    return results

{'fraction_non_alphanumeric': 0.15962566844919787, 'fraction_numerical': 0.0037433155080213902, 'mean_word_length': 2.4258241758241756, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6864655', 'n_tokens_mistral': 1182, 'n_tokens_neox': 1135, 'n_words': 252}