PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/couchpotato/core/media/_base/providers/nzb/nzbclub.py

https://gitlab.com/132nd-etcher/CouchPotatoServer
Python | 100 lines | 84 code | 16 blank | 0 comment | 6 complexity | b0365f643ebf45801cd32264a69a7d64 MD5 | raw file
  1. import time
  2. from bs4 import BeautifulSoup
  3. from couchpotato.core.helpers.encoding import toUnicode
  4. from couchpotato.core.helpers.rss import RSS
  5. from couchpotato.core.helpers.variable import tryInt
  6. from couchpotato.core.logger import CPLog
  7. from couchpotato.core.media._base.providers.nzb.base import NZBProvider
  8. from dateutil.parser import parse
  9. log = CPLog(__name__)
  10. class Base(NZBProvider, RSS):
  11. urls = {
  12. 'search': 'https://www.nzbclub.com/nzbfeeds.aspx?%s',
  13. }
  14. http_time_between_calls = 4 # seconds
  15. def _search(self, media, quality, results):
  16. nzbs = self.getRSSData(self.urls['search'] % self.buildUrl(media))
  17. for nzb in nzbs:
  18. nzbclub_id = tryInt(self.getTextElement(nzb, "link").split('/nzb_view/')[1].split('/')[0])
  19. enclosure = self.getElement(nzb, "enclosure").attrib
  20. size = enclosure['length']
  21. date = self.getTextElement(nzb, "pubDate")
  22. def extra_check(item):
  23. full_description = self.getCache('nzbclub.%s' % nzbclub_id, item['detail_url'], cache_timeout = 25920000)
  24. for ignored in ['ARCHIVE inside ARCHIVE', 'Incomplete', 'repair impossible']:
  25. if ignored in full_description:
  26. log.info('Wrong: Seems to be passworded or corrupted files: %s', item['name'])
  27. return False
  28. return True
  29. results.append({
  30. 'id': nzbclub_id,
  31. 'name': toUnicode(self.getTextElement(nzb, "title")),
  32. 'age': self.calculateAge(int(time.mktime(parse(date).timetuple()))),
  33. 'size': tryInt(size) / 1024 / 1024,
  34. 'url': enclosure['url'].replace(' ', '_'),
  35. 'detail_url': self.getTextElement(nzb, "link"),
  36. 'get_more_info': self.getMoreInfo,
  37. 'extra_check': extra_check
  38. })
  39. def getMoreInfo(self, item):
  40. full_description = self.getCache('nzbclub.%s' % item['id'], item['detail_url'], cache_timeout = 25920000)
  41. html = BeautifulSoup(full_description)
  42. nfo_pre = html.find('pre', attrs = {'class': 'nfo'})
  43. description = toUnicode(nfo_pre.text) if nfo_pre else ''
  44. item['description'] = description
  45. return item
  46. def extraCheck(self, item):
  47. full_description = self.getCache('nzbclub.%s' % item['id'], item['detail_url'], cache_timeout = 25920000)
  48. if 'ARCHIVE inside ARCHIVE' in full_description:
  49. log.info('Wrong: Seems to be passworded files: %s', item['name'])
  50. return False
  51. return True
  52. config = [{
  53. 'name': 'nzbclub',
  54. 'groups': [
  55. {
  56. 'tab': 'searcher',
  57. 'list': 'nzb_providers',
  58. 'name': 'NZBClub',
  59. 'description': 'Free provider, less accurate. See <a href="https://www.nzbclub.com/">NZBClub</a>',
  60. 'wizard': True,
  61. 'icon': 'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAACEUlEQVQ4y3VSMWgUQRR9/8/s7OzeJSdnTsVGghLEYBNQjBpQiRBFhIB2EcHG1kbs0murhZAmVocExEZQ0c7CxkLINYcJJpoYj9wZcnu72fF21uJSXMzuhyne58/j/fcf4b+KokgBIOSU53lxP5b9oNVqDT36dH+5UjoiKvIwPFEEgWBshGZ3E7/NOupL9fMjx0e+ZhKsrq+c/FPZKJi0w4FsQXMBDEJsd7BNW9h2tuyP9vfTALIJkMIu1hYRtINM+dpzcWc0sbkreK4fUEogyraAmKGF3+7vcT/wtR9QwkCabSAzQQuvk0uglAo5YaQ5DASGYjfMXcHVOqKu6NmR7iehlKAdHWUqWPv1c3i+9uwVdRlEBGaGEAJCCrDo9ShhvF6qPq8tL57bp+DbRn2sHtUuCY9YphLMu5921VhrwYJ5tbt0tt6sjQP4vEfB2Ikz7/ytwbeR6ljHkXCUA6UcOLtPOg4MYhtH8ZcLw5er+xQMDAwEURRNl96X596Y6oxFwsw9fmtTOAr2Ik19nL365FZpsLSdnQPPM8aYewc+lDcX4rkHqbQMAGTJXulOLzycmr1bKBTi3DOGYagajcahiaOT89fbM0/dxEsUu3aidfPljWO3HzebzYNBELi5Z5RSJlrrHd/3w8lT114MrVTWOn875fHRiYVisRhorWMpZXdvNnLKGCOstb0AMlulVJI19w/+nceU4D0aCwAAAABJRU5ErkJggg==',
  62. 'options': [
  63. {
  64. 'name': 'enabled',
  65. 'type': 'enabler',
  66. },
  67. {
  68. 'name': 'extra_score',
  69. 'advanced': True,
  70. 'label': 'Extra Score',
  71. 'type': 'int',
  72. 'default': 0,
  73. 'description': 'Starting score for each release found via this provider.',
  74. }
  75. ],
  76. },
  77. ],
  78. }]