Automating Douyin Likes with Python, ADB, and Baidu AI Face Recognition
This article demonstrates how to build a Python-based Douyin crawler that uses ADB to control an Android device, captures screenshots, employs Baidu AI face recognition to detect high‑scoring female faces, and automatically likes videos meeting the criteria.
This guide explains how to create a Douyin (TikTok) automation script that automatically likes videos featuring attractive female faces. The solution combines Python, Android Debug Bridge (ADB) commands, and Baidu AI's face‑recognition API.
Prerequisites : Python environment (Anaconda recommended), ADB installed and device debugging enabled, and a Baidu AI account with appid , api_key , and secret_key for the face‑recognition service.
ADB basics : ADB acts as a bridge to control Android apps. Key commands used are:
# Launch Douyin app
adb shell am start -n com.ss.android.ugc.aweme com.ss.android.ugc.aweme.splash.SplashActivity # Simulate a tap on the like button (example coordinates)
adb shell input tap 1330 1750 # Swipe up to the next video
adb shell input swipe 900 1400 400 1400 100The script defines the package and activity names:
# Douyin app package and initial activity
package_name = 'com.ss.android.ugc.aweme'
activity_name = 'com.ss.android.ugc.aweme.splash.SplashActivity'Python ADB control functions handle launching the app, taking screenshots, saving liked videos, and swiping to the next video:
import os
from PIL import Image
def start_my_app(package_name, activity_name):
os.popen('adb shell am start -n %s/%s' % (package_name, activity_name))
def save_video_met(screen_name, find_girl_num):
img = Image.open(screen_name).convert('RGB')
img.save("漂亮的小姐姐/DYGirl_%d.jpg" % find_girl_num)
os.system('adb shell input tap 1330 1750')
def play_next_video():
os.system('adb shell input swipe 540 1300 540 500 100')
def get_screen_shot_part_img(image_name):
os.system('adb shell /system/bin/screencap -p /sdcard/screenshot.jpg')
os.system('adb pull /sdcard/screenshot.jpg %s' % image_name)
img = Image.open(image_name).convert('RGB')
w, h = img.size
img = img.crop((0, 400, 1200, 2750))
img.thumbnail((int(w/1.5), int(h/1.5)))
img.save(image_name)
return image_nameMain crawling logic repeatedly captures screenshots, sends them to Baidu AI for face analysis, and decides whether to like the video based on gender and a beauty score threshold (≥70). If a suitable face is found, the script likes the video and moves on; otherwise it continues scanning until a timeout is reached.
import datetime, time, shutil
if __name__ == '__main__':
access_token = get_access_token()
RECOGNITE_TOTAL_TIME = 10
TYPE_IMAGE_LOCAL = 1
start_my_app(package_name, activity_name)
time.sleep(5)
find_girl_num = 0
while True:
recognite_time_start = datetime.datetime.now()
recognite_count = 1
while True:
screen_name = get_screen_shot_part_img('images/temp%d.jpg' % recognite_count)
recognite_result = analysis_face(parse_face_pic(screen_name, TYPE_IMAGE_LOCAL, access_token))
recognite_count += 1
recognite_time_end = datetime.datetime.now()
if recognite_result:
find_girl_num += 1
save_video_met(screen_name, find_girl_num)
print('已经发现 %d 个漂亮小姐姐' % find_girl_num)
break
else:
if (recognite_time_end - recognite_time_start).seconds < RECOGNITE_TOTAL_TIME:
continue
else:
print('超时!!!这是一条没有吸引力的视频!')
break
shutil.rmtree('./images')
time.sleep(0.05)
os.mkdir('./images')
print('==' * 30)
time.sleep(2)
print('准备播放下一个视频~')
play_next_video()
time.sleep(2)Adjust the screen coordinates in the ADB commands to match your device's resolution. The author notes that after a few days of running the crawler, Douyin's recommendation algorithm starts showing predominantly attractive videos, confirming the effectiveness of the automated liking strategy.
Conclusion : By integrating ADB automation with AI‑driven face analysis, developers can build a self‑sustaining Douyin bot that selectively engages with content, showcasing a practical application of mobile automation and computer vision.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.