-
Notifications
You must be signed in to change notification settings - Fork 0
/
youPyDownloader.py
90 lines (68 loc) · 2.47 KB
/
youPyDownloader.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
import pyforms
from pyforms.basewidget import BaseWidget
from pyforms.controls import ControlText
from pyforms.controls import ControlButton
from pyforms.controls import ControlTextArea
from pyforms.controls import ControlLabel
import sys
from pytube import YouTube
from databaseConnection import Base, engine,Session
from downloadedModel import Downloaded
Base.metadata.create_all(engine)
session = Session()
class youPyDownloader(BaseWidget):
def __init__(self):
super(youPyDownloader,self).__init__('youtube downloader')
#definatino of forms fields
self._videoUrl = ControlText('Video Url')
self._button = ControlButton('View Details')
self._details = ControlTextArea("Details")
self._downloadButton = ControlButton("Download")
self._downloadCompleted = ControlLabel(" ")
self._button.value = self.__buttonAction
self._downloadButton.value = self.__downloadAction
self.formset = [ ('_videoUrl'), '_button', '_details', '_downloadButton' ,'_downloadCompleted']
#The ' ' is used to indicate that a empty space should be placed at the bottom of the window
#If you remove the ' ' the forms will occupy the entire window
self.mainmenu = [
{ 'File': [
{"Downloaded Files": self.__viewDownloaded},
{'About': self.__about},
'-',
{'Quit': self.__quit}
]
}
]
def __viewDownloaded(self):
...
def __about(self):
...
def __quit(self):
try:
session.commit()
session.close()
sys.exit()
except:
sys.exit()
def __downloadAction(self):
yt = self.__getDetails()
stream = yt.streams.filter(progressive = True).first()
stream.download()
video = Downloaded(yt.title)
print("downloaded - " + yt.title)
session.add(video)
session.commit()
session.close()
self._downloadCompleted.value = "Download Completed!!"
print("Download completed!!")
def __buttonAction(self):
yt = self.__getDetails()
print(self._videoUrl.value)
self._details.value = "\nVideo title - "+ yt.title
def __getDetails(self):
self._downloadCompleted.value = " "
yt = YouTube(self._videoUrl.value)
# print(yt.title)
return yt
if __name__ == "__main__":
pyforms.start_app(youPyDownloader)