全民爱拍等小视频批量上传发布辅助工具

       当下小视频火得不得了,于是研究了一下排名前十得小视频平台,比如爱拍,火山,抖音之类的。发现每个平台的模式都比较类似,于是就想一个视频是不是可以自动发布到多个平台。是不是可以自动发布多个账号下的多个视频?经过研究,发现确实是可以这么玩的,于是就写了个小工具。在此记录一下。有需要验证的可以下载打包好的执行文件:

链接:https://pan.baidu.com/s/1AW8RrRdWC2ip4cGV01dxwA
提取码:ge2z

部分源码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import sys
import re
import time
from PyQt5 import QtWidgets, QtGui, QtCore
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import QApplication, QMainWindow
import videoupload
import uploadprocess
import openpyxl
from openpyxl import Workbook
#import mutiTask
import logging
#import filerename
 
class FileUploadThread(QThread):
    signal = pyqtSignal(str, int)
    def __init__(self, parent=None,fileName='', resultFile='', taskIndex=1):
        super(FileUploadThread,self).__init__(parent)
        self.fileName = fileName
        self.resultFile = resultFile
        self.taskIndex = taskIndex
         
    def run(self):
        localTaskIndex = self.taskIndex
        localFileName = self.fileName
        self.signal.emit('开始上传 ' + localFileName, localTaskIndex)
        self.uploadFile()
        self.signal.emit('上传完成 ' + localFileName, localTaskIndex)
        '''k = 1
        while True:
            self.signal.emit('上传完成 ' + str(k), localTaskIndex)
            k = k + 1
            time.sleep(5)'''
         
    def is_number(self, num):
        pattern = re.compile(r'^[-+]?[-0-9]\d*\.\d*|[-+]?\.?[0-9]\d*$')
        result = pattern.match(str(num))
        if result:
            return True
        else:
            return False
             
    def uploadFile(self):
        localTaskIndex = self.taskIndex
        localAccountFile = self.fileName
        localResultFile = self.resultFile
        uploadItem = uploadprocess.UploadProcess()
        accounts = uploadItem.getAccounts(localAccountFile)
        resultInfo = uploadItem.getResultInfo(localResultFile)
        resultFilePath = localAccountFile[0:localAccountFile.rindex('.')]
        #将上传账号的记录保存下来
        fileName = 'result-' + time.strftime('%Y%m%d%H%M', time.localtime(time.time())) + '.xlsx'
        resultFilePath = resultFilePath + fileName
        wb = Workbook()
        sheet = wb.active   
        k = 1
        if uploadItem.firstPageOpen():
            for i in range(0, len(accounts)):
                accountInfo = accounts[i][0]
                if self.is_number(accountInfo):
                    accountInfo = str(int(accounts[i][0]))
                self.signal.emit('开始登陆 ' + accountInfo, localTaskIndex)
                 
                uploadedLastNum = 0
                try:
                    if((len(resultInfo) > 0) and (len(resultInfo[accountInfo]) > 0)):
                        print('in function')
                        uploadedLastNum = int(resultInfo[accountInfo])
                except:
                    self.signal.emit('上传结果文件内容有异常',localTaskIndex)
                    break
                filePaths = uploadItem.getUploadFiles(accounts[i][10][8:], uploadedLastNum)
                if len(filePaths) > 0:
                    k = k + 1
                    #0 -- username, 1 -- password, 10 -- 文件路径, 3 -- 默认评论
                    uploadItem.loginAccount(accountInfo, accounts[i][1])
                    uploadedNum = uploadItem.uploadForAccount(filePaths, accounts[i][3],self.signal, localTaskIndex)
                    self.signal.emit(accountInfo + ' 完成上传 ' + str(uploadedNum) + ' 个视频文件',localTaskIndex)
                    #self.saveUploadResult(i+1, accounts[i][0], uploadedNum)
                    uploadItem.logoutAccount()
                    sheet['A' + str(k)] = accountInfo
                    sheet['B' + str(k)] = str(uploadedNum)
            uploadItem.finishUpload()
        else:
            self.signal.emit('切换登录方式失败',localTaskIndex)
        wb.save(resultFilePath)
        self.signal.emit('上传完成,结果存储在文件:' + resultFilePath,localTaskIndex)
 
class WindowResourceInit(QMainWindow):
    fileName = ''
    resultFile = ''
    taskIndex = 1
    windowList = []
    def windowInit(self):
        ui.btnFileChoose.clicked.connect(self.getAccountFile)
        ui.btnStart.clicked.connect(self.startUpload)
        ui.btnResultChoose.clicked.connect(self.getResult)
        #ui.actionVideoRename.triggered.connect(self.fileRenameAction)
 
    def getAccountFile(self):
        self.fileName, fileType = QFileDialog.getOpenFileName(self, "打开账号文件", "C:\\", "Excel 文件 (*.xlsx)")
        ui.txtFilePath.setText(str(self.fileName))       
        ui.btnStart.setEnabled(True)
         
    def getResult(self):
        self.resultFile, fileType = QFileDialog.getOpenFileName(self, "打开结果文件", "C:\\", "Excel 文件 (*.xlsx)")
        ui.txtLastResult.setText(self.resultFile)
     
    def startUpload(self):
        try:
            ui.btnStart.setEnabled(False)
            if self.taskIndex > 1:
                #新建个Tab,result status
                tabName = 'tab_' + str(self.taskIndex)
                gridName = 'gridLayout_' + str(self.taskIndex + 1)
                statusName = 'txtStatus_' + str(self.taskIndex)
                tabNameObj = QtWidgets.QWidget()
                tabNameObj.setObjectName(tabName)
                gridNameObj = QtWidgets.QGridLayout(tabNameObj)
                gridNameObj.setObjectName(gridName)
                statusNameObj = QtWidgets.QTextEdit()
                font = QtGui.QFont()
                font.setPointSize(15)
                statusNameObj.setFont(font)
                statusNameObj.setObjectName(statusName)
                statusNameObj.append('Init Logs')
                gridNameObj.addWidget(statusNameObj, 0, 0, 1, 1)
                ui.tabStatus.addTab(tabNameObj, "")
                ui.tabStatus.setCurrentIndex(self.taskIndex - 1)
                _translate = QtCore.QCoreApplication.translate
                ui.tabStatus.setTabText(ui.tabStatus.indexOf(tabNameObj), _translate("MainWindow", '任务' + str(self.taskIndex)))
            #ui.txtStatus.setText('')
            #新开一个线程来做上传
            self.thread = FileUploadThread(self, self.fileName, self.resultFile, self.taskIndex)
            self.thread.signal.connect(self.threadCallback)
            self.thread.start()    # 启动线程
            self.taskIndex = self.taskIndex + 1
        except Exception as e:
            print(e)
            logger = logging.getLogger()  # 创建logging对象
            # 使用.basicConfig打开当前目录下的LOG.log文件,并设置log的显示格式(即在文档中看到的格式)
            logging.basicConfig(filename='../LOG.log',format='[%(asctime)s-%(filename)s-%(levelname)s:%(message)s]', level=logging.DEBUG,filemode='a', datefmt='%Y-%m-%d%I:%M:%S %p')
            # 根据日志输出需要在相应的函数模块中设定日志的如下属性:
            logging.info = str(e)
            #需要把信息记录到日志文件
        '''uploadItem = uploadprocess.UploadProcess()
        accounts = uploadItem.getAccounts(self.fileName)
        if uploadItem.firstPageOpen():
            for i in range(0, len(accounts)):
                #0 -- username, 1 -- password, 10 -- 文件路径, 3 -- 默认评论
                uploadItem.loginAccount(accounts[i][0], accounts[i][1])
                filePaths = uploadItem.getUploadFiles(accounts[i][10][8:])
                uploadedNum = uploadItem.uploadForAccount(filePaths, accounts[i][3])
                self.saveUploadResult(i+1, accounts[i][0], uploadedNum)
                uploadItem.logoutAccount()
            uploadItem.finishUpload()'''
             
    def threadCallback(self, data, taskIndex):
        if taskIndex == 1:
            ui.txtStatus.append(data)
        else:
            txtName = 'txtStatus_' + str(taskIndex)
            print(txtName)
            print(ui.tabStatus.findChild(QTextEdit, txtName))
            ui.tabStatus.findChild(QTextEdit, txtName).append(data)

  

  

posted @   modentime  阅读(591)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
点击右上角即可分享
微信分享提示