-
Notifications
You must be signed in to change notification settings - Fork 3
/
LightLoader.py
89 lines (62 loc) · 2.65 KB
/
LightLoader.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
from urllib.request import urlopen, Request
from bs4 import BeautifulSoup
import random, string, os
import threading
import requests
import time
# - Output folder name.
DIRNAME = "Output"
DLCOUNT = 0
ERCOUNT = 0
LENGTH = 6
class LightLoader(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
while True:
fileName = self.generateId(LENGTH)
url = self.generateLink(fileName)
print(url)
self.generateImgur(url, fileName)
# - Generates lightshot link using generateId() function
def generateLink(self, fileName):
return "https://prnt.sc/" + fileName
# - Generates random string
def generateId(self, size):
return ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(size))
# - Downloads HTML File from link previously generated
def generateHtml(self, fileName):
url = self.generateLink(fileName)
request = Request(url, headers={'User-Agent': 'Mozilla/5.0'})
print(request)
page = urlopen(request).read()
return page
# - Looks for raw image link in HTML File
def generateImgur(self, url, fileName):
soup = BeautifulSoup(self.generateHtml(fileName), 'html.parser')
imgUrl = soup.find('img', id='screenshot-image')['src']
# - Prevents "Error Image" From being downloaded
if imgUrl != '//st.prntscr.com/2018/06/19/0614/img/0_173a7b_211be8ff.png':
imgUrl = imgUrl.replace('//st.', 'http://st.') if imgUrl.startswith('//st.') else imgUrl
global DLCOUNT
DLCOUNT += 1
print("Prepare to download: " + imgUrl)
archive_path = DIRNAME + "/" + fileName + ".png"
with open(archive_path, 'wb') as f:
f.write(requests.get(imgUrl, headers={'User-Agent': 'Mozilla/5.0'}).content)
print("File: " + fileName + " - Saved to " + DIRNAME + " folder. ")
print("Total Downloads: " + str(DLCOUNT))
else:
global ERCOUNT
ERCOUNT += 1
print("The requested url is invalid. Trying a new combination... Error n. " + str(ERCOUNT))
def main():
# - Creates "Output" folder if not present
if not os.path.exists(DIRNAME):
os.makedirs(DIRNAME)
for _ in range(int(input("Input number of threads to be used: "))):
thread = LightLoader()
thread.start()
time.sleep(0.25)
print("Active threads: {}".format(threading.activeCount() - 1))
main()