Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
641
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.75 KB | None | 0 0
  1. import traceback
  2.  
  3. from bs4 import BeautifulSoup
  4. from couchpotato.core.logger import CPLog
  5. from couchpotato.core.helpers.variable import tryInt
  6. from couchpotato.core.helpers.encoding import tryUrlencode
  7. from couchpotato.core.media.movie.providers.base import MovieProvider
  8. from couchpotato.core.media._base.providers.torrent.base import TorrentProvider
  9. import six
  10.  
  11. log = CPLog(__name__)
  12.  
  13. def autoload():
  14.     return TorrentLeech()
  15.  
  16. class TorrentLeech(TorrentProvider, MovieProvider):
  17.  
  18.     urls = {
  19.         'test': 'https://www.torrentleech.org/',
  20.         'login': 'https://www.torrentleech.org/user/account/login/',
  21.         'login_check': 'https://torrentleech.org/user/messages',
  22.         'detail': 'https://www.torrentleech.org/torrent/%s',
  23.         'search': 'https://www.torrentleech.org/torrents/browse/index/query/%s/categories/%d',
  24.         'download': 'https://www.torrentleech.org%s',
  25.     }
  26.  
  27.     http_time_between_calls = 1  # Seconds
  28.     cat_backup_id = None
  29.  
  30.     cat_ids = [
  31.             ([13], ['720p', '1080p', 'bd50']),
  32.             ([8], ['cam']),
  33.             ([9], ['ts', 'tc']),
  34.             ([10], ['r5', 'scr']),
  35.             ([11], ['dvdrip']),
  36.             ([14], ['brrip']),
  37.             ([12], ['dvdr']),
  38.         ]
  39.  
  40.     def buildUrl(self, title, media, quality):
  41.         return (
  42.             tryUrlencode(title.replace(':', '')),
  43.             self.getCatId(quality)[0]
  44.         )
  45.  
  46.     def _searchOnTitle(self, title, media, quality, results):
  47.  
  48.         url = self.urls['search'] % self.buildUrl(title, media, quality)
  49.  
  50.         data = self.getHTMLData(url)
  51.  
  52.         if data:
  53.             html = BeautifulSoup(data)
  54.  
  55.             try:
  56.                 result_table = html.find('table', attrs = {'id': 'torrenttable'})
  57.                 if not result_table:
  58.                     return
  59.  
  60.                 entries = result_table.find_all('tr')
  61.  
  62.                 for result in entries[1:]:
  63.  
  64.                     link = result.find('td', attrs = {'class': 'name'}).find('a')
  65.                     url = result.find('td', attrs = {'class': 'quickdownload'}).find('a')
  66.                     details = result.find('td', attrs = {'class': 'name'}).find('a')
  67.  
  68.                     results.append({
  69.                         'id': link['href'].replace('/torrent/', ''),
  70.                         'name': six.text_type(link.string),
  71.                         'url': self.urls['download'] % url['href'],
  72.                         'detail_url': self.urls['download'] % details['href'],
  73.                         'size': self.parseSize(result.find_all('td')[4].string),
  74.                         'seeders': tryInt(result.find('td', attrs = {'class': 'seeders'}).string),
  75.                         'leechers': tryInt(result.find('td', attrs = {'class': 'leechers'}).string),
  76.                     })
  77.  
  78.             except:
  79.                 log.error('Failed to parsing %s: %s', (self.getName(), traceback.format_exc()))
  80.  
  81.     def getLoginParams(self):
  82.         return {
  83.             'username': self.conf('username'),
  84.             'password': self.conf('password'),
  85.             'remember_me': 'on',
  86.             'login': 'submit',
  87.         }
  88.  
  89.     def loginSuccess(self, output):
  90.         return '/user/account/logout' in output.lower() or 'welcome back' in output.lower()
  91.  
  92.     loginCheckSuccess = loginSuccess
  93.  
  94.  
  95. config = [{
  96.     'name': 'torrentleech',
  97.     'groups': [
  98.         {
  99.             'tab': 'searcher',
  100.             'list': 'torrent_providers',
  101.             'name': 'TorrentLeech',
  102.             'description': '<a href="http://torrentleech.org">TorrentLeech</a>',
  103.             'wizard': True,
  104.             'icon': 'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAACHUlEQVR4AZVSO48SYRSdGTCBEMKzILLAWiybkKAGMZRUUJEoDZX7B9zsbuQPYEEjNLTQkYgJDwsoSaxspEBsCITXjjNAIKi8AkzceXgmbHQ1NJ5iMufmO9/9zrmXlCSJ+B8o75J8Pp/NZj0eTzweBy0Wi4PBYD6f12o1r9ebTCZx+22HcrnMsuxms7m6urTZ7LPZDMVYLBZ8ZV3yo8aq9Pq0wzCMTqe77dDv9y8uLyAWBH6xWOyL0K/56fcb+rrPgPZ6PZfLRe1fsl6vCUmGKIqoqNXqdDr9Dbjps9znUV0uTqdTjuPkDoVCIfcuJ4gizjMMm8u9vW+1nr04czqdK56c37CbKY9j2+1WEARZ0Gq1RFHAz2q1qlQqXxoN69HRcDjUarW8ZD6QUigUOnY8uKYH8N1sNkul9yiGw+F6vS4Rxn8EsodEIqHRaOSnq9T7ajQazWQycEIR1AEBYDabSZJyHDucJyegwWBQr9ebTCaKvHd4cCQANUU9evwQ1Ofz4YvUKUI43GE8HouSiFiNRhOowWBIpVLyHITJkuW3PwgAEf3pgIwxF5r+OplMEsk3CPT5szCMnY7EwUdhwUh/CXiej0Qi3idPz89fdrpdbsfBzH7S3Q9K5pP4c0sAKpVKoVAQGO1ut+t0OoFAQHkH2Da/3/+but3uarWK0ZMQoNdyucRutdttmqZxMTzY7XaYxsrgtUjEZrNhkSwWyy/0NCatZumrNQAAAABJRU5ErkJggg==',
  105.             'options': [
  106.                 {
  107.                     'name': 'enabled',
  108.                     'type': 'enabler',
  109.                     'default': False,
  110.                 },
  111.                 {
  112.                     'name': 'username',
  113.                     'default': '',
  114.                 },
  115.                 {
  116.                     'name': 'password',
  117.                     'default': '',
  118.                     'type': 'password',
  119.                 },
  120.                 {
  121.                     'name': 'seed_ratio',
  122.                     'label': 'Seed ratio',
  123.                     'type': 'float',
  124.                     'default': 1,
  125.                     'description': 'Will not be (re)moved until this seed ratio is met.',
  126.                 },
  127.                 {
  128.                     'name': 'seed_time',
  129.                     'label': 'Seed time',
  130.                     'type': 'int',
  131.                     'default': 40,
  132.                     'description': 'Will not be (re)moved until this seed time (in hours) is met.',
  133.                 },
  134.                 {
  135.                     'name': 'extra_score',
  136.                     'advanced': True,
  137.                     'label': 'Extra Score',
  138.                     'type': 'int',
  139.                     'default': 20,
  140.                     'description': 'Starting score for each release found via this provider.',
  141.                 }
  142.             ],
  143.         },
  144.     ],
  145. }]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement