ShortDL is a tool for downloading YouTube videos, extracting metadata, and storing checksum values to avoid duplicate downloads.
- Download YouTube videos.
- Extract metadata, including description, captions, title, and transcript.
- Store and check checksum values in a PostgreSQL database to avoid duplicate downloads.
- Handle sensitive content and various errors gracefully.
- Go 1.16+
- Docker
- PostgreSQL
- Gin framework
- GORM
youtube/v2
library
-
Run PostgreSQL in Docker:
docker run --rm --name dev-postgres -p 5432:5432 -e POSTGRES_PASSWORD=12345678 -d postgres
-
Initialize the Database:
Ensure the database is running and update the connection string in
database/connect.go
if necessary.
- Update the
DSN
indatabase/connect.go
with your PostgreSQL credentials.
main.go
: Application entry point.routes/routes.go
: Defines API routes.services/syoutube.go
: Contains the logic for downloading videos and extracting metadata.database/database.go
: Database connection and initialization.models/models.go
: Defines the database models.utils/utils.go
: Utility functions.handler/handler.go
: Error handling.
-
Clone the repository:
git clone https://github.com/yourusername/shortdl.git cd shortdl
-
Install dependencies:
go mod tidy
-
Run the application:
go run main.go
-
GET /yshort
Extracts the video ID from the URL, downloads the video, and stores metadata.
Request:
GET /yshort?url=https://www.youtube.com/watch?v=YOUR_VIDEO_ID
Response:
{ "message": "Successfully downloaded youtube", "data": { "Description": "Video description", "Caption": { "BaseUrl": "https://...", "Name": { "Language": "English", "Value": "English" } }, "Title": "Video title", "Transcript": "Transcript text" } }
- Ensure the
download
directory exists in the root of the project to store downloaded videos. - The application checks for existing checksums to avoid downloading duplicate videos.
- Update
utils/utils.go
andhandler/handler.go
as needed to match your project structure.
MIT License. See LICENSE for more information.