subtitleseeker.py 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. ## Subtitleseeker (Video)
  2. #
  3. # @website http://www.subtitleseeker.com
  4. # @provide-api no
  5. #
  6. # @using-api no
  7. # @results HTML
  8. # @stable no (HTML can change)
  9. # @parse url, title, content
  10. from cgi import escape
  11. from urllib import quote_plus
  12. from lxml import html
  13. # engine dependent config
  14. categories = ['videos']
  15. paging = True
  16. language = ""
  17. # search-url
  18. url = 'http://www.subtitleseeker.com/'
  19. search_url = url+'search/TITLES/{query}&p={pageno}'
  20. # specific xpath variables
  21. results_xpath = '//div[@class="boxRows"]'
  22. # do search-request
  23. def request(query, params):
  24. params['url'] = search_url.format(query=quote_plus(query),
  25. pageno=params['pageno'])
  26. return params
  27. # get response from search-request
  28. def response(resp):
  29. results = []
  30. dom = html.fromstring(resp.text)
  31. # parse results
  32. for result in dom.xpath(results_xpath):
  33. link = result.xpath(".//a")[0]
  34. href = link.attrib.get('href')
  35. if language is not "":
  36. href = href + language + "/"
  37. title = escape(link.xpath(".//text()")[0])
  38. content = result.xpath('.//div[contains(@class,"red")]//text()')[0]
  39. content = content + " - "
  40. content = content + html.tostring(result.xpath('.//div[contains(@class,"grey-web")]')[0], method='text')
  41. if result.xpath(".//span") != []:
  42. content = content + " - (" + result.xpath(".//span//text()")[0].strip() + ")"
  43. # append result
  44. results.append({'url': href,
  45. 'title': title,
  46. 'content': escape(content)})
  47. # return results
  48. return results