Aggiornare 'upload.py'

vtube
MickSlash 2022-04-15 15:21:42 +00:00
parent 0db3b253df
commit 3ab94a5918
1 changed files with 20 additions and 14 deletions

View File

@ -1,6 +1,7 @@
import os
import requests
from pathlib import Path
from requests_toolbelt import MultipartEncoder
# 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
fileinDirectory = []
MAX_UPLOAD_GB = 750
UPLOADED_GB = 0
def visit_list(l):
@ -67,7 +70,7 @@ def getFolderList():
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)
if response.ok:
data = response.json()
@ -100,23 +103,26 @@ def upload(file_obj):
print(file_path)
content_name = str(fileslist)
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
videoexists = checkIfFileExists(fileNoExtension, fld_id)
if videoexists:
if videoexists or UPLOADED_GB == MAX_UPLOAD_GB or file_size_gb >= 10:
pass
else:
pass
url = "https://marlin2.vtube.to/upload/01"
files = {
"file": (
content_name,
open(
file_path,
"rb",
),
),
"api_key": (None, "473u3rs97it2ge3hk77"),
}
response = requests.post(url, files=files)
m = MultipartEncoder(
fields={
"file": (content_name, open(file_path, "rb")),
"api_key": "473u3rs97it2ge3hk77",
}
)
response = requests.post(
url, data=m, headers={"Content-Type": m.content_type}
)
try:
response.raise_for_status()
except:
@ -137,4 +143,4 @@ def upload(file_obj):
if __name__ == "__main__":
folderUpload = input("Inserisci la cartella dove sono presenti i file : ")
upload(folderUpload)
upload(folderUpload)