wkaisertexas / tiktok-uploader

Automatically ⬆️ upload TikTok videos
https://pypi.org/project/tiktok-uploader/
MIT License
390 stars 91 forks source link

How to upload videos from directory ? #56

Closed RedGeneral-X closed 1 year ago

RedGeneral-X commented 1 year ago

Which file to edit to upload multiples video from directory

csrgxtu commented 1 year ago

you mean you have couple of videos located in a directory, and you want to upload all the videos in that directory?

RedGeneral-X commented 1 year ago

Yes please I made this code work but it's stop in second video upload .... import sys import os from PyQt5.QtWidgets import ( QApplication, QMainWindow, QWidget, QVBoxLayout, QPushButton, QFileDialog, QTextEdit, QLabel, ) from tiktok_uploader.upload import upload_videos from tiktok_uploader.auth import AuthBackend

class VideoUploaderApp(QMainWindow): def init(self): super().init()

    self.init_ui()

def init_ui(self):
    self.setWindowTitle("Video Uploader")
    self.setGeometry(100, 100, 800, 600)

    self.central_widget = QWidget(self)
    self.setCentralWidget(self.central_widget)

    self.layout = QVBoxLayout()

    self.upload_button = QPushButton("Upload Videos")
    self.upload_button.clicked.connect(self.upload_videos)
    self.layout.addWidget(self.upload_button)

    self.select_cookies_button = QPushButton("Select Cookies")
    self.select_cookies_button.clicked.connect(self.select_cookies_file)
    self.layout.addWidget(self.select_cookies_button)

    self.video_paths = []
    self.cookies_file_path = None

    self.log_label = QLabel("Log:")
    self.layout.addWidget(self.log_label)

    self.log_text = QTextEdit()
    self.layout.addWidget(self.log_text)

    self.central_widget.setLayout(self.layout)

def select_cookies_file(self):
    options = QFileDialog.Options()
    options |= QFileDialog.ReadOnly

    file_dialog = QFileDialog()
    file_dialog.setFileMode(QFileDialog.ExistingFiles)
    file_dialog.setNameFilter("Text Files (*.txt)")
    selected_files, _ = file_dialog.getOpenFileNames(self, "Select Cookies File", "", options=options)

    if selected_files:
        self.cookies_file_path = selected_files[0]
        self.log_text.clear()
        self.log_text.append("Selected Cookies File:")
        self.log_text.append(self.cookies_file_path)

def upload_videos(self):
    if not self.cookies_file_path:
        self.log_text.clear()
        self.log_text.append("Please select the cookies file.")
        return

    options = QFileDialog.Options()
    options |= QFileDialog.ReadOnly

    file_dialog = QFileDialog()
    file_dialog.setFileMode(QFileDialog.ExistingFiles)
    file_dialog.setNameFilter("Video Files (*.mp4 *.avi *.mov *.mkv)")
    selected_files, _ = file_dialog.getOpenFileNames(self, "Select Videos to Upload", "", options=options)

    if selected_files:
        self.video_paths = selected_files
        self.log_text.clear()
        self.log_text.append("Selected Videos:")
        for path in self.video_paths:
            self.log_text.append(path)

        auth = AuthBackend(cookies=self.cookies_file_path)

        videos = [{"path": path} for path in self.video_paths]

        failed = upload_videos(videos, auth=auth)

        if failed:
            self.log_text.append("\nUpload Failed for the Following Videos:")
            for video in failed:
                self.log_text.append(video["path"])
        else:
            self.log_text.append("\nAll Videos Uploaded Successfully!")

def main(): app = QApplication(sys.argv) window = VideoUploaderApp() window.show() sys.exit(app.exec_())

if name == "main": main()