-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdownloud_app.py
More file actions
113 lines (93 loc) · 3.64 KB
/
Copy pathdownloud_app.py
File metadata and controls
113 lines (93 loc) · 3.64 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
from PyQt5 import QtWidgets
from PyQt5 import QtCore
from PyQt5 import QtGui
from PyQt5 import uic
from PyQt5.QtWidgets import QFileDialog
import os
from os import path
import sys
import urllib.request
from PyQt5.QtWidgets import QMessageBox
import pafy
import humanize
class MainApp(QtWidgets.QMainWindow):
def __init__(self):
super(MainApp, self).__init__()
uic.loadUi('main.ui', self)
self.handel_ui()
self.handel_button()
def handel_ui(self):
self.setWindowTitle("MH Downloud ")
self.setFixedSize(600, 330)
def handel_browes(self):
save_location = QFileDialog.getSaveFileName(
self, caption="Save as", directory=".", filter="All Files(*.*)")
print(save_location)
self.lineEdit_2.setText(str(save_location[0]))
def handel_button(self):
self.pushButton_2.clicked.connect(self.downloud)
self.pushButton.clicked.connect(self.handel_browes)
self.pushButton_5.clicked.connect(self.Get_Video_Data)
self.pushButton_4.clicked.connect(self.Download_Video)
self.pushButton_3.clicked.connect(self.Save_Browse)
def handel_progres(self, blocknum, blocksize, totalsize):
readed_data = blocknum * blocksize
if totalsize > 0:
download_percentage = readed_data * 100 / totalsize
self.progressBar.setValue(download_percentage)
# QApplication.processEvents()
def downloud(self):
url = self.lineEdit.text()
save_location = self.lineEdit_2.text()
try:
urllib.request.urlretrieve(
url, save_location, self.handel_progres)
except Exception:
QMessageBox.information(self, "Error Massege", "Downloud faild")
return
QMessageBox.information(self, "Downloud Compled", "Finsh Downloud")
self.lineEdit.setText('')
self.lineEdit_2.setText('')
self.progressBar.setValue(0)
def Save_Browse(self):
# save location in the line edit
save_location = QFileDialog.getSaveFileName(
self, caption="Save as", directory=".", filter="All Files(*.*)")
self.lineEdit_3.setText(str(save_location[0]))
def Get_Video_Data(self):
video_url = self.lineEdit_4.text()
print(video_url)
if video_url == '':
QMessageBox.warning(self, "Data Error",
"Provide a valid Video URL")
else:
video = pafy.new(video_url)
print(video.title)
print(video.duration)
print(video.author)
print(video.length)
print(video.viewcount)
print(video.likes)
print(video.dislikes)
video_streams = video.videostreams
for stream in video_streams:
print(stream.get_filesize())
size = humanize.naturalsize(stream.get_filesize())
data = "{} {} {} {}".format(
stream.mediatype, stream.extension, stream.quality, size)
self.comboBox.addItem(data)
def Download_Video(self):
video_url = self.lineEdit_4.text()
save_location = self.lineEdit_3.text()
video = pafy.new(video_url)
video_stream = video.videostreams
video_quality = self.comboBox.currentIndex()
download = video_stream[video_quality].download(
filepath=save_location)
def main():
app = QtWidgets.QApplication(sys.argv)
window = MainApp()
window.show()
app.exec_()
if __name__ == '__main__':
main()