def process(self, buff): """ Finds referentes to torrents in buffer. Returns a list with torrent infos """ soup = bs4.BeautifulSoup(buff) trs = soup.select('table > tr')[:-1] torrents = [] for tr in trs: details = tr.select('font.detDesc')[0].text try: (amount, suffix) = re.findall(r'([0-9\.]+)\s([GMK])iB', details, re.IGNORECASE)[0] size = int(float(amount) * self._SIZE_TABLE[suffix]) except: self._logger.warning(_("Invalid torrent found")) continue data = { 'name' : tr.findAll('a')[2].text, 'language' : 'en-US', 'uri' : tr.findAll('a')[3]['href'], 'size' : size, 'timestamp': utcnow_timestamp(), 'seeds' : int(tr.findAll('td')[-2].text), 'leechers' : int(tr.findAll('td')[-1].text) } torrents.append(Torrent(**data)) return torrents
def process(self, buff): """ Finds referentes to torrents in buffer. Returns a list with torrent infos """ soup = bs4.BeautifulSoup(buff) torrents = [] for tr in soup.select('tr'): children = tr.findChildren('td') if len(children) != 5: continue try: torrents.append(Torrent(**{ 'name': children[1].text.strip(), 'uri': children[2].select('a.magnet')[0]['href'], 'language': 'en-US', 'timestamp': utcnow_timestamp(), })) except IndexError: continue return torrents
trackers = [quote_plus(x) for x in ['udp://tracker.openbittorrent.com:80', 'udp://tracker.publicbt.com:80', 'udp://tracker.istole.it:6969']] trackers = '&tr='.join(trackers) # Generate Transfer objects TRANSFERS = [] for (idx, tmp) in enumerate(DATA): trsf = tmp[0].copy() del(trsf['id']) TRANSFERS.insert(idx, trsf) # Generate Torrent objects INFOS = [] for (idx, d) in enumerate(DATA): transfer, t_meta = d[0].copy(), d[1].copy() info = t_meta.copy() info.update({ 'uri': 'magnet:?xt=urn:btih:{hash_string}&dn={name}&{trackers}'.format( hash_string=transfer['hash_string'], name=quote_plus(transfer['name']), trackers=trackers), 'name': transfer['name'], 'provider': 'test', 'size': int(transfer['size_when_done']) or (1024**3), 'timestamp': utcnow_timestamp() }) INFOS.insert(idx, info)