Certainly! Below is an example of a Python application using PyQt6 to create a simple GUI for downloading TikTok videos using yt-dlp.exe. This example assumes you have yt-dlp.exe and PyQt6 installed in your environment.
First, ensure you have the necessary packages installed:
bash
pip install pyqt6 yt-dlp
Here is the Python code for the application:
python
import sys
import subprocess
from PyQt6.QtWidgets import QApplication, QWidget, QVBoxLayout, QLineEdit, QPushButton, QLabel, QMessageBox
class TikTokDownloader(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setWindowTitle('TikTok Video Downloader')
self.setGeometry(100, 100, 400, 200)
layout = QVBoxLayout()
self.url_label = QLabel('Enter TikTok Video URL:', self)
layout.addWidget(self.url_label)
self.url_input = QLineEdit(self)
layout.addWidget(self.url_input)
self.download_button = QPushButton('Download', self)
self.download_button.clicked.connect(self.download_video)
layout.addWidget(self.download_button)
self.setLayout(layout)
def download_video(self):
url = self.url_input.text()
if not url:
QMessageBox.warning(self, 'Input Error', 'Please enter a valid URL')
return
try:
subprocess.run(['yt-dlp.exe', url], check=True)
QMessageBox.information(self, 'Download Complete', 'Video downloaded successfully')
except subprocess.CalledProcessError as e:
QMessageBox.critical(self, 'Download Error', f'Failed to download video: {e}')
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = TikTokDownloader()
ex.show()
sys.exit(app.exec())
Explanation:
Imports: Import necessary modules from PyQt6 and subprocess.
TikTokDownloader Class: This class inherits from QWidget and sets up the GUI.
initUI Method: Initializes the UI components like labels, input field, and button.
download_video Method: This method is called when the download button is clicked. It retrieves the URL from the input field, validates it, and uses subprocess.run to call yt-dlp.exe to download the video.
Main Block: Creates an instance of the QApplication, initializes the TikTokDownloader widget, and starts the application loop.
Running the Application:
Save the code to a file, for example, tiktok_downloader.py, and run it using Python:
bash
python tiktok_downloader.py
This will open a simple GUI where you can enter a TikTok video URL and download the video using yt-dlp.exe.