subtitleseeker.py 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. # search-url
  17. url = 'http://www.subtitleseeker.com/'
  18. search_url = url+'search/TITLES/{query}&p={pageno}'
  19. # specific xpath variables
  20. results_xpath = '//div[@class="boxRows"]'
  21. # do search-request
  22. def request(query, params):
  23. params['url'] = search_url.format(query=quote_plus(query),
  24. pageno=params['pageno'])
  25. return params
  26. # get response from search-request
  27. def response(resp):
  28. results = []
  29. dom = html.fromstring(resp.text)
  30. # parse results
  31. for result in dom.xpath(results_xpath):
  32. link = result.xpath(".//a")[0]
  33. href = link.attrib.get('href')
  34. title = escape(link.xpath(".//text()")[0])
  35. content = result.xpath('.//div[contains(@class,"red")]//text()')[0]
  36. content = content + " - "
  37. content = content + html.tostring(result.xpath('.//div[contains(@class,"grey-web")]')[0], method='text')
  38. if result.xpath(".//span") != []:
  39. content = content + " - (" + result.xpath(".//span//text()")[0].strip() + ")"
  40. # append result
  41. results.append({'url': href,
  42. 'title': title,
  43. 'content': escape(content)})
  44. # return results
  45. return results