Solve TikTok CAPTCHAs locally using OpenCV - supports slide, rotate, and 3D shapes captchas
Project description
TikTok CAPTCHA Solver 🧩
A Python library for solving TikTok CAPTCHAs using OpenCV.
Get your API key at: https://captchasolved.com
Supports:
- ✅ Slide/Puzzle CAPTCHA - Slide a piece to fit into a gap
- ✅ Rotate/Whirl CAPTCHA - Rotate an image to match the background
- ✅ 3D Shapes CAPTCHA - Click on matching 3D objects
Features
- 🚀 Fast - Solves CAPTCHAs in milliseconds using optimized OpenCV algorithms
- 🎯 Accurate - High accuracy using edge detection and template matching
- 🔌 Easy Integration - Works with Selenium, Playwright, or standalone
- 🐍 Pure Python - Simple pip install
Installation
pip install captchasolved
With Browser Automation Support
# For Selenium
pip install captchasolved[selenium]
# For Playwright
pip install captchasolved[playwright]
# For both
pip install captchasolved[all]
Quick Start
1. Get Your API Key
Sign up at https://captchasolved.com to get your API key.
2. Set Your API Key
from tiktok_captcha_solver import set_api_key
# Option 1: Set in code
set_api_key("cs_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
# Option 2: Set via environment variable
# export CAPTCHA_SOLVER_API_KEY="cs_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
3. Solve CAPTCHAs
from tiktok_captcha_solver import TikTokCaptchaSolver, set_api_key
set_api_key("cs_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
solver = TikTokCaptchaSolver()
# Solve slide/puzzle captcha
result = solver.solve_slide(
background="path/to/background.png", # or base64, bytes, numpy array
piece="path/to/piece.png"
)
print(f"Slide distance: {result.x} pixels")
print(f"Confidence: {result.confidence}")
# Solve rotate captcha
result = solver.solve_rotate(
outer="path/to/outer.png",
inner="path/to/inner.png"
)
print(f"Rotate angle: {result.angle} degrees")
# Solve 3D shapes captcha
result = solver.solve_shapes(
image="path/to/shapes.png"
)
print(f"Click points: ({result.x1}, {result.y1}) and ({result.x2}, {result.y2})")
With Selenium
from tiktok_captcha_solver import SeleniumSolver, set_api_key
from selenium import webdriver
set_api_key("cs_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
driver = webdriver.Chrome()
driver.get("https://www.tiktok.com/login")
solver = SeleniumSolver(driver)
solver.solve_captcha_if_present()
With Playwright (Sync)
from tiktok_captcha_solver import PlaywrightSolver, set_api_key
from playwright.sync_api import sync_playwright
set_api_key("cs_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
with sync_playwright() as p:
browser = p.chromium.launch(headless=False)
page = browser.new_page()
page.goto("https://www.tiktok.com/login")
solver = PlaywrightSolver(page)
solver.solve_captcha_if_present()
With Playwright (Async)
import asyncio
from tiktok_captcha_solver import AsyncPlaywrightSolver, set_api_key
from playwright.async_api import async_playwright
set_api_key("cs_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
async def main():
async with async_playwright() as p:
browser = await p.chromium.launch(headless=False)
page = await browser.new_page()
await page.goto("https://www.tiktok.com/login")
solver = AsyncPlaywrightSolver(page)
await solver.solve_captcha_if_present()
asyncio.run(main())
Pricing
| Plan | Solves | Price |
|---|---|---|
| Starter | 1,000 | $9 |
| Pro | 10,000 | $49 |
| Enterprise | 100,000 | $299 |
Get your API key at: https://captchasolved.com
Check Your Usage
from tiktok_captcha_solver import get_usage_info
info = get_usage_info()
print(f"Plan: {info['plan']}")
print(f"Remaining: {info['remaining_solves']} solves")
API Reference
TikTokCaptchaSolver
Main solver class that combines all CAPTCHA types.
solver = TikTokCaptchaSolver()
Methods
solve_slide(background, piece, piece_start_x=0) -> SlideResult
Solve a slide/puzzle CAPTCHA.
Parameters:
background: Background image (path, base64, bytes, numpy array, or PIL Image)piece: Puzzle piece imagepiece_start_x: Starting X position of the piece (default: 0)
Returns: SlideResult with:
x: X position/slide distancey: Y positionconfidence: Match confidence (0-1)
solve_rotate(outer, inner) -> RotateResult
Solve a rotate/whirl CAPTCHA.
Parameters:
outer: Outer/background imageinner: Inner image to rotate
Returns: RotateResult with:
angle: Degrees to rotateconfidence: Match confidence (0-1)
solve_shapes(image) -> ShapesResult
Solve a 3D shapes matching CAPTCHA.
Parameters:
image: CAPTCHA image with shapes
Returns: ShapesResult with:
x1, y1: First click pointx2, y2: Second click pointconfidence: Match confidence (0-1)
SeleniumSolver
Selenium integration with automatic CAPTCHA detection.
solver = SeleniumSolver(
driver, # Selenium WebDriver instance
max_retries=3, # Max retry attempts
retry_delay=1.0, # Delay between retries
callback=None # Optional callback(event, data)
)
Methods
solve_captcha_if_present(): Detect and solve any CAPTCHAsolve_slide_captcha(): Solve slide CAPTCHAsolve_rotate_captcha(): Solve rotate CAPTCHAsolve_shapes_captcha(): Solve shapes CAPTCHAdetect_captcha_type(): Returns 'slide', 'rotate', 'shapes', or None
PlaywrightSolver / AsyncPlaywrightSolver
Playwright integration (sync and async versions).
# Sync
solver = PlaywrightSolver(page, max_retries=3, retry_delay=1.0, callback=None)
# Async
solver = AsyncPlaywrightSolver(page, max_retries=3, retry_delay=1.0, callback=None)
Same methods as SeleniumSolver (async versions return coroutines).
Advanced Usage
Using Individual Solvers
from tiktok_captcha_solver import SlideSolver, RotateSolver, ShapesSolver
# Slide solver with custom settings
slide_solver = SlideSolver(use_edge_detection=True)
result = slide_solver.solve(background, piece)
# Get position as ratio (useful for different screen sizes)
x_ratio, y_ratio = slide_solver.solve_with_ratio(background, piece)
# Rotate solver with custom angle steps
rotate_solver = RotateSolver(angle_step=1.0, refine_step=0.1)
result = rotate_solver.solve(outer, inner)
# Get as drag distance for a slider
distance = rotate_solver.solve_as_distance(outer, inner, slider_width=348)
Callback Events
def on_event(event, data):
print(f"Event: {event}, Data: {data}")
solver = SeleniumSolver(driver, callback=on_event)
solver.solve_captcha_if_present()
# Events:
# - 'solving': Starting to solve (data = captcha type)
# - 'solved': Solution found (data = result)
# - 'attempt': Retry attempt (data = attempt number)
# - 'success': Successfully solved
# - 'failed': Failed to solve
# - 'error': Error occurred (data = error message)
Loading Images
The solver accepts multiple image formats:
# File path
result = solver.solve_slide("background.png", "piece.png")
# Base64 string
result = solver.solve_slide(base64_bg, base64_piece)
# Bytes
result = solver.solve_slide(image_bytes_bg, image_bytes_piece)
# NumPy array (OpenCV format)
import cv2
bg = cv2.imread("background.png")
result = solver.solve_slide(bg, piece_array)
# PIL Image
from PIL import Image
bg = Image.open("background.png")
result = solver.solve_slide(bg, piece_image)
How It Works
Slide/Puzzle CAPTCHA
- Load background and puzzle piece images
- Remove whitespace/transparent borders from piece
- Apply Canny edge detection to both images
- Use OpenCV template matching (
cv2.matchTemplate) - Find the position with highest correlation score
Rotate/Whirl CAPTCHA
- Load outer and inner images
- Rotate inner image through 0-360 degrees
- Calculate similarity between rotated inner and outer
- Find angle with highest similarity
- Refine with smaller angle steps
3D Shapes CAPTCHA
- Load the CAPTCHA image
- Detect shape regions using contour detection
- Extract features using ORB detector
- Compare all pairs of shapes using feature matching
- Return the centers of the best matching pair
Requirements
- Python 3.8+
- OpenCV (opencv-python)
- NumPy
- Pillow
Optional:
- Selenium (for browser automation)
- Playwright (for browser automation)
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License - see LICENSE file.
Disclaimer
This library is for educational purposes only. Please ensure you comply with TikTok's Terms of Service when using this library. The authors are not responsible for any misuse of this software.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ttcaptchasolved-1.0.0.tar.gz.
File metadata
- Download URL: ttcaptchasolved-1.0.0.tar.gz
- Upload date:
- Size: 19.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
689c292c222b8f878113100c80bb92fa7c9a0f458410f3f728f708998df63b09
|
|
| MD5 |
299013d1173997a0865fd30f0a15917e
|
|
| BLAKE2b-256 |
6e3e8a625c777c548f3889c05c054a771afa429242e8cda6ff0c773c18ef10a1
|
File details
Details for the file ttcaptchasolved-1.0.0-py3-none-any.whl.
File metadata
- Download URL: ttcaptchasolved-1.0.0-py3-none-any.whl
- Upload date:
- Size: 22.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7feccb690ced20c9a6556496f905ea5f6ffe8d3188cdf5b60ba9dec9ff0b07c
|
|
| MD5 |
6a979a870c4db910d42ecc8bb548b6f8
|
|
| BLAKE2b-256 |
94ae9add2b2233f0c8fe9548700b729e331bb073dd72d3c4befefa47df134d35
|