本文整理汇总了Python中module.utils.parseFileSize函数的典型用法代码示例。如果您正苦于以下问题:Python parseFileSize函数的具体用法?Python parseFileSize怎么用?Python parseFileSize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parseFileSize函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parseFileInfo
def parseFileInfo(self, url='', html=''):
info = {"name": url, "size": 0, "status": 3}
if hasattr(self, "pyfile"):
url = self.pyfile.url
if hasattr(self, "req") and self.req.http.code == '404':
info['status'] = 1
else:
if not html and hasattr(self, "html"):
html = self.html
if isinstance(self.SH_BROKEN_ENCODING, (str, unicode)):
html = unicode(html, self.SH_BROKEN_ENCODING)
if hasattr(self, "html"):
self.html = html
if hasattr(self, "FILE_OFFLINE_PATTERN") and re.search(self.FILE_OFFLINE_PATTERN, html):
# File offline
info['status'] = 1
else:
online = False
try:
info.update(re.match(self.__pattern__, url).groupdict())
except:
pass
for pattern in ("FILE_INFO_PATTERN", "FILE_NAME_PATTERN", "FILE_SIZE_PATTERN"):
try:
info.update(re.search(getattr(self, pattern), html).groupdict())
online = True
except AttributeError:
continue
if online:
# File online, return name and size
info['status'] = 2
if 'N' in info:
info['name'] = replace_patterns(info['N'], self.FILE_NAME_REPLACEMENTS)
if 'S' in info:
size = replace_patterns(info['S'] + info['U'] if 'U' in info else info['S'],
self.FILE_SIZE_REPLACEMENTS)
info['size'] = parseFileSize(size)
elif isinstance(info['size'], (str, unicode)):
if 'units' in info:
info['size'] += info['units']
info['size'] = parseFileSize(info['size'])
if hasattr(self, "file_info"):
self.file_info = info
return info['name'], info['size'], info['status'], url
示例2: getInfo
def getInfo(urls):
file_info = list()
list_ids = dict()
# Create a dict id:url. Will be used to retrieve original url
for url in urls:
m = re.search(FilefactoryCom.__pattern__, url)
list_ids[m.group('id')] = url
# WARN: There could be a limit of urls for request
post_data = {'func': 'links', 'links': '\n'.join(urls)}
rep = getURL('http://www.filefactory.com/tool/links.php', post=post_data, decode=True)
# Online links
for m in re.finditer(
r'innerText">\s*<h1 class="name">(?P<N>.+) \((?P<S>[\w.]+) (?P<U>\w+)\)</h1>\s*<p>http://www.filefactory.com/file/(?P<ID>\w+).*</p>\s*<p class="hidden size">',
rep):
file_info.append((m.group('N'), parseFileSize(m.group('S'), m.group('U')), 2, list_ids[m.group('ID')]))
# Offline links
for m in re.finditer(
r'innerText">\s*<h1>(http://www.filefactory.com/file/(?P<ID>\w+)/)</h1>\s*<p>\1</p>\s*<p class="errorResponse">Error: file not found</p>',
rep):
file_info.append((list_ids[m.group('ID')], 0, 1, list_ids[m.group('ID')]))
return file_info
示例3: loadAccountInfo
def loadAccountInfo(self, user, req):
password = self.accounts[user]['password']
api_data = req.load('http://www.ddlstorage.com/cgi-bin/api_req.cgi',
post={'req_type': 'user_info',
'client_id': 53472,
'user_login': user,
'user_password': md5(password).hexdigest(),
'sign': md5('user_info%d%s%s%s' % (53472, user, md5(password).hexdigest(),
'25JcpU2dPOKg8E2OEoRqMSRu068r0Cv3')).hexdigest()})
api_data = api_data.replace('<pre>', '').replace('</pre>', '')
self.logDebug('Account Info API data: ' + api_data)
api_data = json_loads(api_data)
if api_data['status'] != 'OK': # 'status' must be always OK for a working account
return {"premium": False, "valid": False}
if api_data['account_type'] == 'REGISTERED':
premium = False
validuntil = None
else:
premium = True
validuntil = int(mktime(strptime(api_data['premium_expire'], "%Y-%m-%d %H:%M:%S")))
if api_data['usr_bandwidth_available'] == 'UNLIMITED':
trafficleft = -1
else:
trafficleft = parseFileSize(api_data['usr_bandwidth_available']) / 1024
return {"premium": premium, "validuntil": validuntil, "trafficleft": trafficleft}
示例4: loadAccountInfo
def loadAccountInfo(self, user, req):
html = req.load("http://www.stahnu.to/")
found = re.search(r'>VIP: (\d+.*)<', html)
trafficleft = parseFileSize(found.group(1)) * 1024 if found else 0
return {"premium": trafficleft > (512 * 1024), "trafficleft": trafficleft, "validuntil": -1}
示例5: loadAccountInfo
def loadAccountInfo(self, user, req):
html = req.load("http://egofiles.com")
if "You are logged as a Free User" in html:
return {"premium": False, "validuntil": None, "trafficleft": None}
m = re.search(self.PREMIUM_ACCOUNT_PATTERN, html)
if m:
validuntil = int(time.mktime(time.strptime(m.group("P"), "%Y-%m-%d %H:%M:%S")))
trafficleft = parseFileSize(m.group("T"), m.group("U")) / 1024
return {"premium": True, "validuntil": validuntil, "trafficleft": trafficleft}
else:
self.logError("Unable to retrieve account information - Plugin may be out of date")
示例6: loadAccountInfo
def loadAccountInfo(self, user, req):
html = req.load("http://www.fastshare.cz/user", decode=True)
found = re.search(self.CREDIT_PATTERN, html)
if found:
trafficleft = parseFileSize(found.group(1)) / 1024
premium = True if trafficleft else False
else:
trafficleft = None
premium = False
return {"validuntil": -1, "trafficleft": trafficleft, "premium": premium}
示例7: process
def process(self, pyfile):
if re.match(self.__pattern__, pyfile.url):
new_url = pyfile.url
elif not self.account:
self.logError(_("Please enter your %s account or deactivate this plugin") % "Real-debrid")
self.fail("No Real-debrid account provided")
else:
self.logDebug("Old URL: %s" % pyfile.url)
password = self.getPassword().splitlines()
if not password:
password = ""
else:
password = password[0]
url = "https://real-debrid.com/ajax/unrestrict.php?lang=en&link=%s&password=%s&time=%s" % (
quote(pyfile.url, ""), password, int(time() * 1000))
page = self.load(url)
data = json_loads(page)
self.logDebug("Returned Data: %s" % data)
if data["error"] != 0:
if data["message"] == "Your file is unavailable on the hoster.":
self.offline()
else:
self.logWarning(data["message"])
self.tempOffline()
else:
if pyfile.name is not None and pyfile.name.endswith('.tmp') and data["file_name"]:
pyfile.name = data["file_name"]
pyfile.size = parseFileSize(data["file_size"])
new_url = data['generated_links'][0][-1]
if self.getConfig("https"):
new_url = new_url.replace("http://", "https://")
else:
new_url = new_url.replace("https://", "http://")
if new_url != pyfile.url:
self.logDebug("New URL: %s" % new_url)
if pyfile.name.startswith("http") or pyfile.name.startswith("Unknown") or pyfile.name.endswith('..'):
#only use when name wasnt already set
pyfile.name = self.getFilename(new_url)
self.download(new_url, disposition=True)
check = self.checkDownload(
{"error": "<title>An error occured while processing your request</title>"})
if check == "error":
#usual this download can safely be retried
self.retry(wait_time=60, reason="An error occured while generating link.")
示例8: loadAccountInfo
def loadAccountInfo(self, user, req):
html = req.load("http://www.quickshare.cz/premium", decode = True)
found = re.search(r'Stav kreditu: <strong>(.+?)</strong>', html)
if found:
trafficleft = parseFileSize(found.group(1)) / 1024
premium = True if trafficleft else False
else:
trafficleft = None
premium = False
return {"validuntil": -1, "trafficleft": trafficleft, "premium": premium}
示例9: loadAccountInfo
def loadAccountInfo(self, user, req):
html = req.load("http://www.fastshare.cz/user", decode=True)
found = re.search(r"(?:Kredit|Credit)\s*: </td><td>(.+?) ", html)
if found:
trafficleft = parseFileSize(found.group(1)) / 1024
premium = True if trafficleft else False
else:
trafficleft = None
premium = False
return {"validuntil": -1, "trafficleft": trafficleft, "premium": premium}
示例10: loadAccountInfo
def loadAccountInfo(self, user, req):
#self.relogin(user)
html = req.load("http://www.multishare.cz/profil/", decode=True)
found = re.search(self.TRAFFIC_LEFT_PATTERN, html)
trafficleft = parseFileSize(found.group('S'), found.group('U')) / 1024 if found else 0
self.premium = True if trafficleft else False
html = req.load("http://www.multishare.cz/", decode=True)
mms_info = dict(re.findall(self.ACCOUNT_INFO_PATTERN, html))
return dict(mms_info, **{"validuntil": -1, "trafficleft": trafficleft})
示例11: process
def process(self, pyfile):
if not self.account:
self.logError(_("Please enter your AllDebrid account or deactivate this plugin"))
self.fail("No AllDebrid account provided")
self.log.debug("AllDebrid: Old URL: %s" % pyfile.url)
if re.match(self.__pattern__, pyfile.url):
new_url = pyfile.url
else:
password = self.getPassword().splitlines()
if not password: password = ""
else: password = password[0]
url = "http://www.alldebrid.com/service.php?link=%s&json=true&pw=%s" %(pyfile.url, password)
page = self.load(url)
data = json_loads(page)
self.log.debug("Json data: %s" % str(data))
if data["error"]:
if data["error"] == "This link isn't available on the hoster website.":
self.offline()
else:
self.logWarning(data["error"])
self.tempOffline()
else:
if self.pyfile.name and not self.pyfile.name.endswith('.tmp'):
self.pyfile.name = data["filename"]
self.pyfile.size = parseFileSize(data["filesize"])
new_url = data["link"]
if self.getConfig("https"):
new_url = new_url.replace("http://", "https://")
else:
new_url = new_url.replace("https://", "http://")
self.log.debug("AllDebrid: New URL: %s" % new_url)
if pyfile.name.startswith("http") or pyfile.name.startswith("Unknown"):
#only use when name wasnt already set
pyfile.name = self.getFilename(new_url)
self.download(new_url, disposition=True)
check = self.checkDownload(
{"error": "<title>An error occured while processing your request</title>","empty": re.compile(r"^$")})
if check == "error":
self.retry(reason="An error occured while generating link.", wait_time=60)
else:
if check == "empty":
self.retry(reason="Downloaded File was empty.", wait_time=60)
示例12: getInfo
def getInfo(urls):
for url in urls:
header = getURL(url, just_header=True)
if 'Location: http://cloudzer.net/404' in header:
file_info = (url, 0, 1, url)
else:
if url.endswith('/'):
api_data = getURL(url + 'status')
else:
api_data = getURL(url + '/status')
name, size = api_data.splitlines()
size = parseFileSize(size)
file_info = (name, size, 2, url)
yield file_info
示例13: process
def process(self, pyfile):
self.pyfile = pyfile
self.pyfile.url = re.sub("(video|image|audio|flash)","download",self.pyfile.url)
self.html = self.load(pyfile.url)
if "File Not Found" in self.html:
self.offline()
filenameMatch = re.search("File Name:.*?<font color=\"#666666\".*?>(.*?)</font>", self.html, re.DOTALL)
filesizeMatch = re.search("File Size:.*?<font color=\"#666666\".*?>([^<]+)</font>", self.html, re.DOTALL)
if not filenameMatch or not filesizeMatch:
self.offline()
filename = filenameMatch.group(1)
filesize = filesizeMatch.group(1)
if filename.strip() == "":
self.offline()
pyfile.name = filename
pyfile.size = parseFileSize(filesize)
if '<input name="download"' not in self.html:
self.fail("No download form")
self.html = self.load(pyfile.url, post={
"download": 1,
"imageField.x": random.randrange(160),
"imageField.y": random.randrange(60)})
dllinkMatch = re.search("var link_enc\\=new Array\\(\\'(.*?)\\'\\)", self.html)
if dllinkMatch:
dllink = re.sub("\\'\\,\\'", "", dllinkMatch.group(1))
else:
self.fail("Plugin defect")
self.setWait(51)
self.wait()
self.download(dllink)
check = self.checkDownload({
"unav": "/images/download.gif",
"404": "404 - Not Found"
})
#print check
if check == "unav":
self.fail("Plugin defect")
elif check == "404":
self.offline()
示例14: parseFileInfo
def parseFileInfo(self, url = '', html = ''):
if not html and hasattr(self, "html"): html = self.html
name, size, status, found, fileid = url, 0, 3, None, None
if re.search(self.FILE_OFFLINE_PATTERN, html):
# File offline
status = 1
else:
found = re.search(self.FILE_INFO_PATTERN, html)
if found:
name, fileid = html_unescape(found.group('N')), found.group('ID')
size = parseFileSize(found.group('S'))
status = 2
return name, size, status, fileid
示例15: checkFile
def checkFile(plugin, urls):
html = getURL(plugin.URLS[1], post={"urls": "\n".join(urls)}, decode=True)
file_info = []
for li in re.finditer(plugin.LINKCHECK_TR, html, re.DOTALL):
try:
cols = re.findall(plugin.LINKCHECK_TD, li.group(1))
if cols:
file_info.append((
cols[1] if cols[1] != '--' else cols[0],
parseFileSize(cols[2]) if cols[2] != '--' else 0,
2 if cols[3].startswith('Available') else 1,
cols[0]))
except Exception, e:
continue