Moviepy 在 PyQt5 网络浏览器中制作字母两次

问题描述

我从 pyqt5 制作了一个网络浏览器,并通过使用 moviepypytube 制作功能添加了将 YouTube 视频作为音频或视频下载到所需文件夹中的功能。但是,当我导入 moviepy 模块(通过反复试验发现)并运行该程序时,因此我在 youtube 的搜索框中(也在 urlbar 中)中输入的任何字母似乎是两次并且删除键停止工作。没有moviepy它工作正常。另外我如何在 mac 中制作这个 python 文件的独立应用程序。

我的代码

from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import *
import os
import sys
import pytube
from pytube.cli import on_progress
from moviepy.editor import VideoFileClip
import io


class browser(QMainWindow):
    def __init__(self):
        super(browser,self).__init__()

        self.browser = QWebEngineView()
        self.browser.setUrl(QUrl('https://www.youtube.com/'))
        self.browser.urlChanged.connect(self.update_urlbar)
        self.browser.loadFinished.connect(self.update_title)
        self.setCentralWidget(self.browser)
        self.status = QStatusBar()
        self.setStatusBar(self.status)

        navtb = qtoolbar("Navigation")
        self.addToolBar(navtb)

        back_btn = QAction("Back",self)
        back_btn.setStatusTip("Back to prevIoUs page")

        back_btn.triggered.connect(self.browser.back)

        navtb.addAction(back_btn)

        next_btn = QAction("Forward",self)
        next_btn.setStatusTip("Forward to next page")

        next_btn.triggered.connect(self.browser.forward)
        navtb.addAction(next_btn)

        reload_btn = QAction("Reload",self)
        reload_btn.setStatusTip("Reload page")

        reload_btn.triggered.connect(self.browser.reload)
        navtb.addAction(reload_btn)

        home_btn = QAction("Home",self)
        home_btn.setStatusTip("Go home")
        home_btn.triggered.connect(self.navigate_home)
        navtb.addAction(home_btn)

        navtb.addSeparator()

        self.urlbar = QLineEdit()
        self.urlbar.returnpressed.connect(self.navigate_to_url)

        navtb.addWidget(self.urlbar)

        stop_btn = QAction("Stop",self)
        stop_btn.setStatusTip("Stop loading current page")

        stop_btn.triggered.connect(self.browser.stop)
        navtb.addAction(stop_btn)

        # download video
        videodownload = QAction("Download Video",self)
        videodownload.setStatusTip("Downloads Video")

        videodownload.triggered.connect(self.download_video)
        navtb.addAction(videodownload)

        # Download song
        audioDownload = QAction("Download Audio",self)
        audioDownload.setStatusTip("Downloads audio")

        audioDownload.triggered.connect(self.audio_download)
        navtb.addAction(audioDownload)

    def update_title(self):
        title = self.browser.page().title()
        self.setwindowTitle(title + "- Tanmay's browser")

    def navigate_home(self):
        self.browser.setUrl(QUrl("http://www.google.com"))

    def navigate_to_url(self):
        q = QUrl(self.urlbar.text())

        if q.scheme() == "":
            q.setScheme("http")

        self.browser.setUrl(q)

    def update_urlbar(self,q):

        self.urlbar.setText(q.toString())
        self.urlbar.setCursorPosition(0)

    def download_video(self):
        vid_url = self.urlbar.text()
        dialog = QFileDialog()
        dialog.setFileMode(QFileDialog.DirectoryOnly)
        if dialog.exec_():
            foldername = dialog.selectedFiles()[0]
            print(foldername)
            self.ytd(vid_url,foldername)


    def audio_download(self):
        aud_url = self.urlbar.text()
        dialog = QFileDialog()
        dialog.setFileMode(QFileDialog.DirectoryOnly)
        if dialog.exec_():
            foldername = dialog.selectedFiles()[0]
            print(foldername)
            self.ytmp3(aud_url,foldername)

    def vider_downloader(self,url):
        yt = pytube.YouTube(url,on_progress_callback=on_progress)
        stream = yt.streams.filter(progressive=True)
        with io.BytesIO() as buffer:
            path = stream[0].download(stream[0].stream_to_buffer(buffer))
            return path,stream[0].title

    def ytmp3(self,url,path):
        path_to_video,title = self.vider_downloader(url)
        file = VideoFileClip(path_to_video)
        file.audio.write_audiofile(path + title + '.mp3')
        os.remove(path_to_video)

    def ytd(self,path):
        yt = pytube.YouTube(url,on_progress_callback=on_progress)
        stream = yt.streams.filter(progressive=True)
        for a,b in enumerate(list(stream)):
            print(f'Press {a} for {b}')

        cho = int(input())
        stream[cho].download(path + stream[0].title + '.mp4')

if __name__ == '__main__':
    app = QApplication(sys.argv)
    app.setApplicationName("Tanmay's browser")

    window = browser()
    window.show()
    app.exec_()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...