def parse(self, data, mode): """ Parse search results from data :param data: response data :param mode: search mode :return: search results """ results = [] with bs4_parser(data) as html: torrent_table = html.find('table', attrs={'id': 'torrents-table'}) torrent_rows = torrent_table.find_all('tr') if torrent_table else [] # Continue only if at least one Release is found if len(torrent_rows) < 2: sickrage.app.log.debug("Data returned from provider does not contain any torrents") return results for result in torrent_table.find_all('tr')[1:]: try: link = result.find('td', attrs={'class': 'ttr_name'}).find('a') url = result.find('td', attrs={'class': 'td_dl'}).find('a') title = link.string if re.search(r'\.\.\.', title): data = sickrage.app.wsession.get(self.urls['base_url'] + "/" + link['href']).text with bs4_parser(data) as details_html: title = re.search('(?<=").+(?<!")', details_html.title.string).group(0) download_url = self.urls['download'] % url['href'] seeders = int(result.find('td', attrs={'class': 'ttr_seeders'}).string) leechers = int(result.find('td', attrs={'class': 'ttr_leechers'}).string) size = convert_size(result.find('td', attrs={'class': 'ttr_size'}).contents[0], -1) if not all([title, download_url]): continue item = {'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers, 'hash': ''} if mode != 'RSS': sickrage.app.log.debug("Found result: {}".format(title)) results.append(item) except Exception: sickrage.app.log.error("Failed parsing provider") return results
def parse(self, data, mode, **kwargs): """ Parse search results from data :param data: response data :param mode: search mode :return: search results """ results = [] def _process_title(title): # Quality, if no literal is defined it's HDTV if 'calidad' not in title: title += ' HDTV x264' else: title = title.replace('(calidad baja)', 'HDTV x264') title = title.replace('(Buena calidad)', '720p HDTV x264') title = title.replace('(Alta calidad)', '720p HDTV x264') title = title.replace('(calidad regular)', 'DVDrip x264') title = title.replace('(calidad media)', 'DVDrip x264') # Language, all results from this provider have spanish audio, we append it to title (avoid to download undesired torrents) title += ' SPANISH AUDIO-ELITETORRENT' return title with bs4_parser(data) as html: torrent_table = html.find('table', class_='fichas-listado') torrent_rows = torrent_table('tr') if torrent_table else [] if len(torrent_rows) < 2: sickrage.app.log.debug("Data returned from provider does not contain any torrents") return results for row in torrent_rows[1:]: try: title = _process_title(row.find('a', class_='nombre')['title']) download_url = self.urls['base_url'] + row.find('a')['href'] if not all([title, download_url]): continue seeders = try_int(row.find('td', class_='semillas').get_text(strip=True)) leechers = try_int(row.find('td', class_='clientes').get_text(strip=True)) # seeders are not well reported. Set 1 in case of 0 seeders = max(1, seeders) # Provider does not provide size size = -1 results += [ {'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers} ] if mode != 'RSS': sickrage.app.log.debug("Found result: {}".format(title)) except Exception: sickrage.app.log.error("Failed parsing provider") return results
def test_search(self): self.url = 'kickass.unblocked.li' searchURL = '{}/usearch/American%20Dad%20S08/'.format(self.url) data = WebSession().get(searchURL) if not data: return with bs4_parser(data) as html: torrent_table = html.find('table', attrs={'class': 'data'}) # Continue only if one Release is found torrent_rows = torrent_table.find_all('tr') if torrent_table else [] if len(torrent_rows) < 2: print("The data returned does not contain any torrents") return for tr in torrent_rows[1:]: try: link = urlparse.urljoin(self.url, (tr.find('div', {'class': 'torrentname'}).find_all('a')[1])['href']) id = tr.get('id')[-7:] title = (tr.find('div', {'class': 'torrentname'}).find_all('a')[1]).text \ or (tr.find('div', {'class': 'torrentname'}).find_all('a')[2]).text url = tr.find('a', 'imagnet')['href'] verified = True if tr.find('a', 'iverify') else False trusted = True if tr.find('img', {'alt': 'verified'}) else False seeders = int(tr.find_all('td')[-2].text) leechers = int(tr.find_all('td')[-1].text) except (AttributeError, TypeError): continue print title
def get_download_url(self, url): try: data = sickrage.app.wsession.get(urljoin(self.urls['base_url'], url)).text with bs4_parser(data) as html: return html.find('div', class_="btn-magnet").find('a').get('href') except Exception: pass
def parse(self, data, mode, **kwargs): """ Parse search results from data :param data: response data :param mode: search mode :return: search results """ results = [] with bs4_parser(data) as html: table_body = html.find('tbody') # Continue only if at least one release is found if not table_body: sickrage.app.log.debug('Data returned from provider does not contain any torrents') return results for row in table_body('tr'): cells = row('td') if len(cells) < 4: continue try: title = download_url = None info_cell = cells[0].a if info_cell: title = info_cell.get_text() download_url = self._get_download_link(urljoin(self.urls['base_url'], info_cell.get('href'))) if not all([title, download_url]): continue title = '{name} {codec}'.format(name=title, codec='x264') if self.custom_url: if not validate_url(self.custom_url): sickrage.app.log.warning("Invalid custom url: {}".format(self.custom_url)) return results download_url = urljoin(self.custom_url, download_url.split(self.urls['base_url'])[1]) seeders = try_int(cells[2].get_text(strip=True)) leechers = try_int(cells[3].get_text(strip=True)) torrent_size = cells[1].get_text() size = convert_size(torrent_size, -1) results += [{ 'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers }] if mode != 'RSS': sickrage.app.log.debug("Found result: {}".format(title)) except Exception: sickrage.app.log.error("Failed parsing provider") return results
def parse(self, data, mode): """ Parse search results from data :param data: response data :param mode: search mode :return: search results """ results = [] with bs4_parser(data) as html: # Continue only if one Release is found empty = html.find('h2', text="No .torrents fit this filter criteria") if empty: sickrage.app.log.debug("Data returned from provider does not contain any torrents") return results torrent_table = html.find('table', attrs={'style': 'border: none; width: 100%;'}) if not torrent_table: sickrage.app.log.error("Could not find table of torrents") return results torrent_rows = torrent_table.find_all('tr', attrs={'class': 'browse'}) for result in torrent_rows: cells = result.find_all('td') size = None link = cells[1].find('a', attrs={'style': 'font-size: 1.25em; font-weight: bold;'}) torrent_id = link['href'].replace('details.php?id=', '') try: if link.has_key('title'): title = link['title'] else: title = link.contents[0] download_url = self.urls['download'] % (torrent_id, link.contents[0]) seeders = int(cells[9].contents[0]) leechers = int(cells[10].contents[0]) # Need size for failed downloads handling if size is None: if re.match(r'[0-9]+,?\.?[0-9]*[KkMmGg]+[Bb]+', cells[7].text): size = convert_size(cells[7].text, -1) if not all([title, download_url]): continue item = {'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers, 'hash': ''} if mode != 'RSS': sickrage.app.log.debug("Found result: {}".format(title)) results.append(item) except Exception: sickrage.app.log.error("Failed parsing provider.") return results
def fetch_popular_shows(self): """Get popular show information from IMDB""" popular_shows = [] data = getURL(self.url, session=self.session, params=self.params, headers={"Referer": "http://akas.imdb.com/"}) if not data: return None with bs4_parser(data) as soup: results = soup.find("table", {"class": "results"}) rows = results.find_all("tr") for row in rows: show = {} image_td = row.find("td", {"class": "image"}) if image_td: image = image_td.find("img") show[b"image_url_large"] = self.change_size(image[b"src"], 3) show[b"image_path"] = os.path.join("images", "imdb_popular", os.path.basename(show[b"image_url_large"])) self.cache_image(show[b"image_url_large"]) td = row.find("td", {"class": "title"}) if td: show[b"name"] = td.find("a").contents[0] show[b"imdb_url"] = "http://www.imdb.com" + td.find("a")["href"] show[b"imdb_tt"] = show[b"imdb_url"][-10:][0:9] show[b"year"] = td.find("span", {"class": "year_type"}).contents[0].split(" ")[0][1:] rating_all = td.find("div", {"class": "user_rating"}) if rating_all: rating_string = rating_all.find("div", {"class": "rating rating-list"}) if rating_string: rating_string = rating_string[b"title"] match = re.search(r".* (.*)\/10.*\((.*)\).*", rating_string) if match: matches = match.groups() show[b"rating"] = matches[0] show[b"votes"] = matches[1] else: show[b"rating"] = None show[b"votes"] = None else: show[b"rating"] = None show[b"votes"] = None outline = td.find("span", {"class": "outline"}) if outline: show[b"outline"] = outline.contents[0] else: show[b"outline"] = "" popular_shows.append(show) return popular_shows
def parse(self, data, mode, **kwargs): """ Parse search results from data :param data: response data :param mode: search mode :return: search results """ results = [] def process_column_header(td): result = '' if td.a and td.a.img: result = td.a.img.get('title', td.a.get_text(strip=True)) if not result: result = td.get_text(strip=True) return result with bs4_parser(data) as html: torrent_table = html.find('table', attrs={'id': 'torrent_table'}) torrent_rows = torrent_table('tr') if torrent_table else [] # Continue only if one Release is found if len(torrent_rows) < 2: sickrage.app.log.debug("Data returned from provider does not contain any torrents") return results # '', '', 'Name /Year', 'Files', 'Time', 'Size', 'Snatches', 'Seeders', 'Leechers' labels = [process_column_header(label) for label in torrent_rows[0]('td')] # Skip column headers for row in torrent_rows[1:]: try: cells = row('td') if len(cells) < len(labels): continue title = cells[labels.index('Name /Year')].find('a', dir='ltr').get_text(strip=True) download = cells[labels.index('Name /Year')].find('a', title='Download')['href'] download_url = urljoin(self.urls['base_url'], download) if not all([title, download_url]): continue seeders = try_int(cells[labels.index('Seeders')].get_text(strip=True)) leechers = try_int(cells[labels.index('Leechers')].get_text(strip=True)) torrent_size = cells[labels.index('Size')].get_text(strip=True) size = convert_size(torrent_size, -1) results += [ {'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers} ] if mode != 'RSS': sickrage.app.log.debug('Found result: {}'.format(title)) except Exception: sickrage.app.log.error('Failed parsing provider') return results
def search(self, search_string, search_mode='eponly', epcount=0, age=0, epObj=None): # FIXME ADD MODE if self.show and not self.show.is_anime: return [] sickrage.srCore.srLogger.debug("Search string: %s " % search_string) params = { "terms": search_string.encode('utf-8'), "type": 1, # get anime types } searchURL = self.urls['base_url'] + '/search.php?' + urllib.urlencode(params) sickrage.srCore.srLogger.debug("Search URL: %s" % searchURL) try: data = sickrage.srCore.srWebSession.get(searchURL).text except Exception: sickrage.srCore.srLogger.debug("No data returned from provider") return [] results = [] try: with bs4_parser(data) as html: torrent_table = html.find('table', attrs={'class': 'listing'}) torrent_rows = torrent_table.find_all('tr') if torrent_table else [] if torrent_rows: if torrent_rows[0].find('td', attrs={'class': 'centertext'}): a = 1 else: a = 0 for top, bottom in zip(torrent_rows[a::2], torrent_rows[a::2]): title = top.find('td', attrs={'class': 'desc-top'}).text title.lstrip() download_url = top.find('td', attrs={'class': 'desc-top'}).find('a')['href'] # FIXME size = -1 seeders = 1 leechers = 0 if not all([title, download_url]): continue # Filter unseeded torrent # if seeders < self.minseed or leechers < self.minleech: # if mode != 'RSS': # LOGGER.debug(u"Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format(title, seeders, leechers)) # continue item = title, download_url, size, seeders, leechers results.append(item) except Exception as e: sickrage.srCore.srLogger.error("Failed parsing provider. Traceback: %s" % traceback.format_exc()) # FIXME SORTING return results
def _doSearch(self, search_params, search_mode='eponly', epcount=0, age=0, epObj=None): results = [] items = {'Season': [], 'Episode': [], 'RSS': []} # check for auth if not self._doLogin(): return results for mode in search_params.keys(): sickrage.LOGGER.debug("Search Mode: %s" % mode) for search_string in search_params[mode]: if mode is not 'RSS': sickrage.LOGGER.debug("Search string: %s " % search_string) searchURL = self.urlsearch % (urllib.quote(search_string), self.categories) sickrage.LOGGER.debug("Search URL: %s" % searchURL) data = self.getURL(searchURL) if not data: continue with bs4_parser(data) as html: resultsTable = html.find("table", {"class": "table2 table-bordered2"}) if resultsTable: rows = resultsTable.findAll("tr") for row in rows: link = row.find("a", href=re.compile("details.php")) if link: title = link.text download_url = self.url + '/' + row.find("a", href=re.compile("download.php"))['href'] # FIXME size = -1 seeders = 1 leechers = 0 if not all([title, download_url]): continue # Filter unseeded torrent # if seeders < self.minseed or leechers < self.minleech: # if mode is not 'RSS': # sickrage.LOGGER.debug(u"Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format(title, seeders, leechers)) # continue item = title, download_url, size, seeders, leechers if mode is not 'RSS': sickrage.LOGGER.debug("Found result: %s " % title) items[mode].append(item) # For each search mode sort all the items by seeders if available if available items[mode].sort(key=lambda tup: tup[3], reverse=True) results += items[mode] return results
def parse(self, data, mode, **kwargs): """ Parse search results from data :param data: response data :param mode: search mode :return: search results """ results = [] def process_column_header(td): td_title = '' if td.img: td_title = td.img.get('title', td.get_text(strip=True)) if not td_title: td_title = td.get_text(strip=True) return td_title with bs4_parser(data) as html: torrent_table = html.find('table', id='sortabletable') torrent_rows = torrent_table('tr') if torrent_table else [] # Continue only if at least one Release is found if len(torrent_rows) < 2: sickrage.app.log.debug("Data returned from provider does not contain any torrents") return results labels = [process_column_header(label) for label in torrent_rows[0]('td')] # Skip column headers for result in torrent_rows[1:]: try: title = result.find('div', class_='tooltip-target').get_text(strip=True) # skip if torrent has been nuked due to poor quality if title.startswith('Nuked.'): continue download_url = result.find( 'img', title='Click to Download this Torrent in SSL!').parent['href'] if not all([title, download_url]): continue cells = result('td') seeders = try_int(cells[labels.index('Seeders')].get_text(strip=True)) leechers = try_int(cells[labels.index('Leechers')].get_text(strip=True)) torrent_size = cells[labels.index('Size')].get_text(strip=True) size = convert_size(torrent_size, -1) results += [ {'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers} ] if mode != 'RSS': sickrage.app.log.debug("Found result: {}".format(title)) except Exception: sickrage.app.log.error("Failed parsing provider") return results
def parse(self, data, mode): """ Parse search results from data :param data: response data :param mode: search mode :return: search results """ results = [] with bs4_parser(data) as html: torrent_rows = html.findAll('tr') # Continue only if one Release is found if len(torrent_rows) < 2: sickrage.app.log.debug("Data returned from provider does not contain any torrents") return results # Scenetime apparently uses different number of cells in #torrenttable based # on who you are. This works around that by extracting labels from the first # <tr> and using their index to find the correct download/seeders/leechers td. labels = [label.get_text() for label in torrent_rows[0].find_all('td')] for result in torrent_rows[1:]: cells = result.find_all('td') link = cells[labels.index('Name')].find('a') full_id = link['href'].replace('details.php?id=', '') torrent_id = full_id.split("&")[0] try: title = link.contents[0].get_text() filename = "%s.torrent" % title.replace(" ", ".") download_url = self.urls['download'] % (torrent_id, filename) int(cells[labels.index('Seeders')].get_text()) seeders = int(cells[labels.index('Seeders')].get_text()) leechers = int(cells[labels.index('Leechers')].get_text()) # FIXME size = -1 if not all([title, download_url]): continue item = {'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers, 'hash': ''} if mode != 'RSS': sickrage.app.log.debug("Found result: {}".format(title)) results.append(item) except Exception: sickrage.app.log.error("Failed parsing provider") return results
def search(self, search_strings, search_mode='eponly', epcount=0, age=0, epObj=None): results = [] for mode in search_strings: items = [] sickrage.srCore.srLogger.debug('Search Mode: {}'.format(mode)) for search_string in search_strings[mode]: search_url = self.urls['feed'] if mode != 'RSS': sickrage.srCore.srLogger.debug('Search string: {}'.format(search_string)) try: data = sickrage.srCore.srWebSession.get(search_url, params={'f': search_string}).text except Exception: sickrage.srCore.srLogger.debug('No data returned from provider') continue if not data.startswith('<?xml'): sickrage.srCore.srLogger.info('Expected xml but got something else, is your mirror failing?') continue with bs4_parser(data) as parser: for item in parser('item'): if item.category and 'tv' not in item.category.get_text(strip=True): continue title = item.title.get_text(strip=True) t_hash = item.guid.get_text(strip=True).rsplit('/', 1)[-1] if not all([title, t_hash]): continue download_url = "magnet:?xt=urn:btih:" + t_hash + "&dn=" + title torrent_size, seeders, leechers = self._split_description(item.find('description').text) size = convert_size(torrent_size) or -1 # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != 'RSS': sickrage.srCore.srLogger.debug("Discarding torrent because it doesn't meet the minimum seeders or leechers: {} (S:{} L:{})".format(title, seeders, leechers)) continue items += [{ 'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers, 'hash': t_hash }] # For each search mode sort all the items by seeders if available items.sort(key=lambda d: int(d.get('seeders', 0)), reverse=True) results += items return results
def parse(self, data, mode): """ Parse search results from data :param data: response data :param mode: search mode :return: search results """ results = [] with bs4_parser(data) as html: torrent_table = html.find("table", border="1") torrent_rows = torrent_table("tr") if torrent_table else [] # Continue only if at least one Release is found if len(torrent_rows) < 2: sickrage.app.log.debug("Data returned from provider does not contain any torrents") return results # "Type", "Name", Files", "Comm.", "Added", "TTL", "Size", "Snatched", "Seeders", "Leechers" labels = [label.get_text(strip=True) for label in torrent_rows[0]("td")] for result in torrent_rows[1:]: try: cells = result("td") link = cells[labels.index("Name")].find("a", href=re.compile(r"download.php\?id="))["href"] download_url = urljoin(self.urls['base_url'], link) title_element = cells[labels.index("Name")].find("a", href=re.compile(r"details.php\?id=")) title = title_element.get("title", "") or title_element.get_text(strip=True) if not all([title, download_url]): continue if self.freeleech: # Free leech torrents are marked with green [F L] in the title (i.e. <font color=green>[F L]</font>) freeleech = cells[labels.index("Name")].find("font", color="green") if not freeleech or freeleech.get_text(strip=True) != "[F\xa0L]": continue seeders = try_int(cells[labels.index("Seeders")].get_text(strip=True)) leechers = try_int(cells[labels.index("Leechers")].get_text(strip=True)) torrent_size = cells[labels.index("Size")].get_text(strip=True) size = convert_size(torrent_size, -1) item = {'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers, 'hash': ''} if mode != "RSS": sickrage.app.log.debug("Found result: {}".format(title)) results.append(item) except Exception: sickrage.app.log.error("Failed parsing provider.") return results
def parse(self, data, mode, **kwargs): """ Parse search results for items. :param data: The raw response from a search :param mode: The current mode used to search, e.g. RSS :return: A list of items found """ results = [] with bs4_parser(data) as html: torrent_table = html.find(class_='table-responsive results') torrent_rows = torrent_table('tr') if torrent_table else [] # Continue only if at least one Release is found if len(torrent_rows) < 2: sickrage.app.log.debug('Data returned from provider does not contain any torrents') return results for result in torrent_rows[1:]: cells = result('td') if len(cells) < 9: continue try: info = cells[1].find('a') title = info.get_text(strip=True) download_url = info.get('href') if not (title and download_url): continue torrent_id = re.search(r'/(\d+)-', download_url) download_url = self.urls['download'] % torrent_id.group(1) seeders = try_int(cells[7].get_text(strip=True), 0) leechers = try_int(cells[8].get_text(strip=True), 0) torrent_size = cells[5].get_text() size = convert_size(torrent_size, -1, ['O', 'KO', 'MO', 'GO', 'TO', 'PO']) results += [{ 'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers }] if mode != 'RSS': sickrage.app.log.debug("Found result: {}".format(title)) except Exception: sickrage.app.log.error('Failed parsing provider.') return results
def parse(self, data, mode): """ Parse search results from data :param data: response data :param mode: search mode :return: search results """ results = [] with bs4_parser(data) as html: torrent_table = html.find(class_='torrent_table') torrent_rows = torrent_table('tr') if torrent_table else [] # Continue only if at least one Release is found if len(torrent_rows) < 2: sickrage.app.log.debug('Data returned from provider does not contain any torrents') return results # Catégorie, Release, Date, DL, Size, C, S, L labels = [label.get_text(strip=True) for label in torrent_rows[0]('td')] # Skip column headers for result in torrent_rows[1:]: try: cells = result('td') if len(cells) < len(labels): continue title = cells[labels.index('Release')].get_text(strip=True) download_url = urljoin(self.urls['base_url'], cells[labels.index('DL')].find('a', class_='tooltip')['href']) if not all([title, download_url]): continue seeders = try_int(cells[labels.index('S')].get_text(strip=True)) leechers = try_int(cells[labels.index('L')].get_text(strip=True)) size_index = labels.index('Size') if 'Size' in labels else labels.index('Taille') units = ['O', 'KO', 'MO', 'GO', 'TO', 'PO'] size = convert_size(cells[size_index].get_text(), -1, units) item = {'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers, 'hash': ''} if mode != 'RSS': sickrage.app.log.debug('Found result: {}'.format(title)) results.append(item) except Exception: sickrage.app.log.error('Failed parsing provider') return results
def parse(self, data, mode): """ Parse search results from data :param data: response data :param mode: search mode :return: search results """ results = [] with bs4_parser(data) as html: torrent_table = html.find("div", id="torrentBrowse") torrent_rows = torrent_table.findChildren("tr") if torrent_table else [] # Continue only if at least one release is found if len(torrent_rows) < 1: sickrage.app.log.debug("Data returned from provider does not contain any torrents") return results for result in torrent_rows[1:]: try: cells = result.findChildren("td") title = cells[1].find("a").find_next("a") link = cells[3].find("a") shares = cells[8].get_text().split("/", 1) torrent_size = cells[7].get_text().split("/", 1)[0] if title.has_key('title'): title = title['title'] else: title = cells[1].find("a")['title'] download_url = self.urls['download'] % (link['href']) seeders = int(shares[0]) leechers = int(shares[1]) size = -1 if re.match(r"\d+([,.]\d+)?\s*[KkMmGgTt]?[Bb]", torrent_size): size = convert_size(torrent_size.rstrip(), -1) if not all([title, download_url]): continue item = {'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers, 'hash': ''} if mode != 'RSS': sickrage.app.log.debug("Found result: {}".format(title)) results.append(item) except Exception: sickrage.app.log.error("Failed parsing provider.") return results
def parse(self, data, mode): """ Parse search results from data :param data: response data :param mode: search mode :return: search results """ results = [] with bs4_parser(data) as html: torrent_tables = html.find_all('table', class_='release-table') torrent_rows = [] for torrent_table in torrent_tables: curr_torrent_rows = torrent_table('tr') if torrent_table else [] torrent_rows.extend(curr_torrent_rows) # Continue only if one Release is found if len(torrent_rows) < 1: sickrage.app.log.debug("Data returned from provider does not contain any torrents") return results for torrent_row in torrent_rows: try: label = torrent_row.find('td', class_='dl-label') title = label.get_text(strip=True) size = -1 seeders = 1 leechers = 1 link = torrent_row.find('td', class_='hs-torrent-link') download_url = link.find('a')['href'] if link and link.find('a') else None if not download_url: # fallback to magnet link link = torrent_row.find('td', class_='hs-magnet-link') download_url = link.find('a')['href'] if link and link.find('a') else None if not all([title, download_url]): continue item = {'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers, 'hash': ''} if mode != 'RSS': sickrage.app.log.debug("Found result: {}".format(title)) results.append(item) except Exception: sickrage.app.log.error("Failed parsing provider") return results
def parse(self, data, mode): """ Parse search results for items. :param data: The raw response from a search :param mode: The current mode used to search, e.g. RSS :return: A list of items found """ results = [] with bs4_parser(data) as html: torrent_table = html.find(class_='table table-striped') torrent_rows = torrent_table('tr') if torrent_table else [] # Continue only if at least one Release is found if len(torrent_rows) < 2: sickrage.app.log.debug('Data returned from provider does not contain any torrents') return results # Skip column headers for result in torrent_rows[1:]: cells = result('td') if len(cells) < 5: continue try: title = cells[0].find('a', class_='torrent-name').get_text(strip=True) download_url = urljoin(self.urls['base_url'], cells[0].find('a', target='_blank')['href']) if not (title and download_url): continue seeders = try_int(cells[4].get_text(strip=True), 1) leechers = try_int(cells[5].get_text(strip=True), 0) torrent_size = cells[3].get_text() size = convert_size(torrent_size, -1) item = { 'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers } if mode != 'RSS': sickrage.app.log.debug('Found result: {}'.format(title)) results.append(item) except Exception: sickrage.app.log.error('Failed parsing provider.') return results
def search(self, search_strings, search_mode='eponly', epcount=0, age=0, epObj=None): results = [] items = {'Season': [], 'Episode': [], 'RSS': []} for mode in search_strings: for search_string in search_strings[mode]: search_url = self.urls['verified'] if self.confirmed else self.urls['feed'] if mode != 'RSS': search_url += '?q=' + quote_plus(search_string) sickrage.srCore.srLogger.info(search_url) try: data = sickrage.srCore.srWebSession.get(search_url).text except Exception: sickrage.srCore.srLogger.info('Seems to be down right now!') continue if not data.startswith('<?xml'): sickrage.srCore.srLogger.info('Expected xml but got something else, is your mirror failing?') continue with bs4_parser(data) as html: if not html: sickrage.srCore.srLogger.debug("No html data parsed from provider") continue for item in html('item'): if item.category and 'tv' not in item.category.get_text(strip=True): continue title = item.title.text.rsplit(' ', 1)[0].replace(' ', '.') t_hash = item.guid.text.rsplit('/', 1)[-1] if not all([title, t_hash]): continue download_url = "magnet:?xt=urn:btih:" + t_hash + "&dn=" + title torrent_size, seeders, leechers = self._split_description(item.find('description').text) size = convert_size(torrent_size) or -1 # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != 'RSS': sickrage.srCore.srLogger.debug("Discarding torrent because it doesn't meet the minimum seeders or leechers: {} (S:{} L:{})".format(title, seeders, leechers)) continue items[mode].append((title, download_url, size, seeders, leechers)) # For each search mode sort all the items by seeders if available items[mode].sort(key=lambda tup: tup[3], reverse=True) results += items[mode] return results
def parse(self, data, mode, **kwargs): """ Parse search results for items. :param data: The raw response from a search :param mode: The current mode used to search, e.g. RSS :return: A list of items found """ results = [] with bs4_parser(data) as html: if 'no encontrada' in html.get_text(): return results try: link = html.find(rel='canonical') if not link: return results try: title = unidecode(html.find('h1').get_text().split('/')[1]) title = self._process_title(title, link['href']) except Exception: title = None try: download_url = self.urls['download'] % re.search( r'http://tumejorserie.com/descargar/.+?(\d{6}).+?\.html', html.get_text(), re.DOTALL).group(1) except Exception: download_url = None if not all([title, download_url]): return results seeders = 1 # Provider does not provide seeders leechers = 0 # Provider does not provide leechers torrent_size = html.find_all(class_='imp')[1].get_text() torrent_size = re.sub(r'Size: ([\d.]+).+([KMGT]B)', r'\1 \2', torrent_size) size = convert_size(torrent_size, -1) results += [ {'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers} ] if mode != 'RSS': sickrage.app.log.debug("Found result: {}".format(title)) except Exception: sickrage.app.log.error('Failed parsing provider') return results
def parse(self, data, mode): """ Parse search results from data :param data: response data :param mode: search mode :return: search results """ results = [] with bs4_parser(data) as html: torrent_rows = [] down_elems = html.findAll("img", {"alt": "Download Torrent"}) for down_elem in down_elems: if down_elem: torr_row = down_elem.findParent('tr') if torr_row: torrent_rows.append(torr_row) # Continue only if one Release is found if len(torrent_rows) < 1: sickrage.app.log.debug("Data returned from provider does not contain any torrents") return results for torrent_row in torrent_rows: try: title = torrent_row.find('a', {"data-src": True})['data-src'].rsplit('.', 1)[0] download_href = torrent_row.find('img', {"alt": 'Download Torrent'}).findParent()['href'] seeders = int( torrent_row.findAll('a', {'title': 'Click here to view peers details'})[ 0].text.strip()) leechers = int( torrent_row.findAll('a', {'title': 'Click here to view peers details'})[ 1].text.strip()) download_url = self.urls['base_url'] + download_href # FIXME size = -1 if not all([title, download_url]): continue item = {'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers, 'hash': ''} if mode != 'RSS': sickrage.app.log.debug("Found result: {}".format(title)) results.append(item) except Exception: sickrage.app.log.error("Failed parsing provider") return results
def search(self, search_strings, age=0, ep_obj=None): """Start searching for anime using the provided search_strings. Used for backlog and daily.""" results = [] for mode in search_strings: sickrage.app.log.debug('Search mode: {0}'.format(mode)) for search_string in search_strings[mode]: if mode != 'RSS': sickrage.app.log.debug('Search string: {}'.format(search_string)) search_url = (self.urls['rss'], self.urls['api'] + search_string)[mode != 'RSS'] try: response = sickrage.app.wsession.get(search_url).text except Exception: sickrage.app.log.debug('No data returned from provider') continue if not response.text.startswith('<?xml'): sickrage.app.log.info('Expected xml but got something else, is your mirror failing?') continue with bs4_parser(response) as html: entries = html('item') if not entries: sickrage.app.log.info('Returned xml contained no results') continue for item in entries: try: title = item.title.get_text(strip=True) download_url = item.enclosure.get('url').strip() if not (title and download_url): continue # description = item.find('description') size = try_int(item.enclosure.get('length', -1)) item = { 'title': title, 'link': download_url, 'size': size, } results.append(item) except (AttributeError, TypeError, KeyError, ValueError, IndexError): sickrage.app.log.error('Failed parsing provider.') continue return results
def parse(self, data, mode, **kwargs): """ Parse search results from data :param data: response data :param mode: search mode :return: search results """ results = [] with bs4_parser(data) as html: torrent_table = html.find(class_='ttable_headinner') torrent_rows = torrent_table('tr') if torrent_table else [] # Continue only if at least one Release is found if len(torrent_rows) < 2: sickrage.app.log.debug('Data returned from provider does not contain any torrents') return results # Catégorie, Release, Date, DL, Size, C, S, L labels = [label.get_text(strip=True) for label in torrent_rows[0]('th')] # Skip column headers for result in torrent_rows[1:]: try: cells = result('td') if len(cells) < len(labels): continue id = re.search('id=([0-9]+)', cells[labels.index('Nom')].find('a')['href']).group(1) title = cells[labels.index('Nom')].get_text(strip=True) download_url = urljoin(self.urls['download'], '?id={0}&name={1}'.format(id, title)) if not all([title, download_url]): continue seeders = try_int(cells[labels.index('S')].get_text(strip=True)) leechers = try_int(cells[labels.index('L')].get_text(strip=True)) size_index = labels.index('Size') if 'Size' in labels else labels.index('Taille') torrent_size = cells[size_index].get_text() size = convert_size(torrent_size, -1) results += [ {'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers} ] if mode != 'RSS': sickrage.app.log.debug('Found result: {}'.format(title)) except Exception: sickrage.app.log.error('Failed parsing provider') return results
def fetch_popular_shows(self): """Get popular show information from IMDB""" popular_shows = [] try: data = sickrage.app.wsession.get(self.url, headers={'Referer': 'http://akas.imdb.com/'}, params=self.params).text except Exception: return None with bs4_parser(data) as soup: for row in soup.find_all("div", {"class": "lister-item"}): show = {} image_div = row.find("div", {"class": "lister-item-image"}) if image_div: image = image_div.find("img") show['image_url_large'] = self.change_size(image['loadlate'], 3) show['imdb_tt'] = image['data-tconst'] show['image_path'] = posixpath.join('images', 'imdb_popular', os.path.basename(show['image_url_large'])) self.cache_image(show['image_url_large']) content = row.find("div", {"class": "lister-item-content"}) if content: header = row.find("h3", {"class": "lister-item-header"}) if header: a_tag = header.find("a") if a_tag: show['name'] = a_tag.get_text(strip=True) show['imdb_url'] = "http://www.imdb.com" + a_tag["href"] show['year'] = header.find("span", {"class": "lister-item-year"}).contents[0].split(" ")[0][1:5] imdb_rating = row.find("div", {"class": "ratings-imdb-rating"}) show['rating'] = imdb_rating['data-value'] if imdb_rating else None votes = row.find("span", {"name": "nv"}) show['votes'] = votes['data-value'] if votes else None outline = content.find_all("p", {"class": "text-muted"}) if outline and len(outline) >= 2: show['outline'] = outline[1].contents[0].strip("\"") else: show['outline'] = '' popular_shows.append(show) return popular_shows
def parse(self, data, mode, **kwargs): """ Parse search results from data :param data: response data :param mode: search mode :return: search results """ results = [] with bs4_parser(data) as soup: torrent_table = soup.find('table', class_='listing') torrent_rows = torrent_table('tr') if torrent_table else [] # Continue only if one Release is found if len(torrent_rows) < 2: sickrage.app.log.debug("Data returned from provider does not contain any torrents") return results a = 1 if len(torrent_rows[0]('td')) < 2 else 0 for top, bot in zip(torrent_rows[a::2], torrent_rows[a + 1::2]): try: title = download_url = "" desc_top = top.find('td', class_='desc-top') if desc_top: title = desc_top.get_text(strip=True) download_url = desc_top.find('a')['href'] if not all([title, download_url]): continue stats = bot.find('td', class_='stats').get_text(strip=True) sl = re.match(r'S:(?P<seeders>\d+)L:(?P<leechers>\d+)C:(?:\d+)ID:(?:\d+)', stats.replace(' ', '')) seeders = try_int(sl.group('seeders')) leechers = try_int(sl.group('leechers')) desc_bottom = bot.find('td', class_='desc-bot').get_text(strip=True) size = convert_size(desc_bottom.split('|')[1].strip('Size: '), -1) results += [ {'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers} ] if mode != 'RSS': sickrage.app.log.debug("Found result: {}".format(title)) except Exception: sickrage.app.log.error("Failed parsing provider") return results
def parse(self, data, mode): """ Parse search results from data :param data: response data :param mode: search mode :return: search results """ results = [] with bs4_parser(data) as html: torrent_table = html.find('table', attrs={'class': 'koptekst'}) torrent_rows = torrent_table.find_all('tr') if torrent_table else [] # Continue only if one Release is found if len(torrent_rows) < 2: sickrage.app.log.debug("Data returned from provider does not contain any torrents") return results for row in torrent_rows[1:]: try: cells = row.find_all('td') link = cells[1].find('a') download_url = self.urls['download'] % cells[2].find('a')['href'] try: title = link.getText() seeders = int(cells[10].getText()) leechers = int(cells[11].getText()) # FIXME size = -1 except (AttributeError, TypeError): continue if not all([title, download_url]): continue item = {'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers, 'hash': ''} if mode != 'RSS': sickrage.app.log.debug("Found result: {}".format(title)) results.append(item) except Exception: sickrage.app.log.error("Failed parsing provider") return results
def parse(self, data, mode): """ Parse search results from data :param data: response data :param mode: search mode :return: search results """ results = [] with bs4_parser(data) as html: torrent_rows = html.find_all('tr', class_='torrent') if len(torrent_rows) < 1: sickrage.app.log.debug("Data returned from provider does not contain any torrents") return results for result in torrent_rows: try: # skip if torrent has been nuked due to poor quality if result.find('img', alt='Nuked'): continue download_url = urljoin(self.urls['base_url'] + '/', result.find('span', title='Download').parent['href']) title = result.find('a', title='View torrent').get_text(strip=True) if not all([title, download_url]): continue seeders = try_int(result('td', class_="number_column")[1].text, 0) leechers = try_int(result('td', class_="number_column")[2].text, 0) size = -1 if re.match(r'\d+([,.]\d+)?\s*[KkMmGgTt]?[Bb]', result('td', class_="number_column")[0].text): size = convert_size(result('td', class_="number_column")[0].text.strip(), -1) item = {'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers, 'hash': ''} if mode != 'RSS': sickrage.app.log.debug("Found result: {}".format(title)) results.append(item) except Exception: sickrage.app.log.error("Failed parsing provider") return results
def parse(self, data, mode, **kwargs): """ Parse search results from data :param data: response data :param mode: search mode :return: search results """ results = [] try: data = data.split('<div id="information"></div>')[1] except ValueError: sickrage.app.log.error("Could not find main torrent table") return results with bs4_parser(data[data.index('<table'):]) as html: torrents = html.findAll('tr') if not torrents: return results # Skip column headers for result in torrents[1:]: if len(result.contents) < 10: # skip extraneous rows at the end continue try: dl_href = result.find('a', attrs={'href': re.compile(r'download.php.*')})['href'] title = re.search('f=(.*).torrent', dl_href).group(1).replace('+', '.') download_url = self.urls['base_url'] + dl_href seeders = int(result.find('span', attrs={'class': 'seedy'}).find('a').text) leechers = int(result.find('span', attrs={'class': 'leechy'}).find('a').text) size = convert_size(result, -1) if not all([title, download_url]): continue results += [ {'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers} ] if mode != 'RSS': sickrage.app.log.debug("Found result: {}".format(title)) except Exception: sickrage.app.log.error("Failed parsing provider") return results
def parse(self, data, mode): """ Parse search results from data :param data: response data :param mode: search mode :return: search results """ results = [] with bs4_parser(data) as html: torrent_rows = html.find_all('tr') for row in torrent_rows: for torrent in row.find_all('td'): for link in torrent.find_all('a'): try: fileType = ''.join(link.find_previous('i')["class"]) fileType = unicodedata.normalize('NFKD', fileType). \ encode(sickrage.app.sys_encoding, 'ignore') if fileType == "Series": title = link.get_text(strip=True) download_url = self.get_download_url(link.get('href')) if not all([title, download_url]): continue # size size = convert_size(link.findNext('td').text, -1) # Filter unseeded torrent seeders = try_int(link.find_next('img', alt='seeders').parent.text, 0) leechers = try_int(link.find_next('img', alt='leechers').parent.text, 0) if mode != 'RSS': sickrage.app.log.debug("Found result: {}".format(title)) results += [{ 'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers, }] except Exception: sickrage.app.log.error("Failed parsing provider") return results
def parse(self, data, mode, **kwargs): """ Parse search results from data :param data: response data :param mode: search mode :return: search results """ results = [] def process_column_header(td): td_title = '' if td.img: td_title = td.img.get('title', td.get_text(strip=True)) if not td_title: td_title = td.get_text(strip=True) return td_title with bs4_parser(data) as html: torrent_table = html.find('table', id='sortabletable') torrent_rows = torrent_table('tr') if torrent_table else [] # Continue only if at least one Release is found if len(torrent_rows) < 2: sickrage.app.log.debug("Data returned from provider does not contain any torrents") return results labels = [process_column_header(label) for label in torrent_rows[0]('td')] # Skip column headers for result in torrent_rows[1:]: try: tooltip = result.find('div', class_='tooltip-target') if not tooltip: continue title = tooltip.get_text(strip=True) # skip if torrent has been nuked due to poor quality if title.startswith('Nuked.'): continue download_url = result.find('img', title='Click to Download this Torrent in SSL!').parent['href'] if not all([title, download_url]): continue cells = result('td') seeders = try_int(cells[labels.index('Seeders')].get_text(strip=True)) leechers = try_int(cells[labels.index('Leechers')].get_text(strip=True)) torrent_size = cells[labels.index('Size')].get_text(strip=True) size = convert_size(torrent_size, -1) results += [ {'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers} ] if mode != 'RSS': sickrage.app.log.debug("Found result: {}".format(title)) except Exception: sickrage.app.log.error("Failed parsing provider") return results
def search(self, search_params, search_mode='eponly', epcount=0, age=0, epObj=None): results = [] items = {'Season': [], 'Episode': [], 'RSS': []} freeleech = '3' if self.freeleech else '0' if not self.login(): return results for mode in search_params.keys(): sickrage.srCore.srLogger.debug("Search Mode: %s" % mode) for search_string in search_params[mode]: if mode != 'RSS': sickrage.srCore.srLogger.debug("Search string: %s " % search_string) searchURL = self.urls['search'] % (freeleech, search_string) sickrage.srCore.srLogger.debug("Search URL: %s" % searchURL) max_page_number = 0 try: data = sickrage.srCore.srWebSession.get(searchURL, cache=False).text except Exception: sickrage.srCore.srLogger.debug( "No data returned from provider") continue try: with bs4_parser(data) as html: # Check to see if there is more than 1 page of results pager = html.find('div', {'class': 'pager'}) if pager: page_links = pager.find_all('a', href=True) else: page_links = [] if len(page_links) > 0: for lnk in page_links: link_text = lnk.text.strip() if link_text.isdigit(): page_int = int(link_text) if page_int > max_page_number: max_page_number = page_int # limit page number to 15 just in case something goes wrong if max_page_number > 15: max_page_number = 15 # limit RSS search if max_page_number > 3 and mode == 'RSS': max_page_number = 3 except Exception: sickrage.srCore.srLogger.error( "Failed parsing provider. Traceback: %s" % traceback.format_exc()) continue data_response_list = [data] # Freshon starts counting pages from zero, even though it displays numbers from 1 if max_page_number > 1: for i in range(1, max_page_number): time.sleep(1) page_searchURL = searchURL + '&page=' + str(i) try: page_html = sickrage.srCore.srWebSession.get( page_searchURL, cache=False).text except Exception: continue data_response_list.append(page_html) try: for data in data_response_list: with bs4_parser(data) as html: torrent_rows = html.findAll( "tr", {"class": re.compile('torrent_[0-9]*')}) # Continue only if a Release is found if len(torrent_rows) == 0: sickrage.srCore.srLogger.debug( "Data returned from provider does not contain any torrents" ) continue for individual_torrent in torrent_rows: # skip if torrent has been nuked due to poor quality if individual_torrent.find( 'img', alt='Nuked') is not None: continue try: title = individual_torrent.find( 'a', {'class': 'torrent_name_link' })['title'] except Exception: sickrage.srCore.srLogger.warning( "Unable to parse torrent title. Traceback: %s " % traceback.format_exc()) continue try: details_url = individual_torrent.find( 'a', {'class': 'torrent_name_link'})['href'] torrent_id = int((re.match( '.*?([0-9]+)$', details_url).group(1)).strip()) download_url = self.urls['download'] % ( str(torrent_id)) seeders = tryInt( individual_torrent.find( 'td', { 'class': 'table_seeders' }).find('span').text.strip(), 1) leechers = tryInt( individual_torrent.find( 'td', { 'class': 'table_leechers' }).find('a').text.strip(), 0) # FIXME size = -1 except Exception: continue if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != 'RSS': sickrage.srCore.srLogger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})" .format(title, seeders, leechers)) continue item = title, download_url, size, seeders, leechers if mode != 'RSS': sickrage.srCore.srLogger.debug( "Found result: %s " % title) items[mode].append(item) except Exception: sickrage.srCore.srLogger.error( "Failed parsing provider. Traceback: %s" % traceback.format_exc()) # For each search mode sort all the items by seeders if available items[mode].sort(key=lambda tup: tup[3], reverse=True) results += items[mode] return results
def search(self, search_params, search_mode='eponly', epcount=0, age=0, epObj=None): results = [] items = {'Season': [], 'Episode': [], 'RSS': []} if not self.login(): return results for mode in search_params.keys(): sickrage.srCore.srLogger.debug("Search Mode: %s" % mode) for search_string in search_params[mode]: if mode == 'RSS': searchURL = self.urls['index'] % self.categories else: searchURL = self.urls['search'] % (urllib.quote_plus( search_string.encode('utf-8')), self.categories) sickrage.srCore.srLogger.debug("Search string: %s " % search_string) sickrage.srCore.srLogger.debug("Search URL: %s" % searchURL) try: data = sickrage.srCore.srWebSession.get(searchURL, cache=False).text except Exception: sickrage.srCore.srLogger.debug( "No data returned from provider") continue try: with bs4_parser(data) as html: torrent_table = html.find('table', attrs={'id': 'torrenttable'}) torrent_rows = torrent_table.find_all( 'tr') if torrent_table else [] # Continue only if one Release is found if len(torrent_rows) < 2: sickrage.srCore.srLogger.debug( "Data returned from provider does not contain any torrents" ) continue for result in torrent_table.find_all('tr')[1:]: try: link = result.find('td', attrs={ 'class': 'name' }).find('a') url = result.find('td', attrs={ 'class': 'quickdownload' }).find('a') title = link.string download_url = self.urls['download'] % url[ 'href'] seeders = int( result.find('td', attrs={ 'class': 'seeders' }).string) leechers = int( result.find('td', attrs={ 'class': 'leechers' }).string) # FIXME size = -1 except (AttributeError, TypeError): continue if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != 'RSS': sickrage.srCore.srLogger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})" .format(title, seeders, leechers)) continue item = title, download_url, size, seeders, leechers if mode != 'RSS': sickrage.srCore.srLogger.debug( "Found result: %s " % title) items[mode].append(item) except Exception: sickrage.srCore.srLogger.error( "Failed parsing provider. Traceback: {}".format( traceback.format_exc())) # For each search mode sort all the items by seeders if available items[mode].sort(key=lambda tup: tup[3], reverse=True) results += items[mode] return results
def search(self, search_params, search_mode='eponly', epcount=0, age=0, epObj=None): results = [] items = {'Season': [], 'Episode': [], 'RSS': []} if not self._doLogin(): return results for mode in search_params.keys(): sickrage.srCore.srLogger.debug("Search Mode: %s" % mode) for search_string in search_params[mode]: if mode != 'RSS': sickrage.srCore.srLogger.debug("Search string: %s " % search_string) searchURL = self.urls['search'] % (urllib.quote(search_string), self.categories) sickrage.srCore.srLogger.debug("Search URL: %s" % searchURL) try: data = sickrage.srCore.srWebSession.get(searchURL).text except Exception: sickrage.srCore.srLogger.debug( "No data returned from provider") continue try: with bs4_parser(data) as html: torrent_table = html.select("#torrenttable table") torrent_rows = torrent_table[0].select( "tr") if torrent_table else [] # Continue only if one Release is found if len(torrent_rows) < 2: sickrage.srCore.srLogger.debug( "Data returned from provider does not contain any torrents" ) continue # Scenetime apparently uses different number of cells in #torrenttable based # on who you are. This works around that by extracting labels from the first # <tr> and using their index to find the correct download/seeders/leechers td. labels = [ label.get_text() for label in torrent_rows[0].find_all('td') ] for result in torrent_rows[1:]: cells = result.find_all('td') link = cells[labels.index('Name')].find('a') full_id = link['href'].replace( 'details.php?id=', '') torrent_id = full_id.split("&")[0] try: title = link.contents[0].get_text() filename = "%s.torrent" % title.replace( " ", ".") download_url = self.urls['download'] % ( torrent_id, filename) int(cells[labels.index('Seeders')].get_text()) seeders = int( cells[labels.index('Seeders')].get_text()) leechers = int( cells[labels.index('Leechers')].get_text()) # FIXME size = -1 except (AttributeError, TypeError): continue if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != 'RSS': sickrage.srCore.srLogger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})" .format(title, seeders, leechers)) continue item = title, download_url, size, seeders, leechers if mode != 'RSS': sickrage.srCore.srLogger.debug( "Found result: %s " % title) items[mode].append(item) except Exception: sickrage.srCore.srLogger.error( "Failed parsing provider. Traceback: {}".format( traceback.format_exc())) # For each search mode sort all the items by seeders if available items[mode].sort(key=lambda tup: tup[3], reverse=True) results += items[mode] return results
def parse(self, data, mode, **kwargs): """ Parse search results for items. :param data: The raw response from a search :param mode: The current mode used to search, e.g. RSS :return: A list of items found """ results = [] hdtext = [ ' Versione 720p', ' V 720p', ' V 720', ' V HEVC', ' V HEVC', ' V 1080', ' Versione 1080p', ' 720p HEVC', ' Ver 720', ' 720p HEVC', ' 720p' ] with bs4_parser(data) as html: torrent_table = html.find(class_='showrelease_tb') torrent_rows = torrent_table('tr') if torrent_table else [] # Continue only if at least one release is found if len(torrent_rows) < 3: sickrage.app.log.debug( 'Data returned from provider does not contain any torrents' ) return results # Skip column headers for row in torrent_table('tr')[1:]: cells = row('td') if not cells: continue try: title = unidecode(cells[6].text) title = title.replace('·', '').replace(',', '') title = title.replace('by', '-').strip() title = title.strip('-').strip() download_url = cells[1].find('a')['href'] if not all([title, download_url]): continue seeders = try_int(cells[4].text, 1) leechers = try_int(cells[3].text) filename_qt = self._reverse_quality( self._episode_quality(title)) for text in hdtext: title1 = title title = title.replace(text, filename_qt) if title != title1: break if Quality.name_quality(title) == Quality.UNKNOWN: title += filename_qt if self._has_only_subs(title) and not self.subtitle: sickrage.app.log.debug( 'Torrent is only subtitled, skipping: {}'.format( title)) continue if self.engrelease and not self._is_english(title): sickrage.app.log.debug( "Torrent isn't english audio/subtitled, skipping: {} " .format(title)) continue size = -1 results += [{ 'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers }] if mode != 'RSS': sickrage.app.log.debug( "Found result: {}".format(title)) except Exception: sickrage.app.log.error('Failed parsing provider') return results
def parse(self, data, mode, **kwargs): """ Parse search results from data :param data: response data :param mode: search mode :return: search results """ results = [] with bs4_parser(data) as html: torrent_rows = html.findAll('tr') # Continue only if one Release is found if len(torrent_rows) < 2: sickrage.app.log.debug( "Data returned from provider does not contain any torrents" ) return results # Scenetime apparently uses different number of cells in #torrenttable based # on who you are. This works around that by extracting labels from the first # <tr> and using their index to find the correct download/seeders/leechers td. labels = [ label.get_text() for label in torrent_rows[0].find_all('td') ] for result in torrent_rows[1:]: cells = result.find_all('td') link = cells[labels.index('Name')].find('a') full_id = link['href'].replace('details.php?id=', '') torrent_id = full_id.split("&")[0] try: title = link.contents[0].get_text() filename = "%s.torrent" % title.replace(" ", ".") download_url = self.urls['download'] % (torrent_id, filename) int(cells[labels.index('Seeders')].get_text()) seeders = int(cells[labels.index('Seeders')].get_text()) leechers = int(cells[labels.index('Leechers')].get_text()) # FIXME size = -1 if not all([title, download_url]): continue results += [{ 'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers }] if mode != 'RSS': sickrage.app.log.debug( "Found result: {}".format(title)) except Exception: sickrage.app.log.error("Failed parsing provider") return results
def parse(self, data, mode, **kwargs): """ Parse search results from data :param data: response data :param mode: search mode :return: search results """ results = [] with bs4_parser(data) as html: torrent_table = html.find("table", border="1") torrent_rows = torrent_table("tr") if torrent_table else [] # Continue only if at least one Release is found if len(torrent_rows) < 2: sickrage.app.log.debug("Data returned from provider does not contain any torrents") return results # "Type", "Name", Files", "Comm.", "Added", "TTL", "Size", "Snatched", "Seeders", "Leechers" labels = [label.get_text(strip=True) for label in torrent_rows[0]('td')] for result in torrent_rows[1:]: try: cells = result('td') if len(cells) < len(labels): continue link = cells[labels.index("Name")].find("a", href=re.compile(r"download.php\?id="))["href"] download_url = urljoin(self.urls['base_url'], link) title_element = cells[labels.index("Name")].find("a", href=re.compile(r"details.php\?id=")) title = title_element.get("title", "") or title_element.get_text(strip=True) if not all([title, download_url]): continue if self.freeleech: # Free leech torrents are marked with green [F L] in the title (i.e. <font color=green>[F L]</font>) freeleech = cells[labels.index("Name")].find("font", color="green") if not freeleech or freeleech.get_text(strip=True) != "[F\xa0L]": continue seeders = try_int(cells[labels.index("Seeders")].get_text(strip=True)) leechers = try_int(cells[labels.index("Leechers")].get_text(strip=True)) torrent_size = cells[labels.index("Size")].get_text(strip=True) size = convert_size(torrent_size, -1) results += [{ 'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers }] if mode != "RSS": sickrage.app.log.debug("Found result: {}".format(title)) except Exception: sickrage.app.log.error("Failed parsing provider.") return results
def parse(self, data, mode, **kwargs): """ Parse search results from data :param data: response data :param mode: search mode :return: search results """ results = [] # Search result page contains some invalid html that prevents html parser from returning all data. # We cut everything before the table that contains the data we are interested in thus eliminating # the invalid html portions try: index = data.lower().index('<table class="mainblockcontenttt"') except ValueError: sickrage.app.log.debug( "Could not find table of torrents mainblockcontenttt") return results with bs4_parser(data[index:]) as html: torrent_table = html.find('table', class_='mainblockcontenttt') torrent_rows = torrent_table('tr') if torrent_table else [] if not torrent_rows or torrent_rows[2].find('td', class_='lista'): sickrage.app.log.debug( 'Data returned from provider does not contain any torrents' ) return results # Cat., Active, Filename, Dl, Wl, Added, Size, Uploader, S, L, C labels = [ label.a.get_text(strip=True) if label.a else label.get_text( strip=True) for label in torrent_rows[0]('td') ] # Skip column headers for row in torrent_rows[1:]: try: cells = row.findChildren('td')[:len(labels)] if len(cells) < len(labels): continue title = cells[labels.index('Filename')].a title = title.get_text(strip=True) if title else None link = cells[labels.index('Dl')].a link = link.get('href') if link else None download_url = urljoin(self.urls['base_url'], link) if link else None if not all([title, download_url]): continue seeders = try_int( cells[labels.index('S')].get_text(strip=True)) leechers = try_int( cells[labels.index('L')].get_text(strip=True)) torrent_size = cells[labels.index('Size')].get_text() size = convert_size( torrent_size, -1, ['B', 'KIB', 'MIB', 'GIB', 'TIB', 'PIB']) results += [{ 'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers }] if mode != 'RSS': sickrage.app.log.debug( "Found result: {}".format(title)) except Exception: sickrage.app.log.error("Failed parsing provider") return results
def search(self, search_strings, search_mode='eponly', epcount=0, age=0, epObj=None): results = [] items = {'Season': [], 'Episode': [], 'RSS': []} if not self._doLogin(): return results for mode in search_strings.keys(): sickrage.srCore.srLogger.debug("Search Mode: %s" % mode) for search_string in search_strings[mode]: if mode != 'RSS': sickrage.srCore.srLogger.debug("Search string: %s " % search_string) self.search_params['search'] = search_string try: data = sickrage.srCore.srWebSession.get( self.urls['search'], self.search_params).text except Exception: sickrage.srCore.srLogger.debug( "No data returned from provider") continue try: with bs4_parser(data) as html: torrent_table = html.find('table', attrs={'class': 'koptekst'}) torrent_rows = torrent_table.find_all( 'tr') if torrent_table else [] # Continue only if one Release is found if len(torrent_rows) < 2: sickrage.srCore.srLogger.debug( "Data returned from provider does not contain any torrents" ) continue for result in torrent_rows[1:]: cells = result.find_all('td') link = cells[1].find('a') download_url = self.urls['download'] % cells[ 2].find('a')['href'] try: title = link.getText() seeders = int(cells[10].getText()) leechers = int(cells[11].getText()) # FIXME size = -1 except (AttributeError, TypeError): continue if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != 'RSS': sickrage.srCore.srLogger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})" .format(title, seeders, leechers)) continue item = title, download_url, size, seeders, leechers if mode != 'RSS': sickrage.srCore.srLogger.debug( "Found result: %s " % title) items[mode].append(item) except Exception: sickrage.srCore.srLogger.warning( "Failed parsing provider. Traceback: %s" % traceback.format_exc()) # For each search mode sort all the items by seeders if available items[mode].sort(key=lambda tup: tup[3], reverse=True) results += items[mode] return results
def search(self, search_params, search_mode='eponly', epcount=0, age=0, epObj=None): results = [] items = {'Season': [], 'Episode': [], 'RSS': []} # freeleech = '3' if self.freeleech else '0' if not self._doLogin(): return results for mode in search_params.keys(): sickrage.srCore.srLogger.debug("Search Mode: %s" % mode) for search_string in search_params[mode]: if mode != 'RSS': sickrage.srCore.srLogger.debug("Search string: %s " % search_string) searchURL = self.urls['search'] % (search_string.replace( '(', '').replace(')', '')) sickrage.srCore.srLogger.debug("Search URL: %s" % searchURL) # returns top 15 results by default, expandable in user profile to 100 try: data = sickrage.srCore.srWebSession.get(searchURL).text except Exception: sickrage.srCore.srLogger.debug( "No data returned from provider") continue try: with bs4_parser(data) as html: torrent_table = html.find( 'table', attrs={'class': 'torrent_table'}) torrent_rows = torrent_table.findChildren( 'tr') if torrent_table else [] # Continue only if one Release is found if len(torrent_rows) < 2: sickrage.srCore.srLogger.debug( "Data returned from provider does not contain any torrents" ) continue # skip colheader for result in torrent_rows[1:]: cells = result.findChildren('td') link = cells[1].find('span', attrs={ 'title': 'Download' }).parent title_anchor = cells[1].find('a', attrs={'dir': 'ltr'}) # skip if torrent has been nuked due to poor quality if cells[1].find('img', alt='Nuked') is not None: continue torrent_id_long = link['href'].replace( 'torrents.php?action=download&id=', '') try: if title_anchor.has_key('title'): title = cells[1].find( 'a', { 'title': 'View torrent' }).contents[0].strip() else: title = title_anchor.contents[0] download_url = self.urls[ 'download'] % torrent_id_long seeders = cells[6].contents[0] leechers = cells[7].contents[0] size = -1 if re.match( r'\d+([,\.]\d+)?\s*[KkMmGgTt]?[Bb]', cells[4].contents[0]): size = convert_size(cells[4].text.strip()) except (AttributeError, TypeError): continue if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != 'RSS': sickrage.srCore.srLogger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})" .format(title, seeders, leechers)) continue item = title, download_url, size, seeders, leechers if mode != 'RSS': sickrage.srCore.srLogger.debug( "Found result: %s " % title) items[mode].append(item) except Exception as e: sickrage.srCore.srLogger.error( "Failed parsing provider. Traceback: %s" % traceback.format_exc()) # For each search mode sort all the items by seeders if available items[mode].sort(key=lambda tup: tup[3], reverse=True) results += items[mode] return results
def parse(self, data, mode, **kwargs): """ Parse search results from data :param data: response data :param mode: search mode :return: search results """ results = [] with bs4_parser(data) as html: torrent_tables = html.find_all('table', class_='release-table') torrent_rows = [] for torrent_table in torrent_tables: curr_torrent_rows = torrent_table( 'tr') if torrent_table else [] torrent_rows.extend(curr_torrent_rows) # Continue only if one Release is found if len(torrent_rows) < 1: sickrage.app.log.debug( "Data returned from provider does not contain any torrents" ) return results for torrent_row in torrent_rows: try: label = torrent_row.find('td', class_='dl-label') title = label.get_text(strip=True) size = -1 seeders = 1 leechers = 1 link = torrent_row.find('td', class_='hs-torrent-link') download_url = link.find( 'a')['href'] if link and link.find('a') else None if not download_url: # fallback to magnet link link = torrent_row.find('td', class_='hs-magnet-link') download_url = link.find( 'a')['href'] if link and link.find('a') else None if not all([title, download_url]): continue results += [{ 'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers }] if mode != 'RSS': sickrage.app.log.debug( "Found result: {}".format(title)) except Exception: sickrage.app.log.error("Failed parsing provider") return results
def search(self, search_strings, search_mode='eponly', epcount=0, age=0, epObj=None): results = [] search_params = { 'do': 'search', 'keywords': '', 'search_type': 't_name', 'category': 0, 'include_dead_torrents': 'no', } items = {'Season': [], 'Episode': [], 'RSS': []} if not self.login(): return results for mode in search_strings.keys(): sickrage.srCore.srLogger.debug("Search Mode: %s" % mode) for search_string in search_strings[mode]: if mode != 'RSS': sickrage.srCore.srLogger.debug("Search string: %s " % search_string) search_params['keywords'] = search_string.strip() try: data = sickrage.srCore.srWebSession.get( self.urls['search'], params=search_params, cache=False).text except Exception: sickrage.srCore.srLogger.debug( "No data returned from provider") continue with bs4_parser(data) as html: torrent_table = html.find(id='listtorrents').find_all('tr') for torrent in torrent_table: try: title = torrent.find(attrs={ 'class': 'tooltip-content' }).text.strip() download_url = torrent.find( title="Click to Download this Torrent!" ).parent['href'].strip() seeders = int( torrent.find(title='Seeders').text.strip()) leechers = int( torrent.find(title='Leechers').text.strip()) if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != 'RSS': sickrage.srCore.srLogger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})" .format(title, seeders, leechers)) continue # Chop off tracker/channel prefix or we cant parse the result! show_name_first_word = re.search( r'^[^ .]+', search_params['keywords']).group() if not title.startswith(show_name_first_word): title = re.match( r'(.*)(' + show_name_first_word + '.*)', title).group(2) # Change title from Series to Season, or we can't parse if 'Series' in search_params['keywords']: title = re.sub(r'(?i)series', 'Season', title) # Strip year from the end or we can't parse it! title = re.sub(r'[\. ]?\(\d{4}\)', '', title) # FIXME size = -1 item = title, download_url, size, seeders, leechers if mode != 'RSS': sickrage.srCore.srLogger.debug( "Found result: %s " % title) items[mode].append(item) except: continue # For each search mode sort all the items by seeders if available items[mode].sort(key=lambda tup: tup[3], reverse=True) results += items[mode] return results
def search(self, search_strings, search_mode='eponly', epcount=0, age=0, epObj=None): results = [] search_params = { "afficher": 1, "c118": 1, "c129": 1, "c119": 1, "c120": 1, "c121": 1, "c126": 1, "c137": 1, "c138": 1, "c146": 1, "c122": 1, "c110": 1, "c109": 1, "c135": 1, "c148": 1, "c153": 1, "c149": 1, "c150": 1, "c154": 1, "c155": 1, "c156": 1, "c114": 1, "visible": 1, "freeleech": 0, "nuke": 1, "3D": 0, "sort": "size", "order": "desc" } items = {'Season': [], 'Episode': [], 'RSS': []} # check for auth if not self.login(): return results for mode in search_strings.keys(): sickrage.srCore.srLogger.debug("Search Mode: %s" % mode) for search_string in search_strings[mode]: if mode != 'RSS': sickrage.srCore.srLogger.debug("Search string: %s " % search_string) search_params['recherche'] = search_string try: data = sickrage.srCore.srWebSession.get( self.urls['search'], params=search_params, cache=False).text except Exception: sickrage.srCore.srLogger.debug( "No data returned from provider") continue try: with bs4_parser(data) as html: result_table = html.find('table', {'id': 'tablealign3bis'}) if not result_table: sickrage.srCore.srLogger.debug( "Data returned from provider does not contain any torrents" ) continue if result_table: rows = result_table.findAll( "tr", {"class": "ligntorrent"}) for row in rows: link = row.findAll('td')[1].find( "a", href=re.compile("fiche_film")) if link: try: title = link.text download_url = self.urls['base_url'] + "/" + \ row.find("a", href=re.compile(r"download\.php"))['href'] except (AttributeError, TypeError): continue try: detailseedleech = link['mtcontent'] seeders = int( detailseedleech.split( "<font color='#00b72e'>") [1].split("</font>")[0]) leechers = int( detailseedleech.split( "<font color='red'>")[1].split( "</font>")[0]) # FIXME size = -1 except Exception: sickrage.srCore.srLogger.debug( "Unable to parse torrent id & seeders & leechers. Traceback: %s " % traceback.format_exc()) continue if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != 'RSS': sickrage.srCore.srLogger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})" .format( title, seeders, leechers)) continue item = title, download_url, size, seeders, leechers if mode != 'RSS': sickrage.srCore.srLogger.debug( "Found result: %s " % title) items[mode].append(item) except Exception as e: sickrage.srCore.srLogger.error( "Failed parsing provider. Traceback: %s" % traceback.format_exc()) # For each search mode sort all the items by seeders if available items[mode].sort(key=lambda tup: tup[3], reverse=True) results += items[mode] return results
def search(self, search_params, search_mode='eponly', epcount=0, age=0, epObj=None): results = [] items = {'Season': [], 'Episode': [], 'RSS': []} if not self.login(): return results for mode in search_params.keys(): sickrage.srCore.srLogger.debug("Search Mode: %s" % mode) for search_string in search_params[mode]: if mode != 'RSS': sickrage.srCore.srLogger.debug("Search string: %s " % search_string) searchURL = self.urls['search'] % (self.categories, search_string) sickrage.srCore.srLogger.debug("Search URL: %s" % searchURL) # Set cookies from response # Returns top 30 results by default, expandable in user profile try: data = sickrage.srCore.srWebSession.get( searchURL, cookies=self.cookies, cache=False).text except Exception: sickrage.srCore.srLogger.debug( "No data returned from provider") continue try: with bs4_parser(data) as html: torrent_table = html.find("div", id="torrentBrowse") torrent_rows = torrent_table.findChildren( "tr") if torrent_table else [] # Continue only if at least one release is found if len(torrent_rows) < 1: sickrage.srCore.srLogger.debug( "Data returned from provider does not contain any torrents" ) continue for result in torrent_rows[1:]: cells = result.findChildren("td") title = cells[1].find("a").find_next("a") link = cells[3].find("a") shares = cells[8].get_text().split("/", 1) torrent_size = cells[7].get_text().split("/", 1)[0] try: if title.has_key('title'): title = title['title'] else: title = cells[1].find("a")['title'] download_url = self.urls['download'] % ( link['href']) seeders = int(shares[0]) leechers = int(shares[1]) size = -1 if re.match( r"\d+([,\.]\d+)?\s*[KkMmGgTt]?[Bb]", torrent_size): size = convert_size(torrent_size.rstrip()) except (AttributeError, TypeError): continue if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != 'RSS': sickrage.srCore.srLogger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})" .format(title, seeders, leechers)) continue item = title, download_url, size, seeders, leechers if mode != 'RSS': sickrage.srCore.srLogger.debug( "Found result: %s " % title) items[mode].append(item) except Exception as e: sickrage.srCore.srLogger.error( "Failed parsing provider. Traceback: %s" % traceback.format_exc()) # For each search mode sort all the items by seeders if available items[mode].sort(key=lambda tup: tup[3], reverse=True) results += items[mode] return results
def parse(self, data, mode): """ Parse search results from data :param data: response data :param mode: search mode :return: search results """ results = [] with bs4_parser(data) as html: torrent_rows = [] down_elems = html.findAll("img", {"alt": "Download Torrent"}) for down_elem in down_elems: if down_elem: torr_row = down_elem.findParent('tr') if torr_row: torrent_rows.append(torr_row) # Continue only if one Release is found if len(torrent_rows) < 1: sickrage.app.log.debug( "Data returned from provider does not contain any torrents" ) return results for torrent_row in torrent_rows: try: title = torrent_row.find( 'a', {"data-src": True})['data-src'].rsplit('.', 1)[0] download_href = torrent_row.find('img', { "alt": 'Download Torrent' }).findParent()['href'] seeders = int( torrent_row.findAll( 'a', {'title': 'Click here to view peers details' })[0].text.strip()) leechers = int( torrent_row.findAll( 'a', {'title': 'Click here to view peers details' })[1].text.strip()) download_url = self.urls['base_url'] + download_href # FIXME size = -1 if not all([title, download_url]): continue results += [{ 'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers }] if mode != 'RSS': sickrage.app.log.debug( "Found result: {}".format(title)) except Exception: sickrage.app.log.error("Failed parsing provider") return results
def parse(self, data, mode, **kwargs): """ Parse search results from data :param data: response data :param mode: search mode :return: search results """ results = [] with bs4_parser(data) as soup: torrent_table = soup.find('table', class_='listing') torrent_rows = torrent_table('tr') if torrent_table else [] # Continue only if one Release is found if len(torrent_rows) < 2: sickrage.app.log.debug( "Data returned from provider does not contain any torrents" ) return results a = 1 if len(torrent_rows[0]('td')) < 2 else 0 for top, bot in zip(torrent_rows[a::2], torrent_rows[a + 1::2]): try: title = download_url = "" desc_top = top.find('td', class_='desc-top') if desc_top: title = desc_top.get_text(strip=True) download_url = desc_top.find('a')['href'] if not all([title, download_url]): continue stats = bot.find('td', class_='stats').get_text(strip=True) sl = re.match( r'S:(?P<seeders>\d+)L:(?P<leechers>\d+)C:(?:\d+)ID:(?:\d+)', stats.replace(' ', '')) seeders = try_int(sl.group('seeders')) leechers = try_int(sl.group('leechers')) desc_bottom = bot.find( 'td', class_='desc-bot').get_text(strip=True) size = convert_size( desc_bottom.split('|')[1].strip('Size: '), -1) results += [{ 'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers }] if mode != 'RSS': sickrage.app.log.debug( "Found result: {}".format(title)) except Exception: sickrage.app.log.error("Failed parsing provider") return results
def search(self, search_strings, search_mode='eponly', epcount=0, age=0, epObj=None): results = [] items = {'Season': [], 'Episode': [], 'RSS': []} # check for auth if not self._doLogin(): return results for mode in search_strings.keys(): sickrage.srCore.srLogger.debug("Search Mode: %s" % mode) for search_string in search_strings[mode]: if mode != 'RSS': sickrage.srCore.srLogger.debug("Search string: %s " % search_string) self.search_params['search'] = search_string try: data = sickrage.srCore.srWebSession.get( self.urls['search'], params=self.search_params).text except Exception: sickrage.srCore.srLogger.debug( "No data returned from provider") continue try: with bs4_parser(data) as html: result_linkz = html.findAll( 'a', href=re.compile("torrents-details")) if not result_linkz: sickrage.srCore.srLogger.debug( "Data returned from provider do not contains any torrent" ) continue if result_linkz: for link in result_linkz: title = link.text download_url = self.urls[ 'base_url'] + "/" + link['href'] download_url = download_url.replace( "torrents-details", "download") # FIXME size = -1 seeders = 1 leechers = 0 if not title or not download_url: continue # Filter unseeded torrent # if seeders < self.minseed or leechers < self.minleech: # if mode != 'RSS': # LOGGER.debug(u"Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format(title, seeders, leechers)) # continue item = title, download_url, size, seeders, leechers if mode != 'RSS': sickrage.srCore.srLogger.debug( "Found result: %s " % title) items[mode].append(item) except Exception as e: sickrage.srCore.srLogger.error( "Failed parsing provider. Traceback: %s" % traceback.format_exc()) # For each search mode sort all the items by seeders if available items[mode].sort(key=lambda tup: tup[3], reverse=True) results += items[mode] return results
def search(self, search_string, search_mode='eponly', epcount=0, age=0, epObj=None): # FIXME ADD MODE if self.show and not self.show.is_anime: return [] sickrage.srCore.srLogger.debug("Search string: %s " % search_string) params = { "terms": search_string.encode('utf-8'), "type": 1, # get anime types } searchURL = self.urls['base_url'] + '/search.php?' + urllib.urlencode( params) sickrage.srCore.srLogger.debug("Search URL: %s" % searchURL) try: data = sickrage.srCore.srWebSession.get(searchURL).text except Exception: sickrage.srCore.srLogger.debug("No data returned from provider") return [] results = [] try: with bs4_parser(data) as html: torrent_table = html.find('table', attrs={'class': 'listing'}) torrent_rows = torrent_table.find_all( 'tr') if torrent_table else [] if torrent_rows: if torrent_rows[0].find('td', attrs={'class': 'centertext'}): a = 1 else: a = 0 for top, bottom in zip(torrent_rows[a::2], torrent_rows[a::2]): title = top.find('td', attrs={ 'class': 'desc-top' }).text title.lstrip() download_url = top.find('td', attrs={ 'class': 'desc-top' }).find('a')['href'] # FIXME size = -1 seeders = 1 leechers = 0 if not all([title, download_url]): continue # Filter unseeded torrent # if seeders < self.minseed or leechers < self.minleech: # if mode != 'RSS': # LOGGER.debug(u"Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format(title, seeders, leechers)) # continue item = title, download_url, size, seeders, leechers results.append(item) except Exception as e: sickrage.srCore.srLogger.error( "Failed parsing provider. Traceback: %s" % traceback.format_exc()) # FIXME SORTING return results
def parse(self, data, mode, **kwargs): """ Parse search results from data :param data: response data :param mode: search mode :return: search results """ results = [] with bs4_parser(data) as html: torrent_rows = html.find_all("div", class_="torrentrow") # Continue only if at least one Release is found if not torrent_rows: sickrage.app.log.debug( "Data returned from provider does not contain any torrents" ) return results # "Type", "Name", "Download", "Files", "Comments", "Added", "Size", "Snatched", "Seeders", "Leechers", "Upped by" labels = [] columns = html.find_all("div", class_="colhead") for index, column in enumerate(columns): lbl = column.get_text(strip=True) if lbl: labels.append(str(lbl)) else: lbl = column.find("img") if lbl: if lbl.has_attr("alt"): lbl = lbl['alt'] labels.append(str(lbl)) else: if index == 3: lbl = "Download" else: lbl = str(index) labels.append(lbl) # Skip column headers for result in torrent_rows: try: cells = result.find_all("div", class_="torrenttable") if len(cells) < len(labels): continue title = cells[labels.index("Name")].find("a").find( "b").get_text(strip=True) download_url = urljoin( self.urls['base_url'], cells[labels.index("Download")].find("a")["href"]) if not all([title, download_url]): continue seeders = try_int( cells[labels.index("Seeders")].find("span").get_text( strip=True)) leechers = try_int( cells[labels.index("Leechers")].find("span").get_text( strip=True)) torrent_size = cells[labels.index("Size")].find( "span").get_text(strip=True) size = convert_size(torrent_size, -1) results += [{ 'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers }] if mode != "RSS": sickrage.app.log.debug( "Found result: {}".format(title)) except Exception: sickrage.app.log.error("Failed parsing provider") return results
def search(self, search_params, search_mode='eponly', epcount=0, age=0, epObj=None): results = [] items = {'Season': [], 'Episode': [], 'RSS': []} self.categories = "cat=" + str(self.cat) if not self.login(): return results for mode in search_params.keys(): sickrage.srCore.srLogger.debug("Search Mode: %s" % mode) for search_string in search_params[mode]: if mode == 'RSS': self.page = 2 last_page = 0 y = int(self.page) if search_string == '': continue search_string = str(search_string).replace('.', ' ') for x in range(0, y): z = x * 20 if last_page: break if mode != 'RSS': searchURL = (self.urls['search_page'] + '&filter=%s' ) % (z, self.categories, search_string) else: searchURL = self.urls['search_page'] % ( z, self.categories) if mode != 'RSS': sickrage.srCore.srLogger.debug("Search string: %s " % search_string) sickrage.srCore.srLogger.debug("Search URL: %s" % searchURL) try: data = sickrage.srCore.srWebSession.get( searchURL, cache=False).text except Exception: sickrage.srCore.srLogger.debug( "No data returned from provider") continue try: with bs4_parser(data) as html: torrent_table = html.find( 'table', attrs={'class': 'copyright'}) torrent_rows = torrent_table.find_all( 'tr') if torrent_table else [] # Continue only if one Release is found if len(torrent_rows) < 3: sickrage.srCore.srLogger.debug( "Data returned from provider does not contain any torrents" ) last_page = 1 continue if len(torrent_rows) < 42: last_page = 1 for result in torrent_table.find_all('tr')[2:]: try: link = result.find('td').find('a') title = link.string download_url = self.urls[ 'download'] % result.find_all( 'td')[8].find('a')['href'][-8:] leechers = result.find_all( 'td')[3].find_all('td')[1].text leechers = int(leechers.strip('[]')) seeders = result.find_all( 'td')[3].find_all('td')[2].text seeders = int(seeders.strip('[]')) # FIXME size = -1 except (AttributeError, TypeError): continue filename_qt = self._reverseQuality( self._episodeQuality(result)) for text in self.hdtext: title1 = title title = title.replace(text, filename_qt) if title != title1: break if Quality.nameQuality( title) == Quality.UNKNOWN: title += filename_qt if not self._is_italian( result) and not self.subtitle: sickrage.srCore.srLogger.debug( "Torrent is subtitled, skipping: %s " % title) continue if self.engrelease and not self._is_english( result): sickrage.srCore.srLogger.debug( "Torrent isnt english audio/subtitled , skipping: %s " % title) continue search_show = re.split(r'([Ss][\d{1,2}]+)', search_string)[0] show_title = search_show rindex = re.search(r'([Ss][\d{1,2}]+)', title) if rindex: show_title = title[:rindex.start()] ep_params = title[rindex.start():] if show_title.lower() != search_show.lower() \ and search_show.lower() in show_title.lower() and ep_params: title = search_show + ep_params if not all([title, download_url]): continue if self._is_season_pack(title): title = re.sub(r'([Ee][\d{1,2}\-?]+)', '', title) # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != 'RSS': sickrage.srCore.srLogger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: %s (S:%s L:%s)" % (title, seeders, leechers)) continue item = title, download_url, size, seeders, leechers if mode != 'RSS': sickrage.srCore.srLogger.debug( "Found result: %s " % title) items[mode].append(item) except Exception: sickrage.srCore.srLogger.error( "Failed parsing provider. Traceback: %s" % traceback.format_exc()) # For each search mode sort all the items by seeders if available if available items[mode].sort(key=lambda tup: tup[3], reverse=True) results += items[mode] return results
def parse(self, data, mode, **kwargs): """ Parse search results from data :param data: response data :param mode: search mode :return: search results """ results = [] with bs4_parser(data) as html: # Continue only if one Release is found empty = html.find('h2', text="No .torrents fit this filter criteria") if empty: sickrage.app.log.debug( "Data returned from provider does not contain any torrents" ) return results torrent_table = html.find( 'table', attrs={'style': 'border: none; width: 100%;'}) if not torrent_table: sickrage.app.log.debug("Could not find table of torrents") return results torrent_rows = torrent_table.find_all('tr', attrs={'class': 'browse'}) for result in torrent_rows: cells = result.find_all('td') size = None link = cells[1].find( 'a', attrs={'style': 'font-size: 1.25em; font-weight: bold;'}) torrent_id = link['href'].replace('details.php?id=', '') try: if 'title' in link: title = link['title'] else: title = link.contents[0] download_url = self.urls['download'] % (torrent_id, link.contents[0]) seeders = int(cells[9].contents[0]) leechers = int(cells[10].contents[0]) # Need size for failed downloads handling if size is None: if re.match(r'[0-9]+,?\.?[0-9]*[KkMmGg]+[Bb]+', cells[7].text): size = convert_size(cells[7].text, -1) if not all([title, download_url]): continue results += [{ 'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers }] if mode != 'RSS': sickrage.app.log.debug( "Found result: {}".format(title)) except Exception: sickrage.app.log.error("Failed parsing provider.") return results
def search(self, search_strings, search_mode='eponly', epcount=0, age=0, epObj=None): results = [] items = {'Season': [], 'Episode': [], 'RSS': []} if not self.login(): return results for mode in search_strings.keys(): sickrage.srCore.srLogger.debug("Search Mode: %s" % mode) for search_string in search_strings[mode]: if mode != 'RSS': searchURL = self.urls['search'] % (urllib.quote_plus(search_string.replace('.', ' ')),) else: searchURL = self.urls['search'] % '' sickrage.srCore.srLogger.debug("Search URL: %s" % searchURL) if mode != 'RSS': sickrage.srCore.srLogger.debug("Search string: %s" % search_string) try: data = sickrage.srCore.srWebSession.get(searchURL, cache=False).text except Exception: sickrage.srCore.srLogger.debug("No data returned from provider") continue # Search result page contains some invalid html that prevents html parser from returning all data. # We cut everything before the table that contains the data we are interested in thus eliminating # the invalid html portions try: data = data.split('<div id="information"></div>')[1] index = data.index('<table') except ValueError: sickrage.srCore.srLogger.error("Could not find main torrent table") continue with bs4_parser(data[index:]) as html: if not html: sickrage.srCore.srLogger.debug("No html data parsed from provider") continue torrents = html.findAll('tr') if not torrents: continue # Skip column headers for result in torrents[1:]: if len(result.contents) < 10: # skip extraneous rows at the end continue try: dl_href = result.find('a', attrs={'href': re.compile(r'download.php.*')})['href'] title = re.search('f=(.*).torrent', dl_href).group(1).replace('+', '.') download_url = self.urls['base_url'] + dl_href seeders = int(result.find('span', attrs={'class': 'seedy'}).find('a').text) leechers = int(result.find('span', attrs={'class': 'leechy'}).find('a').text) size = convert_size(result) if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != 'RSS': sickrage.srCore.srLogger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format( title, seeders, leechers)) continue item = title, download_url, size, seeders, leechers if mode != 'RSS': sickrage.srCore.srLogger.debug("Found result: %s " % title) items[mode].append(item) except (AttributeError, TypeError, KeyError, ValueError): continue # For each search mode sort all the items by seeders if available items[mode].sort(key=lambda tup: tup[3], reverse=True) results += items[mode] return results
def search(self, search_params, search_mode='eponly', epcount=0, age=0, epObj=None): size = -1 seeders = 1 leechers = 0 results = [] items = {'Season': [], 'Episode': [], 'RSS': []} for mode in search_params.keys(): sickrage.srCore.srLogger.debug("Search Mode: %s" % mode) for search_string in search_params[mode]: if mode != 'RSS': sickrage.srCore.srLogger.debug("Search string: %s " % search_string) searchURL = self.urls[ 'base_url'] + '/recherche/' + search_string.replace( '.', '-') + '.html' sickrage.srCore.srLogger.debug("Search URL: %s" % searchURL) try: data = sickrage.srCore.srWebSession.get(searchURL).text except Exception: sickrage.srCore.srLogger.debug( "No data returned from provider") continue try: with bs4_parser(data) as html: lin = erlin = 0 resultdiv = [] while erlin == 0: try: classlin = 'ligne' + str(lin) resultlin = html.findAll( attrs={'class': [classlin]}) if resultlin: for ele in resultlin: resultdiv.append(ele) lin += 1 else: erlin = 1 except Exception: erlin = 1 for row in resultdiv: try: link = row.find("a", title=True) title = link.text.lower().strip() pageURL = link['href'] # downloadTorrentLink = torrentSoup.find("a", title.startswith('Cliquer')) tmp = pageURL.split('/')[-1].replace( '.html', '.torrent') downloadTorrentLink = (self.urls['download'] % tmp) if downloadTorrentLink: download_url = downloadTorrentLink size = -1 seeders = 1 leechers = 0 except (AttributeError, TypeError): continue if not all([title, download_url]): continue item = title, download_url, size, seeders, leechers if mode != 'RSS': sickrage.srCore.srLogger.debug( "Found result: %s " % title) items[mode].append(item) except Exception as e: sickrage.srCore.srLogger.error( "Failed parsing provider. Traceback: %s" % traceback.format_exc()) # For each search mode sort all the items by seeders if available items[mode].sort(key=lambda tup: tup[3], reverse=True) results += items[mode] return results
def parse(self, data, mode, **kwargs): """ Parse search results from data :param data: response data :param mode: search mode :return: search results """ results = [] try: data = data.split('<div id="information"></div>')[1] except ValueError: sickrage.app.log.error("Could not find main torrent table") return results with bs4_parser(data[data.index('<table'):]) as html: torrents = html.findAll('tr') if not torrents: return results # Skip column headers for result in torrents[1:]: if len(result.contents) < 10: # skip extraneous rows at the end continue try: dl_href = result.find( 'a', attrs={'href': re.compile(r'download.php.*')})['href'] title = re.search('f=(.*).torrent', dl_href).group(1).replace('+', '.') download_url = self.urls['base_url'] + dl_href seeders = int( result.find('span', attrs={ 'class': 'seedy' }).find('a').text) leechers = int( result.find('span', attrs={ 'class': 'leechy' }).find('a').text) size = convert_size(result, -1) if not all([title, download_url]): continue results += [{ 'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers }] if mode != 'RSS': sickrage.app.log.debug( "Found result: {}".format(title)) except Exception: sickrage.app.log.error("Failed parsing provider") return results
def search(self, search_strings, search_mode='eponly', epcount=0, age=0, epObj=None): results = [] items = {'Season': [], 'Episode': [], 'RSS': []} for mode in search_strings: for search_string in search_strings[mode]: search_url = self.urls[ 'verified'] if self.confirmed else self.urls['feed'] if mode != 'RSS': search_url += '?q=' + quote_plus(search_string) sickrage.srCore.srLogger.info(search_url) try: data = sickrage.srCore.srWebSession.get(search_url).text except Exception: sickrage.srCore.srLogger.info( 'Seems to be down right now!') continue if not data.startswith('<?xml'): sickrage.srCore.srLogger.info( 'Expected xml but got something else, is your mirror failing?' ) continue with bs4_parser(data) as html: if not html: sickrage.srCore.srLogger.debug( "No html data parsed from provider") continue for item in html('item'): if item.category and 'tv' not in item.category.get_text( strip=True): continue title = item.title.text.rsplit(' ', 1)[0].replace(' ', '.') t_hash = item.guid.text.rsplit('/', 1)[-1] if not all([title, t_hash]): continue download_url = "magnet:?xt=urn:btih:" + t_hash + "&dn=" + title torrent_size, seeders, leechers = self._split_description( item.find('description').text) size = convert_size(torrent_size) or -1 # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != 'RSS': sickrage.srCore.srLogger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {} (S:{} L:{})" .format(title, seeders, leechers)) continue items[mode].append( (title, download_url, size, seeders, leechers)) # For each search mode sort all the items by seeders if available items[mode].sort(key=lambda tup: tup[3], reverse=True) results += items[mode] return results
def parse(self, data, mode, **kwargs): """ Parse search results from data :param data: response data :param mode: search mode :return: search results """ results = [] def process_column_header(td): result = '' if td.a and td.a.img: result = td.a.img.get('title', td.a.get_text(strip=True)) if not result: result = td.get_text(strip=True) return result with bs4_parser(data) as html: torrent_table = html.find('table', attrs={'id': 'torrent_table'}) torrent_rows = torrent_table('tr') if torrent_table else [] # Continue only if one Release is found if len(torrent_rows) < 2: sickrage.app.log.debug( "Data returned from provider does not contain any torrents" ) return results # '', '', 'Name /Year', 'Files', 'Time', 'Size', 'Snatches', 'Seeders', 'Leechers' labels = [ process_column_header(label) for label in torrent_rows[0]('td') ] # Skip column headers for row in torrent_rows[1:]: try: cells = row('td') if len(cells) < len(labels): continue title = cells[labels.index('Name /Year')].find( 'a', dir='ltr').get_text(strip=True) download = cells[labels.index('Name /Year')].find( 'a', title='Download')['href'] download_url = urljoin(self.urls['base_url'], download) if not all([title, download_url]): continue seeders = try_int( cells[labels.index('Seeders')].get_text(strip=True)) leechers = try_int( cells[labels.index('Leechers')].get_text(strip=True)) torrent_size = cells[labels.index('Size')].get_text( strip=True) size = convert_size(torrent_size, -1) results += [{ 'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers }] if mode != 'RSS': sickrage.app.log.debug( 'Found result: {}'.format(title)) except Exception: sickrage.app.log.error('Failed parsing provider') return results
def search(self, search_strings, search_mode='eponly', epcount=0, age=0, epObj=None): results = [] items = {'Season': [], 'Episode': [], 'RSS': []} if not self._doLogin(): return results for mode in search_strings.keys(): sickrage.srCore.srLogger.debug("Search Mode: %s" % mode) for search_string in search_strings[mode]: if mode != 'RSS': searchURL = self.urls['search'] % ( urllib.quote_plus(search_string), self.categories) else: searchURL = self.urls['rss'] % self.categories sickrage.srCore.srLogger.debug("Search URL: %s" % searchURL) if mode != 'RSS': sickrage.srCore.srLogger.debug("Search string: %s" % search_string) try: data = sickrage.srCore.srWebSession.get(searchURL).text except Exception: sickrage.srCore.srLogger.debug( "No data returned from provider") continue # Search result page contains some invalid html that prevents html parser from returning all data. # We cut everything before the table that contains the data we are interested in thus eliminating # the invalid html portions try: index = data.lower().ind '<table class="mainblockcontenttt"' except ValueError: sickrage.srCore.srLogger.error( "Could not find table of torrents mainblockcontenttt") continue data = urllib.unquote( data[index:].encode('utf-8')).decode('utf-8').replace( '\t', '') with bs4_parser(data) as html: if not html: sickrage.srCore.srLogger.debug( "No html data parsed from provider") continue empty = html.find('No torrents here') if empty: sickrage.srCore.srLogger.debug( "Data returned from provider does not contain any torrents" ) continue tables = html.find('table', attrs={'class': 'mainblockcontenttt'}) if not tables: sickrage.srCore.srLogger.error( "Could not find table of torrents mainblockcontenttt" ) continue torrents = tables.findChildren('tr') if not torrents: continue # Skip column headers for result in torrents[1:]: try: cells = result.findChildren( 'td', attrs={ 'class': re.compile( r'(green|yellow|red|mainblockcontent)') }) if not cells: continue title = download_url = seeders = leechers = size = None for cell in cells: try: if None is title and cell.get( 'title') and cell.get( 'title') in 'Download': title = re.search( 'f=(.*).torrent', cell.a['href']).group(1).replace( '+', '.') title = title.decode('utf-8') download_url = self.urls[ 'home'] % cell.a['href'] continue if None is seeders and cell.get( 'class')[0] and cell.get('class')[ 0] in 'green' 'yellow' 'red': seeders = int(cell.text) if not seeders: seeders = 1 continue elif None is leechers and cell.get( 'class')[0] and cell.get('class')[ 0] in 'green' 'yellow' 'red': leechers = int(cell.text) if not leechers: leechers = 0 continue # Need size for failed downloads handling if size is None: if re.match( r'[0-9]+,?\.?[0-9]* [KkMmGg]+[Bb]+', cell.text): size = convert_size(cell.text) if not size: size = -1 except Exception: sickrage.srCore.srLogger.error( "Failed parsing provider. Traceback: %s" % traceback.format_exc()) if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode != 'RSS': sickrage.srCore.srLogger.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})" .format(title, seeders, leechers)) continue item = title, download_url, size, seeders, leechers if mode != 'RSS': sickrage.srCore.srLogger.debug( "Found result: %s " % title) items[mode].append(item) except (AttributeError, TypeError, KeyError, ValueError): continue # For each search mode sort all the items by seeders if available items[mode].sort(key=lambda tup: tup[3], reverse=True) results += items[mode] return results
def parse(self, data, mode, **kwargs): """ Parse search results from data :param data: response data :param mode: search mode :return: search results """ results = [] with bs4_parser(data) as html: table_body = html.find('tbody') # Continue only if at least one release is found if not table_body: sickrage.app.log.debug( 'Data returned from provider does not contain any torrents' ) return results for row in table_body('tr'): cells = row('td') if len(cells) < 4: continue try: title = download_url = None info_cell = cells[0].a if info_cell: title = info_cell.get_text() download_url = self._get_download_link( urljoin(self.urls['base_url'], info_cell.get('href'))) if not all([title, download_url]): continue title = '{name} {codec}'.format(name=title, codec='x264') if self.custom_url and self.urls[ 'base_url'] in download_url: if not validate_url(self.custom_url): sickrage.app.log.warning( "Invalid custom url: {}".format( self.custom_url)) return results download_url = urljoin( self.custom_url, download_url.split(self.urls['base_url'])[1]) seeders = try_int(cells[2].get_text(strip=True)) leechers = try_int(cells[3].get_text(strip=True)) torrent_size = cells[1].get_text() size = convert_size(torrent_size, -1) results += [{ 'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers }] if mode != 'RSS': sickrage.app.log.debug( "Found result: {}".format(title)) except Exception: sickrage.app.log.error("Failed parsing provider") return results
def parse(self, data, mode, **kwargs): """ Parse search results from data :param data: response data :param mode: search mode :return: search results """ results = [] def process_column_header(th): text = "" if th.a: text = th.a.get_text(strip=True) if not text: text = th.get_text(strip=True) return text with bs4_parser(data) as html: torrent_table = html.find("table", id="searchResult") torrent_rows = torrent_table("tr") if torrent_table else [] # Continue only if at least one Release is found if len(torrent_rows) < 2: sickrage.app.log.debug( "Data returned from provider does not contain any torrents" ) return results labels = [ process_column_header(label) for label in torrent_rows[0]("th") ] # Skip column headers for row in torrent_rows[1:]: cells = row('td') if len(cells) < len(labels): continue try: title = row.find(class_='detName') title = title.get_text(strip=True) if title else None download_url = row.find( title='Download this torrent using magnet') download_url = download_url.get( 'href') if download_url else None if download_url and 'magnet:?' not in download_url: try: details_url = urljoin( self.custom_url or self.urls['base_url'], download_url) details_data = self.session.get(details_url).text except Exception: sickrage.app.log.debug( 'Invalid ThePirateBay proxy please try another one' ) continue with bs4_parser(details_data) as details: download_url = details.find( title='Get this torrent') download_url = download_url.get( 'href') if download_url else None if download_url and 'magnet:?' not in download_url: sickrage.app.log.debug( 'Invalid ThePirateBay proxy please try another one' ) continue if not all([title, download_url]): continue seeders = try_int( cells[labels.index("SE")].get_text(strip=True)) leechers = try_int( cells[labels.index("LE")].get_text(strip=True)) # Accept Torrent only from Good People for every Episode Search if self.confirmed and not row.find( alt=re.compile(r"VIP|Trusted")): if mode != "RSS": sickrage.app.log.debug( "Found result: {0} but that doesn't seem like a trusted result so I'm " "ignoring it".format(title)) continue # Convert size after all possible skip scenarios torrent_size = cells[labels.index('Name')].find( class_='detDesc') torrent_size = torrent_size.get_text( strip=True).split(', ')[1] torrent_size = re.sub(r'Size ([\d.]+).+([KMGT]iB)', r'\1 \2', torrent_size) size = convert_size( torrent_size, -1, ['B', 'KIB', 'MIB', 'GIB', 'TIB', 'PIB']) results += [{ 'title': title, 'link': download_url, 'size': size, 'seeders': seeders, 'leechers': leechers }] if mode != 'RSS': sickrage.app.log.debug( "Found result: {}".format(title)) except Exception: sickrage.app.log.error("Failed parsing provider") return results
def _doSearch(self, search_strings, search_mode='eponly', epcount=0, age=0, epObj=None): results = [] items = {'Season': [], 'Episode': [], 'RSS': []} if not self._doLogin(): return results for mode in search_strings.keys(): for search_string in search_strings[mode]: if mode is not 'RSS': sickrage.LOGGER.debug("Search string: %s " % search_string) data = self.getURL(self.urls['index'], params=self.search_params) searchURL = self.urls['index'] + "?" + urlencode(self.search_params) sickrage.LOGGER.debug("Search URL: %s" % searchURL) if not data: sickrage.LOGGER.debug("No data returned from provider") continue try: with bs4_parser(data) as html: torrent_rows = [] down_elems = html.findAll("img", {"alt": "Download Torrent"}) for down_elem in down_elems: if down_elem: torr_row = down_elem.findParent('tr') if torr_row: torrent_rows.append(torr_row) # Continue only if one Release is found if len(torrent_rows) < 1: sickrage.LOGGER.debug("Data returned from provider does not contain any torrents") continue for torrent_row in torrent_rows: title = torrent_row.find('a', {"data-src": True})['data-src'].rsplit('.', 1)[0] download_href = torrent_row.find('img', {"alt": 'Download Torrent'}).findParent()['href'] seeders = int( torrent_row.findAll('a', {'title': 'Click here to view peers details'})[ 0].text.strip()) leechers = int( torrent_row.findAll('a', {'title': 'Click here to view peers details'})[ 1].text.strip()) download_url = self.urls['base_url'] + download_href # FIXME size = -1 if not all([title, download_url]): continue # Filter unseeded torrent if seeders < self.minseed or leechers < self.minleech: if mode is not 'RSS': sickrage.LOGGER.debug( "Discarding torrent because it doesn't meet the minimum seeders or leechers: {0} (S:{1} L:{2})".format( title, seeders, leechers)) continue item = title, download_url, size, seeders, leechers if mode is not 'RSS': sickrage.LOGGER.debug("Found result: %s " % title) items[mode].append(item) except Exception: sickrage.LOGGER.error("Failed parsing provider. Traceback: {}".format(traceback.format_exc())) # For each search mode sort all the items by seeders items[mode].sort(key=lambda tup: tup[3], reverse=True) results += items[mode] return results