-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload_prod.py
98 lines (81 loc) · 3.4 KB
/
upload_prod.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import os
import sys
import math
import http.client
import requests
import json
import re
from pprint import pprint
from bs4 import BeautifulSoup
def read_in_chunks(file_object, chunk_size=65536):
while True:
data = file_object.read(chunk_size)
if not data:
break
yield data
# filename = "./sample.txt"
filename = "C:\~\/resources\/videos\/27.mp4"
# url="http://httpbin.org/post"
url = "https://fast-upload-pp.youongroup.com/upload"
# Open file
f = open(filename, 'rb')
status = os.stat(filename)
fileSize = status.st_size
resumableChunkSize = 2 * 1024 * 1024 ## 25MB chuncksize
resumableTotalChunks = math.ceil(fileSize / resumableChunkSize)
print(resumableTotalChunks)
index = 0
sizeSum = 0
offset = 0
httpOffset = 0
idAccount = 1
chunkNumber = 1
headers = {}
## TODO Make a get request to https://upload-pp.youongroup.com/4utzruz5z0
uploadUrl = "https://upload-pp.youongroup.com/4utzruz5z0"
response = requests.get(url=uploadUrl)
soup = BeautifulSoup(response.text, 'lxml')
# Create a pattern to match names
# try to match window.maxFileSize = 10737418240;
# try to match window.maxFiles = 1024;
# try to match window.jwt = "..."
# try to match window.fileType = ["mov","avi","mkv","divx","mp4","flv","3gp","3g2","flv","ogv","webm","r3d"];
name_pattern = re.compile(r'(window.jwt)\ \=\ \"(.*)\"', flags=re.M)
print(name_pattern)
# Find all occurrences of the pattern
names = name_pattern.findall(soup.text)
print(names)
sys.exit()
for chunk in read_in_chunks(f, resumableChunkSize):
currentChunkSize = len(chunk)
sizeSum += len(chunk)
offset += len(chunk)
httpOffset = index + len(chunk)
index = httpOffset
jwt = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhY2NvdW50Ijp7Im5hbWUiOiJEZWJ1ZyIsInRva2VuIjoiZGVidWctNmNiOTJlNGE0ZTc0ZTkwYTI5ZjIwNmI0ZWNkOGM1ZmQiLCJpZCI6MX0sImNodW5rcyI6eyJkaXJuYW1lIjoiXC9tbnRcL2RhdGEzXC9za29peS1wcFwvc2tvaXktYWRzXC9hZHMtdXBsb2Fkcy1jaHVua3MifSwidXBsb2FkIjp7ImRpcm5hbWUiOiJcL21udFwvZGF0YTNcL3Nrb2l5LXBwXC9za29peS1hZHNcL2Fkcy11cGxvYWRzIn0sInN0b3JhZ2UiOnsiaWQiOiIzOCIsImRpcm5hbWUiOiJcL21udFwvZGF0YTNcL3Nrb2l5LXBwXC9za29peS1hZHNcL2Fkcy1zb3VyY2VzIn0sImNkbiI6eyJpZCI6IjEzIn0sImNvZGUiOiI0dXR6cnV6NXowIiwidHlwZSI6ImFkcyIsImV4cCI6MTU4NDExMzI5NiwiaWF0IjoxNTgzOTQwNDk2fQ.WNN5jBlv57kPZvhKOmO8z_amE8oWXHq_bjLPCgQ2ddc'
headers['Authorization'] = 'Bearer ' + jwt
try:
payload = {'resumableChunkNumber': chunkNumber,
'resumableChunkSize': resumableChunkSize,
'resumableCurrentChunkSize': currentChunkSize,
'resumableTotalSize': fileSize,
'resumableType': 'video',
'resumableIdentifier': '4671021-27mp4',
'resumableFilename': '%2327.mp4',
'resumableRelativePath': '%2327.mp4',
'resumableTotalChunks': resumableTotalChunks,
'code': '4utzruz5z0',
'id': idAccount}
multipart_form_data = {
'file': (filename, chunk)
}
print(payload)
r = requests.post(url=url, files=multipart_form_data, data=payload, headers=headers)
## r = requests.post("http://httpbin.org/post", files=multipart_form_data, data=payload, headers=headers)
## print("r: %s, Content-Range: %s" % (r,headers['Content-Range']))
# pprint(r.json())
print(r)
chunkNumber = chunkNumber + 1
except Exception as e:
print(e)
## f.close()