pyqt5界面开发-制作程序集合桌面-完结篇

pyqt5界面开发-制作程序集合桌面-完结篇

实现的功能↓

  • Apps
  • 组件

实现的Apps

Apps 已/未完善
翻译 未完善
*讯vide*V(爬虫) 已完善
关机 已完善
电影播放器 已完善
计算器 已完善
寻找文件 已完善

实现的组件

组件 已/未完善
音乐播放 已完善
进度条 已完善
退出主程序按钮 已完善
回到主界面按钮 已完善

资源链接 :https://pan.baidu.com/s/1U23Z71tXqbQXIlVV_vXEHg
提取码:Te12

完整项目链接:https://pan.baidu.com/s/1scRuJox3ZUvsXRIYb95L7A
提取码:Te12

注意:
Video文件夹里的是我自己版本
我拿谷歌浏览器举例:点右上角的三个点,在下面找到设置-您与Google,查看谷歌浏览器版本,
到此处下载chromedriver.exe,把chromedriver.exe放到谷歌浏览器的安装目录下,添加环境变量,到此处下载browsermob-proxry包,然后替换掉我发的文件里Video里的文件夹

控制面板快捷键:win+R,输入control

项目完整源代码

import gc
import sys
import time
import os
import requests
import re
import multiprocessing
import pyquery
import cv2
import numpy as np
from moviepy.editor import *
from PyQt5 import QtCore, QtWidgets ,QtGui
from PyQt5.QtGui import *
from PyQt5.QtWidgets import QProgressBar, QLabel, QApplication, QMainWindow,QToolTip
from PyQt5.QtCore import QBasicTimer, QThread, pyqtSignal
from PyQt5.QtWidgets import *
from translate import Translator
os.environ["PYGAME_HIDE_SUPPORT_PROMPT"]="hide"
from pygame import mixer
from random import randint, shuffle
from selenium import webdriver
from browsermobproxy import Server
from selenium.webdriver.chrome.options import Options
from pyquery import PyQuery


class UI(QMainWindow,QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.sum = 0
        self.num = 0
        self.n = 0
        self.algorithmre = ''
        self.bClose = False
        self.init()
        self.main()

    def init(self):
        QToolTip.setFont(QFont('SansSerif', 10))

        self.resize(1000, 625)
        self.move(300, 300)

        self.setWindowFlags(QtCore.Qt.WindowMinimizeButtonHint)
        self.setFixedSize(self.width(), self.height())

        self.setWindowTitle('TArk-Tools')
        self.setWindowIcon(QIcon('./resource/img/eye.webp'))
        self.setIcon("./resource/img/bg1.jpg")

        self.win_offQL = QLabel(self)
        self.win_offQL.setGeometry(QtCore.QRect(970, 10, 21, 21))
        self.win_offQL.setStyleSheet("border-radius:10px;\n""background-color: rgb(170, 0, 0);")
        self.win_offQL.setText("")
        self.win_off = QPushButton(self)
        self.win_off.setGeometry(QtCore.QRect(970, 10, 21, 21))
        self.win_off.setCursor(QCursor(QtCore.Qt.PointingHandCursor))
        self.win_off.setStyleSheet("QPushButton{background:#ff5500;border-radius:10px;}QPushButton:hover{background:red;}")
        self.win_off.setText("")
        self.win_off.clicked.connect(sys.exit)


    def main(self):
        self.interface()

    #--------------------------*-----------------------

    def music(self):
        jc = multiprocessing.Process(target=play_music, daemon=True)

        global pid

        if self.music_of.text() == '开启':
            self.music_of.setText('关闭')
            jc.start()
            pid = jc.pid

        else:
            self.music_of.setText('开启')
            system = 'taskkill /pid ' + str(pid) + ' /f'
            os.popen(system, 'r')

    def wifi(self):
        if self.num == 0:
            pass
        else:
            self.wifise.hide()

        self.num += 1

        try:
            res = requests.get('https://www.baidu.com/')
        except:
            self.pix = QPixmap("./resource/img/No_Wifi.png")
            self.wifise = QLabel(self)
            self.wifise.setGeometry(750, 0, 30, 30)
            self.wifise.setPixmap(self.pix)
            self.wifise.setScaledContents(True)
            self.wifise.show()
        else:
            self.pix = QPixmap("./resource/img/Yes_Wifi.png")
            self.wifise = QLabel(self)
            self.wifise.setGeometry(750, 0, 30, 30)
            self.wifise.setPixmap(self.pix)
            self.wifise.setScaledContents(True)
            self.wifise.show()

    #--------------------------*-----------------------
    def interface(self):
        self.pbar = QProgressBar(self)
        self.pbar.setGeometry(300,400,450,25)

        self.button = QPushButton('START', self)
        self.button.move(450, 450)

        self.button.clicked.connect(self.onStart)
        self.timer = QBasicTimer()
        self.step = 0



    def timerEvent(self, event):
        if self.step >= 100:
            self.timer.stop()
            self.mainApp()
            return


        self.step = self.step + 1
        self.pbar.setValue(self.step)


    def onStart(self):
        if self.timer.isActive():
            self.timer.stop()
            self.button.setText('Start')
        else:
            self.timer.start(10, self)
            self.button.setText('Stop')

    #--------------------------*----------------------

    def mainApp(self):
        self.win_off.show()
        self.win_offQL.show()

        self.setFixedSize(1000, 625)

        self.wifi()

        y1 = 100

        self.hide1()
        self.setIcon("./resource/img/bg2.jpg")

        self.wifi_debug = QPushButton(self)
        self.wifi_debug.setGeometry(800,0,100,30)
        self.wifi_debug.setText("刷新wifi监测")
        self.wifi_debug.clicked.connect(self.wifi)
        self.wifi_debug.show()

        self.music_of = QPushButton(self)
        self.music_of.setGeometry(0, 0, 50, 30)
        self.music_of.setText("开启")
        self.music_of.clicked.connect(self.music)
        self.music_of.show()




        #翻译App
        self.app1 = QPushButton(self)
        self.app1.setIcon(QIcon('./resource/img/Fanyi.png'))
        self.app1.setIconSize(QtCore.QSize(100, 100))
        self.app1.setGeometry(50,y1,100,100)
        self.app1.clicked.connect(self.App1)
        self.app1.show()



        self.app1_name = QLabel(self)
        self.app1_name.setText("翻译")
        self.app1_name.move(85,y1+100)
        self.app1_name.show()

        def hide_plus1():
            try:
                res = requests.get("https://baidu.com/")
                flag = True
            except:
                flag = False

            if flag == True:
                self.music_of.hide()
                self.App2()
            else:
                self.app2.setIcon(QIcon("./resource/img/404.webp"))
                self.app2.setIconSize(QtCore.QSize(120,120))


        #腾讯视频VipApp
        self.app2 = QPushButton(self)
        self.app2.setIcon(QIcon("./resource/img/TengXun.webp"))
        self.app2.setIconSize(QtCore.QSize(120,120))
        self.app2.setGeometry(200,y1,100,100)
        self.app2.clicked.connect(hide_plus1)
        self.app2.show()

        self.app2_name = QLabel(self)
        self.app2_name.setText("腾讯视频VIP")
        self.app2_name.move(210,y1+100)
        self.app2_name.show()

        def hide_plus2():
            self.music_of.hide()
            self.App3()

        #关机App
        self.app3 = QPushButton(self)
        self.app3.setIcon(QIcon("./resource/img/shutdown.webp"))
        self.app3.setIconSize(QtCore.QSize(120,120))
        self.app3.setGeometry(350,y1,100,100)
        self.app3.clicked.connect(hide_plus2)
        self.app3.show()

        self.app3_name = QLabel(self)
        self.app3_name.setText("关机")
        self.app3_name.move(385,y1+100)
        self.app3_name.show()

        def hide_plus3():
            self.win_off.hide()
            self.win_offQL.hide()

            self.Eventhide()

            self.music_of.hide()
            self.App4()

        #电影播放器App
        self.app4 = QPushButton(self)
        self.app4.setIcon(QIcon("./resource/img/Video.webp"))
        self.app4.setIconSize(QtCore.QSize(120,120))
        self.app4.setGeometry(500,y1,100,100)
        self.app4.clicked.connect(hide_plus3)
        self.app4.show()

        self.app4_name = QLabel(self)
        self.app4_name.move(510,y1+100)
        self.app4_name.setText("电影播放器")
        self.app4_name.show()

        def hide_plus4():
            self.music_of.hide()
            self.App5()

        #计算器App
        self.app5 = QPushButton(self)
        self.app5.setIcon(QIcon("./resource/img/algorithm.webp"))
        self.app5.setIconSize(QtCore.QSize(120,120))
        self.app5.setGeometry(650,y1,100,100)
        self.app5.clicked.connect(hide_plus4)
        self.app5.show()

        self.app5_name = QLabel(self)
        self.app5_name.move(670,y1+100)
        self.app5_name.setText("计算器")
        self.app5_name.show()

        def hide_plus5():
            self.music_of.hide()
            self.App6()

        #寻找文件App
        self.app6 = QPushButton(self)
        self.app6.setIcon(QIcon("./resource/img/findfile.webp"))
        self.app6.setIconSize(QtCore.QSize(120,120))
        self.app6.setGeometry(50,y1+150,100,100)
        self.app6.clicked.connect(hide_plus5)
        self.app6.show()

        self.app6_name = QLabel(self)
        self.app6_name.move(70,y1+150+100)
        self.app6_name.setText("寻找文件")
        self.app6_name.show()

    #-----------------------------*------------------------------
    def setIcon(self, path):
        self.palette = QPalette()
        self.palette.setBrush(QPalette.Background, QBrush(QPixmap(path)))
        self.setPalette(self.palette)

    def hide1(self):
        self.button.hide()
        self.pbar.hide()

    def backmain(self,modes):
        def back():
            sum = 0
            while sum < len(modes):
                modes[sum].hide()
                sum += 1

            self.win_back.hide()
            self.win_backQL.hide()
            self.mainApp()

        self.win_backQL = QtWidgets.QLabel(self)
        self.win_backQL.setGeometry(QtCore.QRect(945, 10, 21, 21))
        self.win_backQL.setStyleSheet("border-radius:10px;\n""background-color: rgb(170, 0, 0);")
        self.win_backQL.setText("")

        self.win_backQL.show()

        self.win_back = QPushButton(self)
        self.win_back.setGeometry(QtCore.QRect(945, 10, 21, 21))
        self.win_back.setCursor(QCursor(QtCore.Qt.PointingHandCursor))
        self.win_back.setStyleSheet("QPushButton{background:#ffff7f;border-radius:10px;}QPushButton:hover{background:yellow;}")
        self.win_back.setText("")
        self.win_back.clicked.connect(back)

        self.win_back.show()

    def Eventhide(self):
        self.app1.hide()
        self.app1_name.hide()
        self.wifi_debug.hide()
        self.wifise.hide()
        self.app2.hide()
        self.app2_name.hide()
        self.app3.hide()
        self.app3_name.hide()
        self.app4.hide()
        self.app4_name.hide()
        self.app5.hide()
        self.app5_name.hide()
        self.app6.hide()
        self.app6_name.hide()

    def killPid(self):
        try:
            system = 'taskkill /pid ' + str(pid) + ' /f'
            os.popen(system,'r')

        except:
            pass

    #------------------------------------------------*--------------------------------------------------

    def change(self):
        if self.want == "Chinese":
            tran = Translator(from_lang='english',to_lang='chinese')
            result = tran.translate(self.text)

        elif self.want == "English":
            tran = Translator(from_lang='chinese',to_lang='english')
            result = tran.translate(self.text)

        else:
            sys.exit()


        return result

    def update(self):
        self.video_urls = []
        self.lt.hide()
        self.ll = QLabel(self)
        self.ll.setText('搜索结果:')
        self.ll.show()

        # 读取标题和url,储存到列表

        with open('./tmp/title.txt', 'r', encoding='utf-8') as f:
            self.titles = f.read()
            self.special_titles = self.titles.split('\n')

        # 显示所有的搜索到的视频title
        self.lll = QLabel(self)
        self.lll.setText(self.titles)
        self.lll.move(0, 30)
        self.lll.resize(600,300)
        self.lll.show()

        with open('./tmp/url.txt', 'r', encoding='utf-8') as f1:
            a = f1.read()
            if a != '':
                a = a.split('\n')
                self.video_urls = list(a)

    def findfile(self,c,a):
        flagse = False
        for root, dirs, files in os.walk(a, topdown=True):
            if c in files:
                flagse = True
                root = root + '/' + c
                break
            else:
                root = None

        return flagse,root

    #----------------------------------------------*---------------------------------------------
    def movie_Ui(self):
        self.setFixedSize(1350, 800)
        self.centralwidget = QtWidgets.QWidget(self)
        self.centralwidget.setObjectName("centralwidget")
        self.ImgDisp = QtWidgets.QLabel(self.centralwidget)
        self.ImgDisp.setGeometry(QtCore.QRect(0, 0, 54, 12))
        self.ImgDisp.setObjectName("ImgDisp")
        self.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(self)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 625, 17))
        self.menubar.setObjectName("menubar")
        self.menushowImg = QtWidgets.QMenu(self.menubar)
        self.menushowImg.setObjectName("menushowImg")
        self.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(self)
        self.statusbar.setObjectName("statusbar")
        self.setStatusBar(self.statusbar)
        self.toolBar = QtWidgets.QToolBar(self)
        self.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar)
        self.actionshowImg = QtWidgets.QAction(self)
        self.actionshowImg.setObjectName("actionshowImg")
        self.menushowImg.addAction(self.actionshowImg)
        self.menubar.addAction(self.menushowImg.menuAction())
        self.toolBar.addAction(self.actionshowImg)

        self.retranslateUi()
        QtCore.QMetaObject.connectSlotsByName(self)

        self.actionshowImg.triggered.connect(self.playVideoFile)

    def retranslateUi(self):
        _translate = QtCore.QCoreApplication.translate
        self.ImgDisp.setText(_translate("MainWindow", "."))
        self.menushowImg.setTitle(_translate("MainWindow", "menu"))
        self.toolBar.setWindowTitle(_translate("MainWindow", "toolBar"))
        self.actionshowImg.setText(_translate("MainWindow", "showImg"))




    #-----------------------------------------------*------------------------------------------------
    def App1(self):
        self.killPid()
        def show1():
            if self.sum == 0:
                pass
            else:
                self.showFanyi.hide()

            self.text = self.lineEdit.text()
            self.want = "English"
            self.text = self.change()
            self.showFanyi = QLabel(self)
            self.showFanyi.setGeometry(0, 200, 1000, 100)
            self.showFanyi.setText(self.text)
            self.showFanyi.show()
            self.backmain([self.showFanyi, self.lineEdit, self.b2, self.determine])
            self.sum += 1

        def show2():
            if self.sum == 0:
                pass
            else:
                self.showFanyi.hide()

            self.text = self.lineEdit.text()
            self.want = "Chinese"
            self.text = self.change()
            self.showFanyi = QLabel(self)
            self.showFanyi.setGeometry(0, 200, 1000, 100)
            self.showFanyi.setText(self.text)
            self.showFanyi.show()
            self.backmain([self.showFanyi, self.lineEdit, self.b2, self.determine])
            self.sum += 1

        self.setIcon("./resource/img/Fanyi.webp")

        self.Eventhide()

        self.lineEdit = QLineEdit(self)
        self.lineEdit.setMaxLength(10)
        self.lineEdit.move(0, 0)
        self.lineEdit.show()

        self.b2 = QPushButton(self)
        self.b2.move(100, 0)
        self.b2.setText("英译中")
        self.b2.clicked.connect(show2)
        self.b2.show()

        self.determine = QPushButton(self)
        self.determine.move(100, 100)
        self.determine.setText("中译英")
        self.determine.clicked.connect(show1)
        self.determine.show()

        self.backmain([self.lineEdit, self.b2, self.determine])


    #------------------------------------*------------------------------------------
    def App2(self):
        self.killPid()
        self.Eventhide()

        def t1():
            # 跳转操作
            def connect():
                # 调用搜索线程
                search_movieThread = Search_Thread(name)
                search_movieThread.start()

                # 挂到线程1的update接收函数
                self.update()

                # 接受处理下标
                t1s, oks = QInputDialog.getInt(self, 'choose', '请输入想看的序号')
                XB = t1s - 1

                # 获取指定视频title
                titles = list(self.titles)
                title = self.special_titles[XB]

                self.ll.hide()
                self.lll.hide()

                self.backmain([self.lt])

                # 想传电影的url
                want = self.video_urls[XB]

                # 调用下载视频进程
                if 'page' in want:
                    # 调用搜索线程2
                    download_movieThread2 = Download_movie2(want, title)
                    download_movieThread2.start()

                elif 'cover' in want:
                    # 调用搜索线程1
                    download_movieThread1 = Download_movie1(want, title)
                    download_movieThread1.start()

                else:
                    sys.exit()

                self.ll.hide()
                self.lll.hide()

                os.remove(os.getcwd() + "\\tmp\\title.txt")
                os.remove(os.getcwd() + "\\tmp\\url.txt")

                self.end = QLabel(self)
                self.end.setText('视频下载完成')
                self.end.setGeometry(0, 0, 100, 30)
                self.end.show()

                self.backmain([self.ll, self.lll, self.lt, self.end])

            self.btn1.hide()

            # 显示提醒
            self.lt = QLabel(self)
            self.lt.setText('正在准备并开始搜索...')
            self.lt.move(0, 0)
            self.lt.resize(200, 20)
            self.lt.show()

            # 输入目标
            text, ok = QInputDialog.getText(self, 'search', '请输入搜索内容')
            name = str(text)

            # 调用跳转函数
            connect()

        self.setIcon('./resource/img/TengXun.jpg')
        # 设置控件第一部分
        self.btn1 = QPushButton(self)
        self.btn1.setText('start')
        self.btn1.setGeometry(450, 305, 150, 50)

        # 跳转到第2部分
        self.btn1.clicked.connect(t1)
        self.btn1.show()

        self.backmain([self.btn1])

    #----------------------------------------------*-----------------------------------------

    def App3(self):
        def shutdown():
            os.popen("shutdown /s /t 0",'r')

        self.Eventhide()
        self.killPid()
        self.setIcon('./resource/img/shutdownbg.jpg')
        self.shutdown = QPushButton(self)
        self.shutdown.setGeometry(450,312.5,100,40)
        self.shutdown.setText("关机")
        self.shutdown.clicked.connect(shutdown)
        self.shutdown.show()
        self.backmain([self.shutdown])

    def App4(self):
        self.setIcon("./resource/img/Videobg.jpg")
        self.killPid()

        try:
            self.playVideoFile()
        except:
            self.centralwidget.hide()
            self.ImgDisp.hide()
            self.menubar.hide()
            self.menushowImg.hide()
            self.statusbar.hide()
            self.toolBar.hide()
            self.mainApp()








    def playVideoFile(self):
        def cvImgtoQtImg(cvImg):
            QtImgBuf = cv2.cvtColor(cvImg, cv2.COLOR_BGR2BGRA)
            QtImg = QtGui.QImage(QtImgBuf.data, QtImgBuf.shape[1], QtImgBuf.shape[0], QtGui.QImage.Format_RGB32)
            return QtImg

        self.movie_Ui()
        text,ok = QInputDialog.getText(self, 'search', '请输入影片路径')
        cap = cv2.VideoCapture(str(text))
        fps = 24

        play_video_audio(str(text))
        video_audio = multiprocessing.Process(target=playaudioing,daemon=True)
        video_audio.start()

        time.sleep(1.05)

        if not cap.isOpened():
            exit()

        while not self.bClose:
            ret, frame = cap.read()
            if not ret:
                if frame is None:
                    self.centralwidget.hide()
                    self.ImgDisp.hide()
                    self.menubar.hide()
                    self.menushowImg.hide()
                    self.statusbar.hide()
                    self.toolBar.hide()
                    self.mainApp()
                else:
                    break


            QtImg = cvImgtoQtImg(frame)
            self.ImgDisp.setPixmap(QtGui.QPixmap.fromImage(QtImg))
            size = QtImg.size()
            self.ImgDisp.resize(size)
            self.ImgDisp.move(0,0)
            self.ImgDisp.show()
            cv2.waitKey(int(1000 / fps))
        cap.release()

    def App5(self):
        self.Eventhide()
        self.killPid()
        self.setIcon("./resource/img/algorithmbg.jpg")

        self.l1 = QLabel(self)
        self.l1.setFrameShape(QFrame.Box)
        self.l1.setLineWidth(3)
        self.l1.setMidLineWidth(1)
        self.l1.setGeometry(420,100,200,50)
        self.l1.show()


        def set():
            self.L_1 = QPushButton(self)
            self.L_2 = QPushButton(self)
            self.L_3 = QPushButton(self)
            self.L_4 = QPushButton(self)
            self.L_5 = QPushButton(self)
            self.L_6 = QPushButton(self)
            self.L_7 = QPushButton(self)
            self.L_8 = QPushButton(self)
            self.L_9 = QPushButton(self)
            self.L_0 = QPushButton(self)
            self.L_X_ = QPushButton(self)
            self.L_chu_ = QPushButton(self)
            self.L_jia_ = QPushButton(self)
            self.L_jian_ = QPushButton(self)
            self.L_kuo1_ = QPushButton(self)
            self.L_kuo2_ = QPushButton(self)
            self.Yes_No = QPushButton(self)
            self.gui_zero = QPushButton(self)

        set()

        def init():
            def TZ(text):
                if text != "\\0":
                    if text != "=":
                        self.algorithmre += text
                        self.l1.setText(self.algorithmre)
                    else:
                        self.l1.clear()
                        self.l1.setText(str(eval(self.algorithmre)))
                        self.algorithmre = ''
                else:
                    self.algorithmre = ''
                    self.l1.clear()

            lh = 80
            wh = 30
            x = 250
            self.L_1.setGeometry(x,200,lh,wh)
            self.L_1.setText('1')
            self.L_1.clicked.connect(lambda:TZ('1'))
            self.L_2.setGeometry(x+100,200,lh,wh)
            self.L_2.setText('2')
            self.L_2.clicked.connect(lambda:TZ('2'))
            self.L_3.setGeometry(x+100+100,200,lh,wh)
            self.L_3.setText('3')
            self.L_3.clicked.connect(lambda:TZ('3'))
            self.L_4.setGeometry(x+100+100+100,200,lh,wh)
            self.L_4.setText('4')
            self.L_4.clicked.connect(lambda:TZ('4'))
            self.L_5.setGeometry(x+100+100+100+100,200,lh,wh)
            self.L_5.setText('5')
            self.L_5.clicked.connect(lambda:TZ('5'))
            self.L_6.setGeometry(x,300,lh,wh)
            self.L_6.setText('6')
            self.L_6.clicked.connect(lambda:TZ('6'))
            self.L_7.setGeometry(x+100,300,lh,wh)
            self.L_7.setText('7')
            self.L_7.clicked.connect(lambda:TZ('7'))
            self.L_8.setGeometry(x+100+100,300,lh,wh)
            self.L_8.setText('8')
            self.L_8.clicked.connect(lambda:TZ('8'))
            self.L_9.setGeometry(x+100+100+100,300,lh,wh)
            self.L_9.setText('9')
            self.L_9.clicked.connect(lambda:TZ('9'))
            self.L_0.setGeometry(x+100+100+100+100,300,lh,wh)
            self.L_0.setText('0')
            self.L_0.clicked.connect(lambda:TZ('0'))
            self.L_X_.setGeometry(x,400,lh,wh)
            self.L_X_.setText('*')
            self.L_X_.clicked.connect(lambda:TZ('*'))
            self.L_chu_.setGeometry(x+100,400,lh,wh)
            self.L_chu_.setText('/')
            self.L_chu_.clicked.connect(lambda:TZ('/'))
            self.L_jia_.setGeometry(x+100+100,400,lh,wh)
            self.L_jia_.setText('+')
            self.L_jia_.clicked.connect(lambda:TZ('+'))
            self.L_jian_.setGeometry(x+100+100+100,400,lh,wh)
            self.L_jian_.setText('-')
            self.L_jian_.clicked.connect(lambda:TZ('-'))
            self.L_kuo1_.setGeometry(x+100+100+100+100,400,lh,wh)
            self.L_kuo1_.setText('(')
            self.L_kuo1_.clicked.connect(lambda:TZ('('))
            self.L_kuo2_.setGeometry(x,500,lh,wh)
            self.L_kuo2_.setText(')')
            self.L_kuo2_.clicked.connect(lambda:TZ(')'))
            self.Yes_No.setGeometry(x+100,500,lh,wh)
            self.Yes_No.setText('=')
            self.Yes_No.clicked.connect(lambda:TZ('='))
            self.gui_zero.setGeometry(x+100+100,500,lh,wh)
            self.gui_zero.setText("\\0")
            self.gui_zero.clicked.connect(lambda:TZ("\\0"))

        init()

        def show():
            self.L_1.show()
            self.L_2.show()
            self.L_3.show()
            self.L_4.show()
            self.L_5.show()
            self.L_6.show()
            self.L_7.show()
            self.L_8.show()
            self.L_9.show()
            self.L_0.show()
            self.L_X_.show()
            self.L_chu_.show()
            self.L_jia_.show()
            self.L_jian_.show()
            self.L_kuo1_.show()
            self.L_kuo2_.show()
            self.Yes_No.show()
            self.gui_zero.show()

        show()



        self.backmain([self.l1,self.L_1,self.L_2,self.L_3,self.L_4,self.L_5,self.L_6,self.L_7,self.L_8,self.L_9,self.L_0,self.L_X_,self.L_chu_,self.L_jia_,self.L_jian_,self.L_kuo1_,self.L_kuo2_,self.Yes_No,self.gui_zero])

    def App6(self):
        def TZ1():
            data = self.lineEdit2.text()
            data = data.split(',')

            filename = data[0]
            LocalSystem = data[1]

            flagse, filepath = self.findfile(filename, LocalSystem)
            if flagse == True and None != filepath:
                result = "找到了\n" + str(filepath)
            else:
                result = "没找到"

            self.result = QLabel(self)
            self.result.setGeometry(0, 100, 200, 20)
            self.result.setText(result)
            self.result.show()

            self.backmain([self.Label, self.lineEdit2, self.result,self.yes_no])

        self.Eventhide()
        self.killPid()
        self.setIcon("./resource/img/findfilebg.jpg")

        self.Label = QLabel(self)
        self.Label.setGeometry(0,0,450,20)
        self.Label.setText("请输入要找的文件名称和盘符[down]{ex:(a.doc,C:/)")
        self.Label.show()


        self.lineEdit2 = QLineEdit(self)
        self.lineEdit2.setMaxLength(100)
        self.lineEdit2.setGeometry(400, 0,200,17)
        self.lineEdit2.show()

        self.yes_no = QPushButton(self)
        self.yes_no.setGeometry(0,50,50,25)
        self.yes_no.clicked.connect(TZ1)
        self.yes_no.setText("确定")
        self.yes_no.show()

        self.backmain([self.yes_no,self.lineEdit2,self.Label])












#-------------------------*------------------------
def play_music():
    while True:
        list_data = os.listdir(r"resource\music")
        music_data = r"resource\music" + "\\" + list_data[randint(0, len(list_data) - 1)]
        mixer.init()
        music_time = mixer.Sound(music_data).get_length()
        mixer.music.load(music_data)
        mixer.music.play()
        time.sleep(music_time)
        mixer.music.stop()



#---------------------------------*-----------------------------------
#搜索线程
class Search_Thread(QThread):

    def __init__(self,name,parent=None):
        super().__init__(parent)
        self.name = name
        self.run()

    #run耗时函数
    def run(self):
        #初始变量
        self.mmm = ''
        self.headers = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36',
            'Cookie': 'pac_uid=0_f3cabb3962d51; iip=0; tvfe_boss_uuid=fd4e4810a9a11032; video_guid=731b99'
                      '36f325c572; video_platform=2; pgv_pvid=8205706391; ts_refer=www.baidu.com/link; ts_uid=842'
                      '184840; bucket_id=9231007; tvfe_search_uid=4a5a3777-a22a-4c92-9084-896a8b742a70; txv_boss_uuid=f27a4813-d5'
                      '1e-3763-09a5-7fedc1b1b761; pgv_info=ssid=s3339476598; qv_als=znCDdIc1H6zn+Z+MA11629181277RexL+A==; ptag=www_baidu_co'
                      'm|channel; vversion_name=8.2.95; video_omgid=731b9936f325c572; ts_last=v.qq.com/x/cover/gothgwl98bmq6es.html; ad_play_index=11'}
        self.vf = ''
        self.n_vf_urls = []
        self.n_mv_urls = []
        self.mv = ''
        self.tt = ''
        self.video_urls = []
        self.titles = []


        # 腾讯索引url
        self.main_url = 'https://v.qq.com/x/search/?'

        # get请求框架1
        get = {
            'q': self.name,
            'stag': '102',
            'smartbox_ab': ''
        }

        # 请求指定内容网页源代码
        self.html1 = requests.get(self.main_url, params=get, headers=self.headers).content.decode('utf-8')

        # 寻找所有视频网页url
        self.vf_urls = re.findall(r'"https://v.qq.com/x/page/.+?.*.html"', self.html1)

        # 使用numpy.unique()函数去重
        self.vf_urls = list(np.unique(self.vf_urls))

        # 寻找所有特别网页url
        self.mv_urls = re.findall(r'"https://v.qq.com/x/cover/.+?.*.html"', self.html1)
        self.mv_urls = list(np.unique(self.mv_urls))

        # 清洗urls
        for self.j in self.vf_urls:
            for self.i in self.j:
                # 逻辑判断
                if (('a' <= self.i <= 'z') or ('A' <= self.i <= 'Z') or ('0' <= self.i <= '9')) or (
                        (self.i == ':') or (self.i == '.') or (self.i == '/')):
                    self.vf += self.i

            if self.vf != '':
                self.n_vf_urls.append(self.vf)
                # 重新赋值
                self.vf = ''

        for self.j in self.mv_urls:
            for self.i in self.j:
                # 逻辑判断
                if (('a' <= self.i <= 'z') or ('A' <= self.i <= 'Z') or ('0' <= self.i <= '9')) or (
                        (self.i == ':') or (self.i == '.') or (self.i == '/')):
                    self.mv += self.i

            if self.mv != '':
                self.n_mv_urls.append(self.mv)
                self.mmm += self.mv + '\n'
                # 重新赋值
                self.mv = ''

        # 重新赋值列表
        if not (self.vf_urls is self.n_vf_urls) and not (self.mv_urls is self.n_mv_urls):
            self.vf_urls = self.n_vf_urls
            self.mv_urls = self.n_mv_urls
            self.video_urls += self.mv_urls
            self.video_urls += self.vf_urls

        else:
            sys.exit()

        # get到列表下标url的网页title
        sum = 0

        for self.url in self.video_urls:
            sum += 1
            self.title = requests.get(self.url, headers=self.headers).content.decode('utf-8')

            #使用try...except...语句捕获异常
            try:
                self.title = re.search(r'.+?.*', self.title).group(0).strip('')

            except:
                self.title = '未知视频'

            self.titles.append(self.title)
            self.tt += str(sum) + '.' + self.title + '\n'

        #因现阶段主类信号不能接收,会卡崩,所以采用外部传输方法,文件传输方法
        with open(os.getcwd()+'\\tmp\\'+'title.txt','w',encoding='utf-8') as fp1:
            fp1.write(self.tt)

        with open(os.getcwd()+'\\tmp\\'+'url.txt','w',encoding='utf-8') as fp2:
            for i in self.video_urls:
                fp2.write(i + '\n')


#下载视频线程1
class Download_movie1(QThread):
    def __init__(self,movie_url,title,parent=None):
        super().__init__(parent)

        #基础变量
        self.headers = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36',
            'Cookie': 'pac_uid=0_f3cabb3962d51; iip=0; tvfe_boss_uuid=fd4e4810a9a11032; video_guid=731b99'
                      '36f325c572; video_platform=2; pgv_pvid=8205706391; ts_refer=www.baidu.com/link; ts_uid=842'
                      '184840; bucket_id=9231007; tvfe_search_uid=4a5a3777-a22a-4c92-9084-896a8b742a70; txv_boss_uuid=f27a4813-d5'
                      '1e-3763-09a5-7fedc1b1b761; pgv_info=ssid=s3339476598; qv_als=znCDdIc1H6zn+Z+MA11629181277RexL+A==; ptag=www_baidu_co'
                      'm|channel; vversion_name=8.2.95; video_omgid=731b9936f325c572; ts_last=v.qq.com/x/cover/gothgwl98bmq6es.html; ad_play_index=11'}

        self.movie_url = movie_url

        #视频解析接口
        self.analysis_url = 'https://jx.parwix.com:4433/player/?url='

        self.title = title

        #调用耗时函数
        self.run()

    #耗时函数
    def run(self):
        options = webdriver.ChromeOptions()
        options.add_argument('-headless') #设置自动化浏览器为无头自动化浏览器

        # 自动化浏览器初始设置
        #服务bat文件所在地
        server = Server(os.getcwd()+'\\video\\browsermob-proxy-2.1.4\\bin\\browsermob-proxy.bat')
        server.start()

        proxy = server.create_proxy()
        options.add_argument('--proxy-server={0}'.format(proxy.proxy))
        options.add_argument('ignore-certificate-errors')
        browser = webdriver.Chrome(chrome_options=options)
        proxy.new_har("ht_list2", options={'captureContent': True})

        #获取视频解析接口源码
        browser.get(self.analysis_url+self.movie_url)
        result = proxy.har
        browser.switch_to.frame(browser.find_elements_by_tag_name("iframe")[0])

        #休息
        time.sleep(5)

        #整理源码
        data = PyQuery(browser.page_source)

        #正则匹配视频地址
        se = re.findall(r'preload="auto" src="https://.+?.*"', str(data))
        if len(se) == 1:
            pass
        else:
            #抛异常
            sys.exit()


        se = re.findall(r'https://.+?.*', se[0])
        if len(se) == 1:
            se = se[0]
        else:
            #抛异常
            sys.exit()
        #重新赋值
        download_url = se
        html = '''
        
        
        
        video
        
        
        
         + download_url + '''>播放地址
        
        
        '''

        browser.close()


        #下载视频
        response = requests.get(download_url,headers=self.headers)
        name = self.title


        with open(os.getcwd() + '\\TengXunVideo\\' + name.strip('1234567890.')+'.html','w') as fb:
            fb.write(html)


        #放入创建过的空的文件
        with open(os.getcwd()+'\\TengXunVideo\\'+name.strip('1234567890.')+'.mp4','wb') as f:
            f.write(response.content)


#下载视频线程2
class Download_movie2(QThread):
    def __init__(self,movie_url,title,parent=None):
        super().__init__(parent)

        #基础变量
        self.movie_url = movie_url
        self.title = title
        self.headers = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36',
            'Cookie': 'pac_uid=0_f3cabb3962d51; iip=0; tvfe_boss_uuid=fd4e4810a9a11032; video_guid=731b99'
                      '36f325c572; video_platform=2; pgv_pvid=8205706391; ts_refer=www.baidu.com/link; ts_uid=842'
                      '184840; bucket_id=9231007; tvfe_search_uid=4a5a3777-a22a-4c92-9084-896a8b742a70; txv_boss_uuid=f27a4813-d5'
                      '1e-3763-09a5-7fedc1b1b761; pgv_info=ssid=s3339476598; qv_als=znCDdIc1H6zn+Z+MA11629181277RexL+A==; ptag=www_baidu_co'
                      'm|channel; vversion_name=8.2.95; video_omgid=731b9936f325c572; ts_last=v.qq.com/x/cover/gothgwl98bmq6es.html; ad_play_index=11'
        }
        self.basic_url = 'https://www.ikukk.com/?ac=0&url='

        #调用耗时操作
        self.run()

    #耗时操作
    def run(self):
        options = webdriver.ChromeOptions()
        options.add_argument('-headless')

        server = Server(os.getcwd() + '\\video\\browsermob-proxy-2.1.4\\bin\\browsermob-proxy.bat')
        server.start()

        proxy = server.create_proxy()
        options.add_argument('--proxy-server={0}'.format(proxy.proxy))
        options.add_argument('ignore-certificate-errors')
        browser = webdriver.Chrome(chrome_options=options)
        proxy.new_har("ht_list2", options={'captureContent': True})

        browser.get(self.basic_url + self.movie_url)
        result = proxy.har
        browser.switch_to.frame(browser.find_elements_by_tag_name("iframe")[0])

        time.sleep(55)

        data = PyQuery(browser.page_source)

        # 正则匹配视频地址
        se = re.findall(r'preload="metadata" src=".+?.*"', str(data))
        if len(se) == 1:
            pass
        else:
            # 抛异常
            sys.exit()

        se = re.findall(r'https://.+?.*', se[0])
        if len(se) == 1:
            se = se[0]
        else:
            # 抛异常
            sys.exit()

        # 重新赋值
        download_url = se
        html = '''
        
        
        
        video
        
        
        
         + download_url + '''>播放地址
        
        
        '''

        browser.close()
        response = requests.get(download_url.strip('"'),headers=self.headers)
        name = self.title

        with open(os.getcwd() + '\\TengXunVideo\\' + name.strip('1234567890.') + '.html', 'w') as fb:
            fb.write(html)

        # 放入创建过的空的文件
        with open(os.getcwd() + '\\TengXunVideo\\' + name.strip('1234567890.') + '.mp4', 'wb') as f:
            f.write(response.content)

#-------------------------------------------*------------------------------------------
def play_video_audio(path):
    video = VideoFileClip(path)
    audio = video.audio
    audio.write_audiofile(os.getcwd() + '\\tmp\\test.wav')
    audio.write_audiofile(os.getcwd() + '\\tmp\\test.wav')
    return 0

def playaudioing():
    while True:
        path = r'tmp\test.wav'
        mixer.init()
        mixer.music.load(path)
        music_time = mixer.Sound(path).get_length()
        mixer.music.play()
        time.sleep(music_time)
        mixer.stop()
        return 0




if __name__ == '__main__':
    def run():
        app = QApplication(sys.argv)
        GUI = UI()
        GUI.show()
        sys.exit(app.exec_())

    run()

    gc.collect()


喜欢此文章请麻烦点一个心心,收藏加关注,爱你么么哒

你可能感兴趣的:(pyqt5,qt,python)