fork download
  1. from PyQt5 import QtCore, QtGui, QtWidgets
  2. import os
  3. import re
  4. import time
  5. from random import *
  6. import requests
  7.  
  8. class Ui_MainWindow(object):
  9. mydir = ''
  10. def setupUi(self, MainWindow):
  11. MainWindow.setObjectName("MainWindow")
  12. MainWindow.resize(685, 266)
  13. font = QtGui.QFont()
  14. font.setPointSize(12)
  15. MainWindow.setFont(font)
  16. self.centralwidget = QtWidgets.QWidget(MainWindow)
  17. self.centralwidget.setObjectName("centralwidget")
  18. self.label = QtWidgets.QLabel(self.centralwidget)
  19. self.label.setGeometry(QtCore.QRect(30, 30, 71, 41))
  20. MainWindow.setMaximumSize(QtCore.QSize(685, 266))
  21. font = QtGui.QFont()
  22. font.setPointSize(12)
  23. self.label.setFont(font)
  24. self.label.setObjectName("label")
  25. self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
  26. self.lineEdit.setGeometry(QtCore.QRect(220, 40, 311, 21))
  27. self.lineEdit.setObjectName("lineEdit")
  28. self.label_2 = QtWidgets.QLabel(self.centralwidget)
  29. self.label_2.setGeometry(QtCore.QRect(30, 100, 131, 16))
  30. font = QtGui.QFont()
  31. font.setPointSize(12)
  32. self.label_2.setFont(font)
  33. self.label_2.setObjectName("label_2")
  34. self.pushButton = QtWidgets.QPushButton(self.centralwidget)
  35. self.pushButton.setGeometry(QtCore.QRect(220, 90, 311, 31))
  36. self.pushButton.setObjectName("pushButton")
  37. self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
  38. self.pushButton_2.setGeometry(QtCore.QRect(30, 160, 61, 51))
  39. self.pushButton_2.setObjectName("pushButton_2")
  40. MainWindow.setCentralWidget(self.centralwidget)
  41. self.menubar = QtWidgets.QMenuBar(MainWindow)
  42. self.menubar.setGeometry(QtCore.QRect(0, 0, 685, 27))
  43. self.menubar.setObjectName("menubar")
  44. MainWindow.setMenuBar(self.menubar)
  45. self.statusbar = QtWidgets.QStatusBar(MainWindow)
  46. self.statusbar.setObjectName("statusbar")
  47. MainWindow.setStatusBar(self.statusbar)
  48. self.pushButton.clicked.connect(self.choose_dir)
  49. self.pushButton_2.clicked.connect(self.start1)
  50. self.retranslateUi(MainWindow)
  51. QtCore.QMetaObject.connectSlotsByName(MainWindow)
  52. def retranslateUi(self, MainWindow):
  53. _translate = QtCore.QCoreApplication.translate
  54. MainWindow.setWindowTitle(_translate("MainWindow", "dobrochan.com"))
  55. self.label.setText(_translate("MainWindow", "Ссылка:"))
  56. self.label_2.setText(_translate("MainWindow", "Папка загрузки:"))
  57. self.pushButton.setText(_translate("MainWindow", "..."))
  58. self.pushButton_2.setText(_translate("MainWindow", "Старт"))
  59.  
  60. def choose_dir(self):
  61. Ui_MainWindow.mydir = QtWidgets.QFileDialog.getExistingDirectory()
  62.  
  63. def randname(x):
  64. return ''.join(sample(''.join([chr(i) for i in range(97,123)])*3 + str(randint(111111,999999))*20, x))
  65.  
  66. def download(self, mylink, mydir):
  67. os.chdir(mydir)
  68. mythread = requests.get(mylink).content.decode()
  69. links = list(set(re.findall(r'(?<=url=)http:\/\/dobrochan\.com\/src\/\S+(?=\")', mythread)))
  70. k = 0
  71. total = len(links)
  72. progress = QtWidgets.QProgressDialog('Loading...', 'Cancel', 0, total)
  73. progress.setWindowModality(QtCore.Qt.WindowModal)
  74. progress.forceShow()
  75. for elem in enumerate(links):
  76. progress.setValue(elem[0])
  77. if progress.wasCanceled():
  78. break
  79. pic = requests.get(elem[1]).content
  80. ext = re.search(r'\.[a-z]{3,4}$',elem[1]).group()
  81. f = open(Ui_MainWindow.randname(16) + ext, 'wb')
  82. f.write(pic)
  83. f.close()
  84. time.sleep(0.5)
  85. progress.setValue(total)
  86. self.lineEdit.clear()
  87.  
  88. def start1(self):
  89. self.download(self.lineEdit.text(), Ui_MainWindow.mydir)
  90.  
  91. if __name__ == "__main__":
  92. import sys
  93. app = QtWidgets.QApplication(sys.argv)
  94. MainWindow = QtWidgets.QMainWindow()
  95. ui = Ui_MainWindow()
  96. ui.setupUi(MainWindow)
  97. MainWindow.show()
  98. sys.exit(app.exec_())
Runtime error #stdin #stdout #stderr 0.02s 8736KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 1, in <module>
ImportError: No module named 'PyQt5'