-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.py
51 lines (36 loc) · 1.17 KB
/
helpers.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
import base64
import requests
import zlib
import random
import os
import io
def encode(input_string):
# Encode the input string to Base64
return str(zlib.compress(input_string.encode('utf-8')))
def decode(encoded_string):
byte_str = encoded_string[2:-1]
bytes_data = bytes(byte_str, 'utf-8')
return zlib.decompress(bytes_data, 'utf-8')
def get_key(url: str) -> str:
key = url.strip().split('/')[-1]
return key
def download_image(url: str, referer) -> str:
req = requests.get(url, headers={
'referer': referer
})
name = str(random.randint(100000, 9999999)) + '.jpg'
with open(f"temp/{name}", "wb") as f:
f.write(req.content)
return name
def remove_image(name: str) -> bool:
os.remove(f'temp/{name}')
return True
def get_image(url: str, referer: str):
""" Fetch the chapter image """
image = requests.get(url, headers={ 'referer': referer })
base = base64.b64encode(image.content).decode('utf-8')
_bytes = io.BytesIO(base64.b64decode(base))
return _bytes
if __name__ == '__main__':
image = get_image('https://avt.mkklcdnv6temp.com/33/a/16-1583494657.jpg', 'https://readmangabat.com/')
print(image)