Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PyQt6.QtWidgets import QApplication , QWidget , QPushButton ,QHBoxLayout ,QLineEdit
- from PyQt6.QtGui import QFont , QIcon
- #import pyautogui as p
- import pytube #added on <8/5/2023>
- import os #added on <8/5/2023>
- import time as t
- '''all the dates ihv used below are MM/DD/YYYY format'''
- #This is not exactly what i intended to create tho it works perfectly fine for now and yeah its gonna take me a crazy amount of time to
- #to acc wrap my head around pyqt6 let alone youtube module lol <8/3/2023>
- #you can use it whatever the way you feel like make sure you change the logic inside the "def click" you could use youtube module as well <8/3/2023>
- '''Whats new?? <8/5/2023'''
- '''just added pytube and os module to this code so yeah we dont rlly hafta use pyautogui'''
- class window(QWidget):
- def __init__(self):
- super().__init__()
- self.setWindowTitle("YouTube Downloader")
- self.hbx() #calling the hbx
- self.setGeometry(400,100,400,400)
- self.setStyleSheet("background-color:#101010") #sets up universal background color
- def hbx(self):
- hbox = QHBoxLayout(self) #horizontal widget alignment
- self.entry = QLineEdit()
- self.entry.setPlaceholderText(" "+'Enter your link')
- self.entry.setFont(QFont("Calibri",19))
- ''' Entry widget with a bit of css properties'''
- self.entry.setStyleSheet("""
- QLineEdit{
- background-color :#171717 ;
- color :#f3f3f3;
- height : 50px;
- width : 100px;
- border-radius : 25px;
- border : none ;
- }
- QLineEdit:hover{
- border: 1px solid #d128a6;
- }
- """)
- btn = QPushButton("Download") #setting up a button
- btn.clicked.connect(self.click)
- btn.setFont(QFont("Calibri",16))
- #adding css properties to the button
- btn.setStyleSheet("""
- QPushButton {
- background-color: #9603a3;
- color: white;
- height : 50px;
- width : 100px;
- border: none;
- border-radius: 20px;
- }
- QPushButton:hover {
- background-color: #871bec;
- }
- QPushButton:focus {
- background-color: #871bec;
- }
- """)
- hbox.addWidget(self.entry)
- hbox.addWidget(btn)
- self.setLayout(hbox)
- #made few changes to my code <8/5/2023>
- #have added a new function "def download_video" which then gets triggered whenever download button is clicked
- def download_video(self,url, output_path): '''added on 8/5/2023''' '''MM/DD/YYYY'''
- try:
- yt = YouTube(url)
- video = yt.streams.get_highest_resolution()
- print(f"Downloading: {yt.title}")
- video.download(output_path)
- print("Download completed!")
- except Exception as e:
- print("Error:", e)
- def click(self): '''added on 8/5/2023'''
- link =self.entry.text()
- user_name=os.getlogin() #looks up for current user name
- path=rf"C:\Users\{user_name}\OneDrive\Desktop\youtube" #or you could add your own directory
- self.download_video(link,path)
- app = QApplication([])
- app_ =window()
- app_.show()
- app.exec()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement