Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #VERSION: 3.33
- from novaprinter import prettyPrinter
- import sgmllib
- from helpers import retrieve_url, download_file
- class nyaatorrents(object):
- url = 'http://www.nyaa.se'
- name = 'Nyaatorrents'
- supported_categories = {'all': '0_0', 'anime': '1_0', 'books': '2_0', 'music': '3_0', 'pictures': '4_0', 'software': '6_0', 'games': '6_24'}
- def __init__(self):
- self.results = []
- self.parser = self.SimpleSGMLParser(self.results, self.url)
- def download_torrent(self, info):
- print download_file(info)
- class SimpleSGMLParser(sgmllib.SGMLParser):
- def __init__(self, results, url):
- sgmllib.SGMLParser.__init__(self)
- self.td_counter = None
- self.current_item = None
- self.results = results
- self.url = url
- def start_a(self, attr):
- params = dict(attr)
- if 'page=view' in params['href']:
- self.current_item = {}
- self.td_counter = 0
- self.current_item['desc_link'] = params['href'].strip()
- elif 'page=download' in params['href']:
- self.current_item['link'] = params['href'].strip()
- def handle_data(self, data):
- if self.td_counter == 0:
- if not self.current_item.has_key('name'):
- self.current_item['name'] = ''
- self.current_item['name'] += data.strip()
- elif self.td_counter == 2:
- if not self.current_item.has_key('size'):
- self.current_item['size'] = ''
- self.current_item['size'] += data.strip()
- elif self.td_counter == 3:
- if not self.current_item.has_key('seeds'):
- self.current_item['seeds'] = ''
- self.current_item['seeds'] += data.strip()
- elif self.td_counter == 4:
- if not self.current_item.has_key('leech'):
- self.current_item['leech'] = ''
- self.current_item['leech'] += data.strip()
- def start_td(self, attr):
- if isinstance(self.td_counter, int):
- self.td_counter += 1
- if self.td_counter > 4:
- self.td_counter = None
- if self.current_item:
- self.current_item['engine_url'] = self.url
- if not self.current_item['seeds'].isdigit():
- self.current_item['seeds'] = 0
- if not self.current_item['leech'].isdigit():
- self.current_item['leech'] = 0
- prettyPrinter(self.current_item)
- self.results.append('a')
- def search(self, what, cat='all'):
- i = 1
- while True and i < 11:
- results = []
- parser = self.SimpleSGMLParser(results, self.url)
- dat = retrieve_url(self.url + '/?page=search&term=%s&offset=%d&cats=%s' % (what, i, self.supported_categories[cat]))
- parser.feed(dat)
- parser.close()
- if len(results) <= 0:
- break
- i += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement