forked from Taysser-Gherfal/YouTube-Download
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathView.py
More file actions
106 lines (84 loc) · 3.38 KB
/
Copy pathView.py
File metadata and controls
106 lines (84 loc) · 3.38 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
from PyQt5 import QtWidgets as qtw
from PyQt5 import QtGui as qtg
from PyQt5 import QtCore as qtc
import datetime
class View(qtw.QWidget):
pasted = qtc.pyqtSignal(str)
submitted = qtc.pyqtSignal(str, str, str, int)
play_url = qtc.pyqtSignal(str)
def __init__(self):
super().__init__()
# Main UI code
self.url = qtw.QLineEdit()
self.url.setToolTip("URL")
self.folder = qtw.QLineEdit()
self.folder.setReadOnly(True)
download_button = qtw.QPushButton("Download", self)
play_button = qtw.QPushButton("Play", self)
folder_button = qtw.QPushButton("...", self)
#folder_button.setMaximumWidth(60)
#folder_button.setMaximumHeight(30)
#play_button.setMaximumWidth(60)
#play_button.setMaximumHeight(30)
#self.spin_box = qtw.QDial()
self.combo_box = qtw.QComboBox()
self.lable = qtw.QLabel()
self.progress = qtw.QProgressBar()
self.text = qtw.QTextBrowser()
# Main UI layout
layout = qtw.QGridLayout()
self.setLayout(layout)
# Right col layout
right_layout = qtw.QVBoxLayout()
layout.addLayout(right_layout, 0, 1)
# Left col layout
left_layout = qtw.QFormLayout()
layout.addLayout(left_layout, 0, 0)
left_layout.addRow("YouTube URL:", self.url)
left_layout.addRow("Download Options:", self.combo_box)
left_layout.addRow("Video Description:", self.text)
left_layout.addRow("Folder Location:", self.folder)
# Adding widgets to the main UI
layout.addWidget(download_button, 2, 1)
layout.addWidget(self.progress, 2, 0)
# Adding widgets to the right col
right_layout.addWidget(self.lable)
right_layout.addWidget(play_button)
right_layout.addWidget(folder_button)
self.lable.setAlignment(qtc.Qt.AlignTop)
# Setting lable text
self.lable.setText("Status...")
# Connecting the download button and the URL change
download_button.clicked.connect(self.download)
self.url.textChanged.connect(self.get_preview)
folder_button.clicked.connect(self.openFolder)
play_button.clicked.connect(self.play)
def openFolder(self):
loc = qtw.QFileDialog.getExistingDirectory(self, "Select Directory")
self.folder.setText(loc)
def download(self):
url = self.url.text()
folder = str(self.folder.text())
library = self.lable.text()
selected = self.combo_box.currentIndex()
self.submitted.emit(url, folder, library, selected)
def play(self):
url = self.url.text()
self.play_url.emit(url)
def show_status(self, status):
self.progress.setValue(status)
def get_preview(self):
url = str(self.url.text())
self.pasted.emit(url)
def show_preview(self, video_data):
self.progress.reset()
time = datetime.timedelta(minutes= video_data["length"])
print(time)
try:
left, right = str(time).split('.')
except:
left = str(time)
self.text.setText("Length: " + left + "\n\n" + "Title: " + video_data["title"] + "\n\n" + "Description: " + video_data["description"])
self.lable.setText(video_data["status"])
self.combo_box.clear()
self.combo_box.addItems(video_data["items"])