6.5 KiB
6.5 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
MeTube is a web-based GUI for youtube-dl/yt-dlp that allows downloading videos from YouTube and 100+ other sites. It consists of a Python backend with aiohttp and an Angular frontend, providing real-time download progress via WebSocket.
Development Commands
Frontend Development
cd ui
npm install # Install Angular dependencies
npm run build # Build production frontend
npm run start # Start development server
npm run lint # Run Angular linting
npm run test # Run Angular tests
Backend Development
# Install Python dependencies using uv (preferred)
curl -LsSf https://astral.sh/uv/install.sh | sh
uv sync # Install dependencies from pyproject.toml
uv run python3 app/main.py # Run the backend server
# Alternative using pip
pip install -r requirements.txt
python3 app/main.py
Docker Development
docker build -t metube . # Build Docker image
docker-compose up -d # Run with docker-compose
docker-compose up -d --build --force-recreate # Rebuild and restart
Code Quality
# Python linting
pylint app/ # Run pylint on Python code
# Type checking (if configured)
pyright # Run Python type checking
Architecture Overview
Backend Structure (app/)
main.py: Main aiohttp server with REST API and WebSocket supportytdl.py: Download queue management, yt-dlp integration, and notifier patterndl_formats.py: Format selection logic for video/audio downloads
Frontend Structure (ui/src/app/)
app.component.ts/html: Main UI component with download interfacedownloads.service.ts: HTTP client for backend API communicationmetube-socket.ts: WebSocket client for real-time updatesdownloads.pipe.ts: Angular pipes for formatting download info
Key Technologies
- Backend: Python 3.13+, aiohttp, python-socketio, yt-dlp, shelve storage
- Frontend: Angular 19+, TypeScript, Bootstrap 5, FontAwesome
- Communication: REST API + WebSocket for real-time updates
- Storage: Shelve-based persistent queues in STATE_DIR
Environment Configuration
Key environment variables (see README.md for complete list):
DOWNLOAD_DIR: Download location (default:/downloads)DOWNLOAD_MODE:sequential|concurrent|limited(default:limited)MAX_CONCURRENT_DOWNLOADS: For limited mode (default: 3)YTDL_OPTIONS: JSON options passed to yt-dlpURL_PREFIX: For reverse proxy setupsHOST/PORT: Server binding (default: 0.0.0.0:8081)
API Endpoints
REST API
POST /add: Add new downloadPOST /delete: Cancel/delete downloadGET /history: Get download historyGET /info: Get server info and configuration
WebSocket Events
added: New download queuedupdated: Download progress updatecompleted: Download finishedcanceled: Download canceledcleared: Download removed from history
Next Implementation: Playlist Monitor Service
The PLAYLIST_MONITOR_ARCHITECTURE.md document outlines a comprehensive plan for adding automated playlist monitoring capabilities. This should be implemented as a separate microservice.
Architecture Summary
- Service Type: FastAPI-based microservice (Python 3.13+)
- Database: SQLite with SQLAlchemy ORM
- Scheduler: APScheduler for periodic tasks
- Integration: MeTube REST API + WebSocket client
- Deployment: Docker container alongside MeTube
Key Components
- Playlist Manager: Subscription management, yt-dlp integration
- Video Tracker: Status tracking, file movement handling
- Scheduler Engine: Periodic playlist checking, download triggering
- State Manager: SQLite persistence, data migrations
- MeTube Client: HTTP/WebSocket communication
Implementation Phases (6 weeks)
- Phase 1: Core infrastructure, FastAPI setup, database models
- Phase 2: Playlist management, yt-dlp integration, start point logic
- Phase 3: Scheduler, periodic checks, MeTube integration
- Phase 4: File tracking, re-downloads, error handling
- Phase 5: UI integration (extend MeTube Angular or separate frontend)
- Phase 6: Testing, Docker containerization, documentation
API Design
/api/playlists: CRUD operations for playlist subscriptions/api/playlists/{id}/videos: Video status management/api/videos/{id}/download: Manual download triggering/api/status: System health and statistics
Database Schema
playlists: Subscription configurationvideos: Individual video tracking with status, errors, file locationactivity_log: Audit trail for operations
Configuration
metube:
url: http://localhost:8081
scheduler:
default_check_interval: 60 # minutes
max_concurrent_downloads: 3
database:
url: sqlite:///data/playlists.db
Key Implementation Notes
- Download Queue Management: Uses async patterns with notifier callbacks for real-time updates
- Format Selection: Complex logic in
dl_formats.pyhandles quality/format preferences - Error Handling: Robust error tracking and retry mechanisms built into ytdl.py
- File Organization: Supports custom directories, templates, and file naming patterns
- WebSocket Integration: Real-time communication between backend and frontend
- Docker Considerations: Multi-stage builds, volume mounts for downloads, environment configuration
Common Development Tasks
Adding New Download Features
- Update
ytdl.pyfor backend logic - Modify
app/main.pyfor new API endpoints - Update frontend components in
ui/src/app/ - Test with various URLs and formats
Modifying Frontend
- Angular components in
ui/src/app/ - Use existing Bootstrap 5 styling
- Maintain WebSocket connection patterns
- Test build process with
npm run build
Database/Storage Changes
- Shelve storage in STATE_DIR (default:
/downloads/.metube) - Persistent queue files:
completed,pending,queue - Cookie storage in
cookies/subdirectory
Testing Downloads
- Use Docker for consistent environment
- Test with various sites from yt-dlp supported sites
- Check different quality/format combinations
- Verify WebSocket updates in frontend