from PyQt5 import QtCore, QtGui, QtWidgets
import os
import re
import time
from random import *
import requests
class Ui_MainWindow(object):
mydir = ''
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(685, 266)
font = QtGui.QFont()
font.setPointSize(12)
MainWindow.setFont(font)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(30, 30, 71, 41))
MainWindow.setMaximumSize(QtCore.QSize(685, 266))
font = QtGui.QFont()
font.setPointSize(12)
self.label.setFont(font)
self.label.setObjectName("label")
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(220, 40, 311, 21))
self.lineEdit.setObjectName("lineEdit")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(30, 100, 131, 16))
font = QtGui.QFont()
font.setPointSize(12)
self.label_2.setFont(font)
self.label_2.setObjectName("label_2")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(220, 90, 311, 31))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(30, 160, 61, 51))
self.pushButton_2.setObjectName("pushButton_2")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 685, 27))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.pushButton.clicked.connect(self.choose_dir)
self.pushButton_2.clicked.connect(self.start1)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "dobrochan.com"))
self.label.setText(_translate("MainWindow", "Ссылка:"))
self.label_2.setText(_translate("MainWindow", "Папка загрузки:"))
self.pushButton.setText(_translate("MainWindow", "..."))
self.pushButton_2.setText(_translate("MainWindow", "Старт"))
def choose_dir(self):
Ui_MainWindow.mydir = QtWidgets.QFileDialog.getExistingDirectory()
def randname(x):
return ''.join(sample(''.join([chr(i) for i in range(97,123)])*3 + str(randint(111111,999999))*20, x))
def download(self, mylink, mydir):
os.chdir(mydir)
mythread = requests.get(mylink).content.decode()
links = list(set(re.findall(r'(?<=url=)http:\/\/dobrochan\.com\/src\/\S+(?=\")', mythread)))
k = 0
total = len(links)
progress = QtWidgets.QProgressDialog('Loading...', 'Cancel', 0, total)
progress.setWindowModality(QtCore.Qt.WindowModal)
progress.forceShow()
for elem in enumerate(links):
progress.setValue(elem[0])
if progress.wasCanceled():
break
pic = requests.get(elem[1]).content
ext = re.search(r'\.[a-z]{3,4}$',elem[1]).group()
f = open(Ui_MainWindow.randname(16) + ext, 'wb')
f.write(pic)
f.close()
time.sleep(0.5)
progress.setValue(total)
self.lineEdit.clear()
def start1(self):
self.download(self.lineEdit.text(), Ui_MainWindow.mydir)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())