全民爱拍火山抖音等小视频自动上传辅助工具
2021-02-14 17:17
标签:ctime message exception cat ddt def match qfile cal 当下小视频火得不得了,于是研究了一下排名前十得小视频平台,比如爱拍,火山,抖音之类的。发现每个平台的模式都比较类似,于是就想一个视频是不是可以自动发布到多个平台。是不是可以自动发布多个账号下的多个视频?经过研究,发现确实是可以这么玩的,于是就写了个小工具。在此记录一下。有需要验证的可以下载打包好的执行文件: 链接:https://pan.baidu.com/s/1AW8RrRdWC2ip4cGV01dxwA 部分源码如下: 全民爱拍火山抖音等小视频自动上传辅助工具 标签:ctime message exception cat ddt def match qfile cal 原文地址:https://www.cnblogs.com/modentime/p/12991741.html
提取码:ge2zimport 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)
上一篇:HTML 在线编辑器
下一篇:css两端固定大小,中间自动大小