-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.py
294 lines (253 loc) · 10.2 KB
/
index.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
import humanize
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
import sys
import os
import os.path
from PyQt5.uic import loadUiType
import urllib.request
from pafy import *
ui, _ = loadUiType('D:/backup/Desktop/DeskFiles/pydesign/main.ui')
class mainApp(QMainWindow, ui):
def __init__(self, parent=None):
super(mainApp, self).__init__(parent)
QMainWindow.__init__(self)
self.setupUi(self)
self.IniUI()
self.handelButtons()
def IniUI(self):
# contain all ui changes in loading
# self.tabWidget.tabBar().setVisible(False)
self.animation()
pass
def handelButtons(self):
# handel all buttons in tha app
self.downloadOther.clicked.connect(self.download)
self.borwseOther.clicked.connect(self.handelBrowse)
self.gitsingledata.clicked.connect(self.getVideoDate)
self.singleb.clicked.connect(self.saveBrowes)
self.singleD.clicked.connect(self.DownloadVideo)
self.playB.clicked.connect(self.playbrowse)
self.playD.clicked.connect(self.downloadPlayList)
self.home.clicked.connect(self.gohome)
self.home.clicked.connect(self.animation)
self.down.clicked.connect(self.godown)
self.you.clicked.connect(self.goyou)
self.setting.clicked.connect(self.gosetting)
self.pushButton_2.clicked.connect(self.dark)
self.pushButton.clicked.connect(self.defaul)
self.pushButton_3.clicked.connect(self.blue)
# pass
def handelProgressBar(self, blocnum, blocksize, totalsize):
readedData = blocnum*blocksize
if totalsize > 0:
downloadPercentage = readedData*100/totalsize
self.OtherprogressBar.setValue(downloadPercentage)
QApplication.processEvents()
# calculate the progressing
# pass
def handelBrowse(self):
saveLocation = QFileDialog.getSaveFileName(
self, caption="save as", directory=".", filter="all files(*.*)")
self.otherLocation.setText(str(saveLocation[0]))
# pick save location
# pass
def download(self):
# print(1)
url = self.otherUrl.text()
saveLocation = self.otherLocation.text()
if url == "" or saveLocation == "":
# self.errormsg.setText("there is no url or location")
QMessageBox.warning(
self, "Error", "there is no url or location please enter the url and save location")
else:
try:
urllib.request.urlretrieve(
url, saveLocation, self.handelProgressBar)
# pass
except Exception:
QMessageBox.warning(self, "Download Error", "Un_vaild url")
return
QMessageBox.information(
self, "Download Compelete", "The Download Compelete Successfully")
self.OtherprogressBar.setValue(0)
self.otherUrl.setText("")
self.otherLocation.setText("")
def saveBrowes(self):
# save location on line edit
pass
# youtube download single video
def saveBrowes(self):
# save location on line edit
saveLocation = QFileDialog.getSaveFileName(
self, caption="save as", directory=".", filter="all files(*.*)")
self.singlelocation.setText(str(saveLocation[0]))
# pass
def getVideoDate(self):
videourl = self.singleurl.text()
videoSaveLocation = self.singlelocation.text()
if videourl == "" or videoSaveLocation == "":
QMessageBox.warning(
self, "Error", "there is no url or location please enter the url and save location")
else:
video = pafy.new(videourl)
print(video.title)
print(video.duration)
video_qulaity = video.videostreams
for q in video_qulaity:
size = humanize.naturalsize(q.get_filesize())
data = "{} {} {} {}".format(
q.mediatype, q.extension, q.quality, size)
self.singlecombo.addItem(data)
# pass
def DownloadVideo(self):
print("here")
video_url_s = self.singleurl.text()
save_location_s = self.singlelocation.text()
if video_url_s == "" or save_location_s == "":
# self.errormsg.setText("there is no url or location")
QMessageBox.warning(
self, "Error", "there is no url or location please enter the url and save location")
else:
video = pafy.new(video_url_s)
videostream = video.videostreams
print(videostream)
videoquality = self.singlecombo.currentIndex()
print(videoquality)
download = videostream[videoquality].download(
filepath=save_location_s, callback=self.videoPROGRESS)
try:
urllib.request.urlretrieve(
video_url_s, save_location_s, self.handelProgressBar)
QMessageBox.information(
self, "Download Compelete", "The Download Compelete Successfully")
self.singlecombo.clear()
# pass
except Exception:
QMessageBox.warning(self, "Download Error", "Un_vaild url")
return
self.singlebar.setValue(0)
self.singleurl.setText("")
self.singlelocation.setText("")
self.downloaded.setText("")
self.rate.setText("")
self.time.setText("")
# pass
def videoPROGRESS(self, total, received, ratio, rate, time):
if total > 0:
self.singlebar.setValue(ratio*100)
self.downloaded.setText(
str("Downloaded : {}".format(humanize.naturalsize(received))))
self.rate.setText(
str("Rate : {}".format(humanize.naturalsize(rate))))
self.time.setText(
str("Time remaining : {}".format((time))))
QApplication.processEvents()
# pass
# youtube playlist
def downloadPlayList(self):
urlp = self.playurl.text()
location = self.playloc.text()
if urlp == "" or location == "":
QMessageBox.warning(
self, "Error", "there is no url or location please enter the url and save location")
else:
import pafy
playlistt = pafy.get_playlist(urlp)
self.lcdNumber_2.display(len(playlistt['items']))
os.chdir(location)
if os.path.exists(str(playlistt['title'])):
os.chdir(str(playlistt['title']))
else:
os.mkdir(str(playlistt['title']))
os.chdir(str(playlistt['title']))
current_video_in_download = 0
qulaityplaylist = self.playquality.currentIndex()
self.lcdNumber.display(current_video_in_download)
self.lcdNumber_3.display(
len(playlistt['items'])-current_video_in_download)
for v in playlistt['items']:
current_video = v['pafy']
current_stream = current_video.videostreams
download = current_stream[qulaityplaylist].download(
callback=self.playprogress)
current_video_in_download += 1
self.lcdNumber.display(current_video_in_download)
self.lcdNumber_3.display(
len(playlistt['items'])-current_video_in_download)
QMessageBox.information(
self, 'Compelete', "Download Compelet successfuly")
self.lcdNumber.display(0)
self.lcdNumber_2.display(0)
self.lcdNumber_3.display(0)
self.playurl.setText("")
self.playloc.setText("")
self.playbar.setValue(0)
self.label_4.setText("")
self.label_5.setText("")
self.label_6.setText("")
def playprogress(self, total, received, ratio, rate, time):
if total > 0:
self.playbar.setValue(ratio*100)
self.label_4.setText(
str("Downloaded : {}".format(humanize.naturalsize(received))))
self.label_5.setText(
str("Rate : {}".format(humanize.naturalsize(rate))))
self.label_6.setText(
str("Time remaining : {}".format((time))))
QApplication.processEvents()
# pass
def playbrowse(self):
se = QFileDialog().getExistingDirectory()
self.playloc.setText(str(se))
def gohome(self):
self.tabWidget.setCurrentIndex(0)
def godown(self):
self.tabWidget.setCurrentIndex(1)
def goyou(self):
self.tabWidget.setCurrentIndex(2)
def gosetting(self):
self.tabWidget.setCurrentIndex(3)
def dark(self):
style = open('D:/backup/Desktop/DeskFiles/pydesign/themes/dark.css', 'r')
style = style.read()
self.setStyleSheet(style)
def blue(self):
style = open('D:/backup/Desktop/DeskFiles/pydesign/themes/blue.css', 'r')
style = style.read()
self.setStyleSheet(style)
def defaul(self):
self.setStyleSheet(None)
def animation(self):
box1 = QPropertyAnimation(self.groupBox, b"geometry")
box1.setDuration(1000)
box1.setStartValue(QRect(0, 0, 0, 0))
box1.setEndValue(QRect(60, 40, 271, 181))
box1.start()
self.box1 = box1
box2 = QPropertyAnimation(self.groupBox_2, b"geometry")
box2.setDuration(1000)
box2.setStartValue(QRect(760, -160, 0, 0))
box2.setEndValue(QRect(420, 40, 271, 181))
box2.start()
self.box2 = box2
box3 = QPropertyAnimation(self.groupBox_3, b"geometry")
box3.setDuration(1000)
box3.setStartValue(QRect(-250, 470, 0, 0))
box3.setEndValue(QRect(60, 290, 271, 181))
box3.start()
self.box3 = box3
box4 = QPropertyAnimation(self.groupBox_4, b"geometry")
box4.setDuration(1000)
box4.setStartValue(QRect(730, 470, 0, 0))
box4.setEndValue(QRect(420, 290, 271, 181))
box4.start()
self.box4 = box4
def main():
app = QApplication(sys.argv)
window = mainApp()
window.show()
app.exec_()
if __name__ == "__main__":
main()