A FastAPI service for handling YouTube videos and channels data with MongoDB.
- YouTube video and channel data management
- MongoDB integration with Motor (async driver)
- RESTful API with proper validation and error handling
- Pagination and filtering support
- OpenAPI documentation
- Python 3.8+
- MongoDB
- Clone this repository
git clone https://github.com/yourusername/ugc-service.git
cd ugc-service- Create a virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies
pip install -r requirements.txt- Configure environment variables (or modify .env file)
MONGODB_URL=mongodb://localhost:27017
DATABASE_NAME=ugc_db
API_PREFIX=/api/v1
DEBUG=true
Start the API server:
python -m uvicorn app.main:app --reloadThe API will be available at http://localhost:8000, and the documentation at http://localhost:8000/api/v1/docs.
GET /api/v1/youtube/videos/- Get all videos (paginated)GET /api/v1/youtube/videos/{video_id}- Get a specific video (MongoDB ID or YouTube ID)POST /api/v1/youtube/videos/- Create a new videoPUT /api/v1/youtube/videos/{video_id}- Update a videoDELETE /api/v1/youtube/videos/{video_id}- Delete a videoGET /api/v1/youtube/videos/search/- Search videos with filters
GET /api/v1/youtube/channels/- Get all channels (paginated)GET /api/v1/youtube/channels/{channel_id}- Get a specific channel (MongoDB ID or YouTube ID)POST /api/v1/youtube/channels/- Create a new channelPUT /api/v1/youtube/channels/{channel_id}- Update a channelDELETE /api/v1/youtube/channels/{channel_id}- Delete a channelGET /api/v1/youtube/channels/{channel_id}/videos- Get videos for a specific channel
ugc-service/
│
├── app/ # Application package
│ ├── api/ # API endpoints
│ │ └── routes/ # API routes
│ ├── core/ # Core application code
│ ├── db/ # Database related code
│ ├── models/ # Data models
│ ├── schemas/ # Pydantic schemas
│ ├── services/ # Business logic
│ └── main.py # FastAPI application entry point
│
├── tests/ # Test directory
├── .env # Environment variables
├── requirements.txt # Python dependencies
└── README.md # Project documentation
Run tests with pytest:
pytestThe service supports the following data models:
YouTube video data with fields like:
- video_id, title, description
- channel information
- view/like/comment counts
- thumbnails
- tags
- comments
YouTube channel data with fields like:
- channel_id, title, description
- subscriber/view counts
- thumbnails
- country
- topic categories