Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

批量维护之前下载的视频/图片 #255

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions TikTokMaintain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@Description:维护之前下载的视频/图片
@Date :2022/11/24
@Author :JP Zhang
@version :1.0.0
@License :(C)Copyright 2019-2022, Liugroup-NLPR-CASIA
@Github :https://github.com/zjplab
@Mail :[email protected]
'''
from tqdm import tqdm
import multiprocessing as mp
import subprocess

class MultiCmds:
def __init__(self, urls, number_of_tasks=4):
self.urls = urls
self.cmd_prefix = ['python', './TiktokTool.py', '-u']
self.cmds=[self.cmd_prefix+[url] for url in self.urls]
self.NUMBER_OF_TASKS = number_of_tasks
self.progress_bar = tqdm(total=self.NUMBER_OF_TASKS)

def exec(self):
# print(self.cmds)
# print(self.NUMBER_OF_TASKS)
pool = mp.Pool(self.NUMBER_OF_TASKS)
for cmd in self.cmds:
pool.apply_async(MultiCmds.work, (cmd,), callback=self.update_progress_bar)
pool.close()
pool.join()

@staticmethod
def work(cmd):
# To do: 压制
# subprocess.call(cmd, stdout=subprocess.DEVNULL)
subprocess.call(cmd)

def update_progress_bar(self, _):
self.progress_bar.update()


class TikTokMaintain:
def __init__(self):
self.users_mapping = {}
with open("maintainList.txt", "r", encoding="UTF-8") as f:
file_lsts = f.readlines()
file_lsts= [line for line in file_lsts if not line.startswith("#")]
self.users_mapping= {split[0]:split[1] for line in file_lsts if (split:=line.strip().split())[0].startswith("https")}
self.users_mapping.update({split[1]:split[0] for line in file_lsts if not (split:=line.strip().split())[0].startswith("http")})

def maintain(self):
cmds= MultiCmds(urls=self.users_mapping.keys(), number_of_tasks=4)
cmds.exec()

if __name__ == '__main__':
maintain = TikTokMaintain()
maintain.maintain()
3 changes: 3 additions & 0 deletions maintainList.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 格式: 链接(https开头) 空格或者tab 用户名备注 或者反序
吴语 https://www.douyin.com/user/MS4wLjABAAAAXUUsWPReYU-Jv4800ojtktBbMV6O_vx7mKLd8qXPU3E?relation=1&vid=7168840033854639399
小五妹 https://www.douyin.com/user/MS4wLjABAAAAVoVEAv2dhtGCuZ7A5XKN9KK5Ky3hN9l6g-esDhOgUiU?vid=7169505458166779174
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ PyQt5==5.15.7
requests==2.22.0
retrying==1.3.3
pyinstaller==3.6
tqdm