Skip to content

Commit f50b4df

Browse files
fix pixeldrain speed
1 parent dc916ec commit f50b4df

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

main.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717

1818
###
1919
# Things in this part are meant for debugging and toggling certaint things.
20-
use_test_file = True
20+
use_test_file = False
2121
test_small_file = True
2222
test_large_file = False
2323
SKIP_SITE_CHECK = True
2424
#
2525
###
2626

27-
version = "1.5.0"
27+
version = "1.5.1"
2828
owd = os.getcwd()
2929
platform = sys.platform
3030

modules/pixeldrain.py

+16-13
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,44 @@
1-
import requests
21
import os
32
import random
4-
3+
import urllib3
54
from .site_data import Site_Data_CLSS, sites_data_dict
65
from .pretty_print import *
76
from .logger import Logger
8-
9-
site = "Pixeldrain"
7+
import json
108

119
class Pixeldrain:
1210

13-
def Uploader(file, proxy_list, user_agents, api_keys):
11+
@staticmethod
12+
def Uploader(file, proxy_list, user_agents, api_keys):
1413
try:
14+
site = "Pixeldrain" # Moved the 'site' definition inside the method
15+
1516
ua = random.choice(user_agents)
1617
size_limit = f'{sites_data_dict[site]["size_limit"]} {sites_data_dict[site]["size_unit"]}'
1718

1819
base_url = sites_data_dict[site]["download_url_base"]
1920

2021
file_size = os.stat(file).st_size
2122
file_name = os.path.basename(file)
22-
file_name = (file_name[:240] + '..') if len(file_name) > 240 else file_name # Changed from 255 to 240 as an additional safety net.
23-
23+
file_name = (file_name[:240] + '..') if len(file_name) > 240 else file_name
24+
2425
upload_url = sites_data_dict[site]["url"].format(file_name=file_name)
2526

2627
calc_size = Site_Data_CLSS.size_unit_calc(site, file_size)
2728

2829
headers = {"User-Agent": ua, "Content-Type": "application/octet-stream"}
29-
proxies = random.choice(proxy_list) if proxy_list else None
30+
proxy = random.choice(proxy_list) if proxy_list else None
3031

3132
if calc_size == "OK":
33+
http = urllib3.PoolManager()
3234
with open(file, "rb") as file_upload:
33-
req = requests.put(url=upload_url, data=file_upload, headers=headers, proxies=proxies, timeout=300, stream=True).json()
34-
file_upload.close()
35-
return {"status": "ok", "file_name": file_name, "file_url": base_url + req['id']}
35+
req = http.urlopen('PUT', upload_url, body=file_upload, headers=headers, timeout=300)
36+
if req.status != 201:
37+
raise Exception(f"HTTP Error {req.status}: {req.reason}")
38+
response_json = json.loads(req.data.decode('utf-8'))
39+
return {"status": "ok", "file_name": file_name, "file_url": base_url + response_json['id']}
3640
else:
3741
return {"status": "size_error", "file_name": file_name, "exception": "SIZE_ERROR", "size_limit": size_limit}
3842

3943
except Exception as e:
40-
return {"status": "error", "file_name": file_name, "exception": str(e), "extra": raw_req}
41-
44+
return {"status": "error", "file_name": file_name, "exception": str(e)}

0 commit comments

Comments
 (0)