本文整理汇总了Python中sickrage.core.helpers.convert_size函数的典型用法代码示例。如果您正苦于以下问题:Python convert_size函数的具体用法?Python convert_size怎么用?Python convert_size使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了convert_size函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse
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
示例2: parse
def parse(self, data, mode, **kwargs):
"""
Parse search results from data
:param data: response data
:param mode: search mode
:return: search results
"""
results = []
for item in data:
try:
title = item['title']
download_url = item['link']
if not all([title, download_url]):
continue
seeders = try_int(item['nyaa_seeders'])
leechers = try_int(item['nyaa_leechers'])
size = convert_size(item['nyaa_size'], -1, units=['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
示例3: parse
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
示例4: parse
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
示例5: parse
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
示例6: search
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
示例7: parse
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
示例8: parse
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
示例9: parse
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
示例10: parse
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
示例11: parse
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
示例12: parse
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
示例13: search
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
示例14: parse
def parse(self, data, mode):
"""
Parse search results from data
:param data: response data
:param mode: search mode
:return: search results
"""
results = []
if not data.startswith("<rss"):
sickrage.app.log.info("Expected rss but got something else, is your mirror failing?")
return results
feed = feedparser.parse(data)
for item in feed.entries:
try:
title = item.title
download_url = item.link
if not (title and download_url):
continue
info = self.regex.search(item.description)
if not info:
continue
seeders = try_int(info.group("seeders"))
leechers = try_int(info.group("leechers"))
category = item.category
if category != 'all':
sickrage.app.log.warning(
'skytorrents.in has added categories! Please report this so it can be updated: Category={cat}, '
'Title={title}'.format(cat=category, title=title))
size = convert_size(info.group('size'), -1)
try:
info_hash = download_url.rsplit('/', 2)[1]
except IndexError:
info_hash = ''
item = {'title': title, 'link': download_url, 'size': size, 'seeders': seeders,
'leechers': leechers, 'hash': info_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
示例15: parse
def parse(self, data, mode):
"""
Parse search results from data
:param data: response data
:param mode: search mode
:return: search results
"""
results = []
torrent_rows = data.pop('torrents', {})
if not self._check_auth_from_data(data):
return results
# Skip column headers
for row in torrent_rows:
try:
title = row.pop('title', '')
info_hash = row.pop('infoHash', '')
download_url = 'magnet:?xt=urn:btih:' + info_hash
if not all([title, download_url, info_hash]):
continue
swarm = row.pop('swarm', {})
seeders = try_int(swarm.pop('seeders', 0))
leechers = try_int(swarm.pop('leechers', 0))
# Filter unseeded torrent
if seeders < min(self.minseed, 1):
if mode != 'RSS':
sickrage.app.log.debug("Discarding torrent because it doesn't meet the minimum "
"seeders: {0}. Seeders: {1}".format(title, seeders))
continue
size = convert_size(row.pop('size', -1)) or -1
item = {
'title': title,
'link': download_url,
'size': size,
'seeders': seeders,
'leechers': leechers,
'pubdate': None,
}
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