douyin-downloader/Dockerfile
jiji262 a7dfcfb8b7 refactor: comprehensive code quality improvements and engineering enhancements
Round 1 - Core fixes:
- Persistent DB connection pool (replace per-operation connect/disconnect)
- Filter sensitive fields (cookies, api_key) before writing to DB history
- Fix bare except clause in validators.py
- Close database connection on exit in cli/main.py

Round 1 - Code improvements:
- Extract shared expansion logic from mix/music strategies into base class
- Add nested aweme extraction (_extract_aweme_from_item) for robust parsing
- Move date parsing outside loop in _filter_by_time for performance
- Unify all logger calls from f-string to lazy %s style (12 files)
- Centralize version number from __init__.__version__

Round 1 - Engineering:
- Add pyproject.toml with optional deps (browser, transcribe, dev)
- Add Dockerfile and .dockerignore for container deployment
- Update User-Agent pool (Chrome 130/131, Firefox 133) with rotation
- Add download integrity check (Content-Length validation + cleanup)
- Replace assert with proper runtime checks in production code

Round 2 - Robustness:
- Add retry logic to _request_json (3 attempts with backoff, skip retry on 4xx)
- Make rate_limit and database_path configurable via config.yml
- Guard DOUYIN_THREAD env var parsing against non-numeric values
- Atomic file download: write to .tmp then os.replace to prevent corrupt files
- Add exception handling in _expand_metadata_items fetcher calls
- Scope set_console_log_level to app loggers only (no third-party side effects)
- Fix MusicDownloader to extract real author name from aweme data
- Validate RateLimiter max_per_second > 0 (fallback to default)
- Add config validation for thread/retry_times range and start_time/end_time format
- Clean up run.py: remove fragile Whisper interactive logic
- Make __version__ import robust with try/except fallback

Round 2 - Tests (93 total, +15 new):
- test_file_manager: file_exists, get_file_size, atomic write, size mismatch cleanup
- test_rate_limiter: interval enforcement, invalid value handling
- test_retry_handler: first-try success, retry-then-succeed, exhaustion raises
- test_config_validation: invalid thread, invalid start_time, bad env var

Documentation:
- Rewrite README.md and README.zh-CN.md with comprehensive feature tables,
  all download modes, Docker usage, re-download instructions, and FAQ

Made-with: Cursor
2026-03-06 16:16:22 +08:00

20 lines
370 B
Docker

FROM python:3.12-slim
WORKDIR /app
RUN apt-get update && \
apt-get install -y --no-install-recommends gcc && \
rm -rf /var/lib/apt/lists/*
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
RUN mkdir -p /app/Downloaded
VOLUME ["/app/Downloaded", "/app/config.yml"]
ENTRYPOINT ["python", "run.py"]
CMD ["-c", "config.yml"]