Guest User

x264.py

a guest
Oct 17th, 2011
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.66 KB | None | 0 0
  1. from app.config.cplog import CPLog
  2. from app.lib.provider.yarr.base import torrentBase
  3. from imdb.parser.http.bsouplxml._bsoup import SoupStrainer, BeautifulSoup
  4. from urllib import quote_plus
  5. import time
  6. import urllib
  7. import urllib2
  8. import re
  9.  
  10. log = CPLog(__name__)
  11.  
  12. class x264(torrentBase):
  13.     """Provider for MysterBin"""
  14.  
  15.     name = 'x264'
  16.     searchUrl = 'http://www.mysterbin.com/search?q=%s&fytype=1&fsize=6'
  17.     downloadUrl = 'http://www.mysterbin.com/nzb?c=%s'
  18.  
  19.     def __init__(self, config):
  20.         log.info('Using Mystery Bin')
  21.  
  22.         self.config = config
  23.  
  24.     def conf(self, option):
  25.         return self.config.get('x264', option)
  26.  
  27.     def enabled(self):
  28.         return self.conf('enabled') and self.config.get('NZB', 'enabled')
  29.    
  30.     def find(self, movie, quality, type):
  31.  
  32.         results = []
  33.         if not self.enabled() or not self.isAvailable(self.searchUrl):
  34.             return results
  35.  
  36.         url = self.searchUrl % quote_plus(self.toSearchString(movie.name + ' ' + quality))
  37.         log.info('Searching: %s' % url)
  38.         data = urllib.urlopen(url)
  39.  
  40.         try:
  41.             tables = SoupStrainer('table')
  42.             html = BeautifulSoup(data, parseOnlyThese = tables)
  43.             resultable = html.find('table', attrs = {'class':'t'})
  44.             for result in resultable.findAll('span', attrs = {'class':'cname'}):
  45.                 new = self.feedItem()
  46.                 a = result.find('a')
  47.                 id  = re.search('(?<=detail\?c\=)\w+', a['href'])
  48.                 new.id = id.group(0)
  49.                 text = a.findAll(text=True)
  50.                 words = ''
  51.                 for text in a.findAll(text=True):
  52.                     words = words + unicode(text).encode('utf-8')
  53.                 new.name = words
  54.                 new.size = 9999
  55.                 new.content = 'x264'
  56.                 new.type = 'nzb'
  57.                 new.url = self.downloadUrl % (new.id)
  58.                 new.date = time.time()
  59.                 new.score = self.calcScore(new, movie)
  60.  
  61.                 if self.isCorrectMovie(new, movie, type):
  62.                     results.append(new)
  63.                     log.info('Found: %s' % new.name)
  64.             return results
  65.  
  66.         except AttributeError:
  67.             log.debug('No search results found.')
  68.  
  69.         return results
  70.  
  71.     def makeIgnoreString(self, type):
  72.         return ''
  73.  
  74.     def getInfo(self, url):
  75.         log.debug('Getting info: %s' % url)
  76.         try:
  77.             data = urllib2.urlopen(url, timeout = self.timeout).read()
  78.             pass
  79.         except IOError:
  80.             log.error('Failed to open %s.' % url)
  81.             return ''
  82.        
  83.         return ''
  84.  
  85.  
  86.  
  87.  
Advertisement
Add Comment
Please, Sign In to add comment