下载地址:m.pan38.com/download.ph… 提取码:6666
抖音点赞插件包含完整的功能实现,包括设备连接、视频滑动、智能点赞、关键词过滤等。使用时需要先安装依赖库,配置好设备连接信息,然后运行主程序即可
import time
import random
import uiautomator2 as u2
from PIL import Image
import cv2
import numpy as np
import os
import json
from datetime import datetime
class DouyinLikeBot:
def __init__(self, config_file='config.json'):
self.device = None
self.config = self.load_config(config_file)
self.like_count = 0
self.max_likes = self.config.get('max_likes', 100)
self.session_timeout = self.config.get('session_timeout', 3600)
self.start_time = datetime.now()
def load_config(self, config_file):
default_config = {
'device_id': None,
'max_likes': 100,
'scroll_delay': [2, 5],
'like_delay': [1, 3],
'session_timeout': 3600,
'detect_interval': 30,
'blacklist_keywords': ['广告', '推广'],
'whitelist_keywords': []
}
try:
with open(config_file, 'r', encoding='utf-8') as f:
return {**default_config, **json.load(f)}
except:
return default_config
def connect_device(self):
try:
if self.config['device_id']:
self.device = u2.connect(self.config['device_id'])
else:
self.device = u2.connect()
return True
except Exception as e:
print(f"设备连接失败: {e}")
return False
def start_douyin(self):
self.device.app_start('com.ss.android.ugc.aweme')
time.sleep(5)
def is_liked(self, screenshot):
# 使用图像识别判断是否已点赞
template = cv2.imread('like_template.png', 0)
if template is None:
return False
img_gray = cv2.cvtColor(np.array(screenshot), cv2.COLOR_BGR2GRAY)
res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)
threshold = 0.8
loc = np.where(res >= threshold)
return len(loc[0]) > 0
def should_like_video(self, description):
# 基于关键词过滤决定是否点赞
desc_lower = description.lower()
for kw in self.config['blacklist_keywords']:
if kw.lower() in desc_lower:
return False
if self.config['whitelist_keywords']:
for kw in self.config['whitelist_keywords']:
if kw.lower() in desc_lower:
return True
return False
return True
def like_video(self):
try:
screenshot = self.device.screenshot(format='opencv')
if self.is_liked(screenshot):
return False
description = self.device(resourceId="com.ss.android.ugc.aweme:id/aab").get_text()
if not self.should_like_video(description):
return False
like_btn = self.device(resourceId="com.ss.android.ugc.aweme:id/d1x")
if like_btn.exists:
like_btn.click()
self.like_count += 1
print(f"已点赞 {self.like_count}/{self.max_likes}")
time.sleep(random.uniform(*self.config['like_delay']))
return True
except Exception as e:
print(f"点赞出错: {e}")
return False
def scroll_to_next(self):
try:
width, height = self.device.window_size()
start_x = width * 0.5
start_y = height * 0.8
end_y = height * 0.2
self.device.swipe(start_x, start_y, start_x, end_y, duration=0.5)
time.sleep(random.uniform(*self.config['scroll_delay']))
return True
except Exception as e:
print(f"滑动出错: {e}")
return False
def run(self):
if not self.connect_device():
return
self.start_douyin()
last_detect_time = time.time()
while (self.like_count < self.max_likes and
(datetime.now() - self.start_time).seconds < self.session_timeout):
current_time = time.time()
if current_time - last_detect_time > self.config['detect_interval']:
if not self.device.app_current()['package'] == 'com.ss.android.ugc.aweme':
print("检测到抖音不在前台,重新启动...")
self.start_douyin()
last_detect_time = current_time
if not self.like_video():
if not self.scroll_to_next():
break
print(f"点赞任务完成,共点赞 {self.like_count} 次")
if __name__ == "__main__":
bot = DouyinLikeBot()
bot.run()
"device_id": "emulator-5554",
"max_likes": 200,
"scroll_delay": [1, 3],
"like_delay": [0.5, 2],
"session_timeout": 7200,
"detect_interval": 60,
"blacklist_keywords": ["广告", "推广", "营销"],
"whitelist_keywords": ["科技", "编程", "人工智能"]
}