Advertisement
Dynamic_Fantasy

GUI_pyqt6

Aug 3rd, 2023 (edited)
1,054
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.69 KB | None | 0 0
  1. from PyQt6.QtWidgets import QApplication , QWidget , QPushButton ,QHBoxLayout ,QLineEdit
  2. from PyQt6.QtGui import QFont , QIcon
  3. #import pyautogui as p
  4. import pytube   #added on <8/5/2023>
  5. import os       #added on <8/5/2023>
  6. import time as t
  7.  
  8. '''all the dates ihv used below are MM/DD/YYYY format'''
  9. #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  
  10. #to acc wrap my head around pyqt6 let alone youtube module lol   <8/3/2023>
  11. #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>
  12.  
  13. '''Whats new??                                                                           <8/5/2023'''
  14.  
  15. '''just added pytube and os module to this code so yeah we dont rlly hafta use pyautogui'''
  16.  
  17.  
  18.  
  19. class window(QWidget):
  20.     def __init__(self):
  21.         super().__init__()
  22.         self.setWindowTitle("YouTube Downloader")
  23.         self.hbx()    #calling the hbx
  24.         self.setGeometry(400,100,400,400)
  25.         self.setStyleSheet("background-color:#101010")       #sets up universal background color
  26.  
  27.  
  28.  
  29.  
  30.  
  31.     def hbx(self):
  32.         hbox = QHBoxLayout(self)    #horizontal widget alignment
  33.  
  34.         self.entry = QLineEdit()
  35.         self.entry.setPlaceholderText(" "+'Enter your link')
  36.         self.entry.setFont(QFont("Calibri",19))
  37.        
  38.         ''' Entry widget with a bit of css properties'''
  39.        
  40.         self.entry.setStyleSheet("""    
  41.  
  42.        QLineEdit{
  43.                background-color :#171717 ;
  44.                color :#f3f3f3;
  45.                height : 50px;
  46.                width : 100px;
  47.                border-radius : 25px;
  48.                border : none ;                
  49.        }
  50.        QLineEdit:hover{
  51.                border: 1px solid #d128a6;
  52.                                
  53.        }
  54.  
  55.  
  56.  
  57.  
  58.        """)
  59.  
  60.         btn = QPushButton("Download")    #setting up a button
  61.         btn.clicked.connect(self.click)
  62.         btn.setFont(QFont("Calibri",16))      
  63.        
  64.        
  65.         #adding css properties to the button
  66.        
  67.         btn.setStyleSheet("""
  68.        
  69.            QPushButton {
  70.                background-color: #9603a3;
  71.                color: white;
  72.                height : 50px;
  73.                width : 100px;
  74.                border: none;
  75.                border-radius: 20px;  
  76.            }
  77.            QPushButton:hover {
  78.                background-color: #871bec;
  79.            }
  80.            QPushButton:focus {
  81.                background-color: #871bec;
  82.            }
  83.            """)
  84.         hbox.addWidget(self.entry)
  85.  
  86.         hbox.addWidget(btn)
  87.  
  88.         self.setLayout(hbox)
  89.  
  90.     #made few changes to my code <8/5/2023>
  91.  
  92. #have added a new function "def download_video" which then gets triggered whenever download button is clicked
  93.  
  94.     def download_video(self,url, output_path):           '''added on 8/5/2023'''           '''MM/DD/YYYY'''
  95.         try:
  96.             yt = YouTube(url)
  97.             video = yt.streams.get_highest_resolution()
  98.            
  99.             print(f"Downloading: {yt.title}")
  100.             video.download(output_path)
  101.             print("Download completed!")
  102.         except Exception as e:
  103.             print("Error:", e)
  104.  
  105.  
  106.     def click(self):     '''added on 8/5/2023'''
  107.         link =self.entry.text()
  108.         user_name=os.getlogin()    #looks up for current user name
  109.        
  110.         path=rf"C:\Users\{user_name}\OneDrive\Desktop\youtube"         #or you could add your own directory
  111.        
  112.         self.download_video(link,path)
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130. app = QApplication([])  
  131. app_ =window()
  132. app_.show()        
  133.  
  134. app.exec()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement