A Go-based automated music file processor that downloads audio files from an FTP server, generates multiple bitrate versions (64kbps, 128kbps, 320kbps) using FFmpeg, and uploads them back to the server. The application is designed to work with a REST API for task management and authentication.
- Multi-threaded Processing: Concurrent processing of multiple albums/directories using configurable worker pools
- Automated Bitrate Generation: Creates lower bitrate versions of audio files (64k, 128k, 320k) based on source quality
- Smart Skip Logic: Automatically skips files that already have all required bitrate versions
- FTP Integration: Downloads and uploads files to/from an FTP server
- API Integration: Authenticates and retrieves processing tasks from a REST API
- Docker Support: Fully containerized with Docker and Docker Compose
- FFmpeg Integration: Uses FFmpeg for audio bitrate detection and conversion
The application consists of three main components:
- API Client (
src/api.go): Handles authentication and communication with the Melodyo API - Directory Operator (
src/directory_operator.go): Core processing logic for downloading, converting, and uploading files - Main Worker (
main.go): Orchestrates FTP connections and manages concurrent workers
- Docker and Docker Compose (recommended)
- OR:
- Go 1.16+
- FFmpeg (for audio processing)
- Access to an FTP server
- Access to Melodyo API
- Clone the repository:
git clone https://github.com/melodyo/melodyo-generator.git
cd melodyo-generator- Copy the environment example file and configure it:
cp .env.example .env- Edit the
.envfile with your credentials:
# API Configuration
API_URL=https://your-api-url.com
API_AUTH_ENDPOINT=/auth/login
API_AUTH_EMAIL=your-email@example.com
API_AUTH_PASSWORD=your-password
API_GENERATOR_ENDPOINT=/api/generator
# FTP Configuration
FTP_URL=ftp.your-server.com
FTP_USERNAME=your-ftp-username
FTP_PASSWORD=your-ftp-password
FTP_ROOT=/path/to/music/directory
FTP_PORT=21
# Processing Configuration
CORE_NUMS=4 # Number of concurrent workers (defaults to CPU cores if not set)- Build and run with Docker Compose:
docker-compose up --build -d- View logs:
docker logs -f melodyo-generator- Install Go 1.16 or higher
- Install FFmpeg:
# Ubuntu/Debian
sudo apt-get install ffmpeg
# macOS
brew install ffmpeg- Clone and build:
git clone https://github.com/melodyo/melodyo-generator.git
cd melodyo-generator
go mod download
go build -o melodyo-generator- Set environment variables and run:
export API_URL=https://your-api-url.com
# ... set other environment variables
./melodyo-generator- Authentication: The application authenticates with the Melodyo API using provided credentials
- Fetch Tasks: Retrieves a list of album/directory IDs to process from the API
- FTP Connection Pool: Creates a pool of FTP connections based on
CORE_NUMSsetting - Concurrent Processing: For each directory:
- Downloads original music files from FTP
- Checks the bitrate of each file using FFmpeg
- Determines which bitrate versions are missing (64k, 128k, 320k)
- Generates missing bitrate versions using FFmpeg
- Uploads generated files back to the FTP server
- Notifies the API that processing is complete
- Cleanup: Removes temporary local files after processing
.
├── main.go # Entry point and worker orchestration
├── src/
│ ├── api.go # API authentication and communication
│ └── directory_operator.go # File processing logic
├── Dockerfile # Docker container definition
├── docker-compose.yml # Docker Compose configuration
├── go.mod # Go module dependencies
├── go.sum # Dependency checksums
├── .env.example # Environment variables template
└── downloads/ # Temporary directory for file processing (created at runtime)
# Build and start the container
docker-compose up --build -d
# View logs
docker logs -f melodyo-generator
# Restart the container
docker restart melodyo-generator
# Stop the container
docker stop melodyo-generator
# Remove the container
docker rm -f melodyo-generator| Variable | Description | Example |
|---|---|---|
API_URL |
Base URL of the Melodyo API | https://api.melodyo.com |
API_AUTH_ENDPOINT |
Authentication endpoint path | /auth/login |
API_AUTH_EMAIL |
Email for API authentication | user@example.com |
API_AUTH_PASSWORD |
Password for API authentication | your-password |
API_GENERATOR_ENDPOINT |
Generator endpoint path | /api/generator |
FTP_URL |
FTP server hostname | ftp.example.com |
FTP_USERNAME |
FTP username | ftpuser |
FTP_PASSWORD |
FTP password | ftppass |
FTP_ROOT |
Root directory on FTP server | /music |
FTP_PORT |
FTP port number | 21 |
CORE_NUMS |
Number of concurrent workers | 4 |
The application intelligently determines which bitrates to generate based on the source file quality:
- Source > 320kbps: Generates 320k, 128k, and 64k versions
- Source > 128kbps: Generates 128k and 64k versions
- Source > 64kbps: Generates 64k version only
- Source ≤ 64kbps: No conversion needed
- jlaffaye/ftp - FTP client library
- joho/godotenv - Environment variable management
- FFmpeg - Audio processing (included in Docker image)
go build -o melodyo-generatorgo test ./...The project includes a .gitlab-ci.yml file for GitLab CI/CD pipeline integration.
- FFmpeg not found: Ensure FFmpeg is installed and in your PATH
- FTP connection errors: Verify FTP credentials and network connectivity
- API authentication failures: Check API credentials and endpoint URLs
- Out of memory: Reduce
CORE_NUMSto process fewer files concurrently
Check Docker logs for detailed processing information:
docker logs melodyo-generatorPlease check with the repository owner for licensing information.
Contributions are welcome! Please submit pull requests or open issues for bugs and feature requests.