Aggiornare 'upload.py'
parent
0db3b253df
commit
3ab94a5918
30
upload.py
30
upload.py
|
@ -1,6 +1,7 @@
|
||||||
import os
|
import os
|
||||||
import requests
|
import requests
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from requests_toolbelt import MultipartEncoder
|
||||||
|
|
||||||
# Endpoints ottenuti tramite http://xvideosharing.com/api/folder/list?key=key&fld_id=fld_id
|
# Endpoints ottenuti tramite http://xvideosharing.com/api/folder/list?key=key&fld_id=fld_id
|
||||||
|
|
||||||
|
@ -14,6 +15,8 @@ headers = {"Content-Type": "application/json"}
|
||||||
# Global Variables
|
# Global Variables
|
||||||
|
|
||||||
fileinDirectory = []
|
fileinDirectory = []
|
||||||
|
MAX_UPLOAD_GB = 750
|
||||||
|
UPLOADED_GB = 0
|
||||||
|
|
||||||
|
|
||||||
def visit_list(l):
|
def visit_list(l):
|
||||||
|
@ -67,7 +70,7 @@ def getFolderList():
|
||||||
|
|
||||||
|
|
||||||
def checkIfFileExists(title_file, fld_id):
|
def checkIfFileExists(title_file, fld_id):
|
||||||
url = f"{endpoint_fileList}&fld_id={fld_id}"
|
url = f"{endpoint_fileList}&fld_id={fld_id}&per_page=2000"
|
||||||
response = requests.get(url, headers=headers)
|
response = requests.get(url, headers=headers)
|
||||||
if response.ok:
|
if response.ok:
|
||||||
data = response.json()
|
data = response.json()
|
||||||
|
@ -100,23 +103,26 @@ def upload(file_obj):
|
||||||
print(file_path)
|
print(file_path)
|
||||||
content_name = str(fileslist)
|
content_name = str(fileslist)
|
||||||
fileNoExtension = Path(file_path).stem
|
fileNoExtension = Path(file_path).stem
|
||||||
|
file_size = os.path.getsize(file_path)
|
||||||
|
file_size_gb = round(file_size / (1024 * 1024 * 1024), 3)
|
||||||
|
global UPLOADED_GB
|
||||||
|
UPLOADED_GB += file_size_gb
|
||||||
count += 1
|
count += 1
|
||||||
videoexists = checkIfFileExists(fileNoExtension, fld_id)
|
videoexists = checkIfFileExists(fileNoExtension, fld_id)
|
||||||
if videoexists:
|
if videoexists or UPLOADED_GB == MAX_UPLOAD_GB or file_size_gb >= 10:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
pass
|
||||||
url = "https://marlin2.vtube.to/upload/01"
|
url = "https://marlin2.vtube.to/upload/01"
|
||||||
files = {
|
m = MultipartEncoder(
|
||||||
"file": (
|
fields={
|
||||||
content_name,
|
"file": (content_name, open(file_path, "rb")),
|
||||||
open(
|
"api_key": "473u3rs97it2ge3hk77",
|
||||||
file_path,
|
|
||||||
"rb",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
"api_key": (None, "473u3rs97it2ge3hk77"),
|
|
||||||
}
|
}
|
||||||
response = requests.post(url, files=files)
|
)
|
||||||
|
response = requests.post(
|
||||||
|
url, data=m, headers={"Content-Type": m.content_type}
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
except:
|
except:
|
||||||
|
|
Loading…
Reference in New Issue