Skip to content

Instantly share code, notes, and snippets.

@Ryoliveira
Created April 18, 2018 04:56
Show Gist options
  • Save Ryoliveira/f4bcb90fa65eac989ffa03ee396e2410 to your computer and use it in GitHub Desktop.
Save Ryoliveira/f4bcb90fa65eac989ffa03ee396e2410 to your computer and use it in GitHub Desktop.
from pytube import YouTube
from PyQt5 import QtWidgets
from PyQt5 import QtGui
from PyQt5 import QtCore
import os
import sys
class MainWindow(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
self.setWindowTitle('YouDownload')
self.setFixedSize(475, 300)
# Main title
title_font = QtGui.QFont('Times', 24, QtGui.QFont.Bold)
self.title = QtWidgets.QLabel("YouDownload")
self.title.setFont(title_font)
self.title.setAlignment(QtCore.Qt.AlignBottom)
# Play button image
self.play_button = QtWidgets.QLabel()
self.play_button.setPixmap(QtGui.QPixmap('playbutton.png'))
title_frame = QtWidgets.QHBoxLayout()
title_frame.addWidget(self.title)
title_frame.addStretch()
title_frame.addWidget(self.play_button)
title_frame.addStretch()
#Entry box for youtube link
self.video_link_entry = QtWidgets.QLineEdit()
self.video_entry_text = QtWidgets.QLabel('Video Link:')
# Frame for youtube link entry
video_link_frame = QtWidgets.QHBoxLayout()
video_link_frame.addWidget(self.video_entry_text)
video_link_frame.addWidget(self.video_link_entry)
video_link_frame.insertSpacing(2,50)
# Download Button
self.download_button = QtWidgets.QPushButton("Download")
self.download_button.clicked.connect(self.download)
download_button_frame = QtWidgets.QHBoxLayout()
download_button_frame.addWidget(self.download_button)
download_button_frame.addStretch()
# Save destination
self.path_label = QtWidgets.QLabel("Download Destination:")
self.path_var = os.path.expanduser('~')
self.path_destination = QtWidgets.QLabel()
self.path_destination.setText(self.path_var)
save_path_frame = QtWidgets.QHBoxLayout()
save_path_frame.addWidget(self.path_label)
save_path_frame.addWidget(self.path_destination)
save_path_frame.addStretch()
# Change dir button
self.changedir_button = QtWidgets.QPushButton("Change Dir")
self.changedir_button.clicked.connect(self.change_save_path)
changedir_frame = QtWidgets.QHBoxLayout()
changedir_frame.addWidget(self.changedir_button)
changedir_frame.addStretch()
# progress bar
self.progress = QtWidgets.QProgressBar()
self.testbutton = QtWidgets.QPushButton('Test download')
self.testbutton.clicked.connect(self.downloadTest)
# Main layout of window
main_window_frame = QtWidgets.QVBoxLayout()
main_window_frame.addLayout(title_frame)
main_window_frame.insertSpacing(1, 15)
main_window_frame.addLayout(video_link_frame)
main_window_frame.addLayout(download_button_frame)
main_window_frame.addLayout(save_path_frame)
main_window_frame.addLayout(changedir_frame)
main_window_frame.addWidget(self.progress)
main_window_frame.addWidget(self.testbutton)
self.setLayout(main_window_frame)
self.show()
def change_save_path(self):
file = str(QtWidgets.QFileDialog.getExistingDirectory(self, "Select Directory"))
self.path_destination.setText(file)
def download(self):
video = YouTube(self.video_link_entry.text()).streams.first()
video.download(self.path_destination.text())
def downloadTest(self):
self.completed = 0
while self.completed < 100:
self.completed += 0.0001
self.progress.setValue(self.completed)
app = QtWidgets.QApplication(sys.argv)
window = MainWindow()
app.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment