-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
76 lines (64 loc) · 2.32 KB
/
main.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
from PyQt5 import uic
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.QtGui import QIcon
import pafy
import sys, os
import threading as th
download_path = os.path.normpath(os.getenv('USERPROFILE') + '/Downloads/')
def download():
def callback(total, recvd, ratio, rate, eta):
ui.label.setText('')
ui.label.setText('Скачано '\
+ str(round(recvd / 1000 / 1000)) + ' из '\
+ str(round(best.get_filesize() / 1000 / 1000)) + ' МБ')
try:
global best
url = ui.entry_url.text()
video = pafy.new(url)
streams = video.streams
best = video.getbest()
ui.label.setText('')
best.download(filepath=download_path, quiet=True, callback=callback)
ui.label.setText('Видео успешно загружено')
except ValueError:
ui.label.setText('Введите верный адрес URL')
except OSError:
pass
except RuntimeError:
pass
def download_thread():
downloaded = False
while not downloaded:
try:
th.Thread(target=download).start()
except RuntimeError:
pass
downloaded = True
def initUI():
ui.btn_download.clicked.connect(download_thread)
ui.btn_settings.setIcon(QIcon('img/settings.png'))
# ui.btn_settings.clicked.connect(show_settings)
ui.btn_info.setIcon(QIcon('img/info.png'))
# ui.btn_info.clicked.connect(dialog_info)
def ICON_PATH(relative):
if hasattr(tk.sys, '_MEIPASS'):
return os.path.join(sys._MEIPASS, relative)
return os.path.join(relative)
if __name__ == '__main__':
# создаем приложене
app = QApplication(sys.argv)
# создаем главное окно
window = QMainWindow()
# подключаем файл .ui для главного окна
ui = uic.loadUi('main.ui', window)
# подключаем файл стилей
window.setStyleSheet(open('main.qss', 'r').read())
# задаем путь к иконке приложения
window.setWindowIcon(QIcon('img/icon.ico'))
# отображаем окно
window.show()
# инициализируем дополнительные элементы GUI
initUI()
# запускаем приложение
sys.exit(app.exec_())