我有一个python脚本,允许你上传文件到usersfiles.com,问题是上传文件高达20 MB / s,但因为网络以85 MB / s的速度上传。什么可能到期?用于此工具带,MultipartEncoderMonitor也使用该功能。
import requests
from requests_toolbelt.multipart.encoder import MultipartEncoder, MultipartEncoderMonitor
import random
import re
import time
import os
import sys
from progressbar import AnimatedMarker, Bar, BouncingBar, Counter, ETA, \
FileTransferSpeed, FormatLabel, Percentage, \
ProgressBar, ReverseBar, RotatingMarker, \
SimpleProgress, Timer
proxies = {}
class usersfiles():
sess_id = ""
srv_tmp_url = ""
upload_type = ""
uid = ""
enlace_usersfiles = ""
def __init__(self, params, tipo, enlace_usersfiles=""):
sessionObj = requests.session()
sessionObj.post("https://usersfiles.com/", data={"login":"users", "password":"pass", "op":"login"}, proxies=proxies)
filehandle = open(params, "rb")
self.extraccion_datos_upload(sessionObj)
self.subir_video(sessionObj, filehandle, params)
self.obtener_enlace_usersfiles(sessionObj, filehandle, params)
def my_callback(self, monitor):
self.pbar.update(monitor.bytes_read)
def extraccion_datos_upload(self, sessionObj):
resp = sessionObj.get("https://usersfiles.com/", proxies=proxies)
self.sess_id = re.search('sess_id.*=?"(.*)?"', str(resp.text)).group(1)
self.srv_tmp_url = re.search('srv_tmp_url.*=?"(.*)?"', str(resp.text)).group(1)
self.upload_type = re.search('upload_type.*=?"(.*)?"', str(resp.text)).group(1)
def obtener_uid(self):
for i in range(0, 12):
self.uid=self.uid + '' + str(random.randint(0,9))
def subir_video(self, sessionObj, filehandle, params):
self.obtener_uid()
tam_arch = os.path.getsize(params)
url="https://up11.usersfiles.com/cgi-bin/upload.cgi?upload_id="+self.uid+"&js_on=1&utype=reg&upload_type="+self.upload_type
e = MultipartEncoder(
fields={"upload_type":self.upload_type , "sess_id":self.sess_id, "srv_tmp_url":self.srv_tmp_url,
"file_0":(params, filehandle, 'text/plain')}
)
m = MultipartEncoderMonitor(e, self.my_callback)
progress = ProgressBar()
widgets = [params, " (Sub-Us): ", Bar(marker="|", left="[", right=" "), Percentage(), " ", FileTransferSpeed(), "] ", ETA()]
self.pbar = ProgressBar(widgets=widgets, maxval=len(e)).start()
self.r = sessionObj.post(url, data=m, headers={'Content-Type': m.content_type}, proxies=proxies)
self.pbar.finish()
def obtener_enlace_usersfiles(self, sessionObj, filehandle, params):
self.enlace_usersfiles = re.search('name=.fn.>(.*?)<', str(self.r.text)).group(1)
archivo = usersfiles("Diabolik Lovers - 12.mp4", "v")