A robust, feature-rich backend server for a music streaming application similar to Spotify. Built with Java, this server provides comprehensive music management capabilities including user authentication, playlist management, music upload/download, and more.
- Music Upload: Upload MP3 files to the server with automatic metadata extraction
- Music Download: Download music files from the server
- Music Library: Comprehensive music database with UUID-based identification
- Metadata Support: Automatic extraction of duration, file size, and music information
- User Registration: Secure signup with validation
- User Authentication: Login system with credential verification
- Profile Management: User data retrieval and management
- Security: Password hashing and validation rules
- Dynamic Playlists: Create, manage, and customize playlists
- Default Playlists: Automatic "All" and "Likes" playlists for every user
- Music Operations: Add/remove music from playlists
- Playlist Limits: Configurable maximum size for playlists
- Input Validation: Comprehensive validation for usernames, emails, and passwords
- Exception Handling: Custom exception classes for better error management
- Secure Storage: Serialized user data storage
- Java 17 or higher
- IntelliJ IDEA (recommended) or any Java IDE
- MP3 files for testing
-
Clone the repository
git clone https://github.com/yourusername/music-player-backend.git cd music-player-backend -
Download required JAR dependencies
- Gson JAR: Download Gson 2.13.1
- MP3agic JAR: Download MP3agic 0.9.1
-
Set up in IntelliJ IDEA
- Open the project in IntelliJ IDEA
- Right-click on the project β "Open Module Settings" (or press F4)
- Go to "Libraries" tab
- Click the "+" button β "Java"
- Select both downloaded JAR files (gson-2.13.1.jar and mp3agic-0.9.1.jar)
- Click "OK" to add them to your project
-
Run the server
- Open
src/Server.javain IntelliJ - Right-click on the
mainmethod β "Run 'Server.main()'" - Or use the green play button next to the main method
- Open
The server will start on port 8888.
If you prefer to run from command line after setting up the JARs:
# Compile the project
javac -cp ".:gson-2.13.1.jar:mp3agic-0.9.1.jar" src/*.java
# Run the server
java -cp ".:src:gson-2.13.1.jar:mp3agic-0.9.1.jar" ServerNote: Make sure the JAR files are in the same directory as your source files when using command line.
POST /user/signup/
Payload:
{
"username": "string",
"password": "string",
"email": "string"
}POST /user/login/
Payload:
{
"username": "string",
"password": "string"
}GET /user/get_data/
Payload:
{
"username": "string",
"password": "string"
}GET /playlist/
Returns all playlists for the authenticated user.
GET /playlist/{id}/
Returns a specific playlist by ID.
POST /playlist/add/
Payload:
{
"username": "string",
"password": "string",
"name": "string",
"maxSize": "number"
}POST /playlist/remove/
Payload:
{
"username": "string",
"password": "string",
"id": "number"
}POST /playlist/{id}/add/
Payload:
{
"username": "string",
"password": "string",
"uuid": "string"
}POST /playlist/{id}/remove/
Payload:
{
"username": "string",
"password": "string",
"uuid": "string"
}GET /audio/get/
Returns all available music in the system.
GET /audio/get/{uuid}/
Returns music information by UUID.
GET /audio/download/{uuid}/
Downloads music file by UUID.
POST /audio/upload/
Payload:
{
"username": "string",
"password": "string",
"base64": "string"
}POST /is_liked/
Payload:
{
"username": "string",
"password": "string",
"uuid": "string"
}src/
βββ _Exceptions/ # Custom exception classes
β βββ FailedLogin.java
β βββ UsernameAlreadyExists.java
β βββ UsernameNotFound.java
β βββ WrongEmailFormatException.java
β βββ WrongPasswordFormatException.java
β βββ WrongUsernameFormatException.java
βββ AdminPannel.java # Admin functionality
βββ Login.java # Login logic
βββ Main.java # Main entry point
βββ PlayList.java # Playlist management
βββ Server.java # Main server implementation
βββ ServerMusic.java # Music file handling
βββ SignUp.java # User registration
βββ User.java # User model and operations
- Port: 8888 (configurable in
Server.java) - Database Path:
Database/directory - User Files:
Database/Users/directory - Music Files:
Database/Musics/directory - Uploads:
Database/Uploads/directory
- Gson 2.13.1: JSON parsing and serialization
- MP3agic 0.9.1: MP3 metadata extraction and file handling
- Lowercase letters and numbers only
- No special characters
- Minimum 8 characters
- Must contain uppercase, lowercase, and numbers
- Cannot contain username
- Alphanumeric characters only
- Standard email format validation
- Must match pattern:
x@y.z
All API responses follow a consistent JSON format:
{
"status": "number",
"message": "string",
"data": "object"
}200: Success201: Created400: Bad Request401: Unauthorized403: Forbidden404: Not Found500: Internal Server Error
curl -X POST http://localhost:8888/user/signup/ \
-H "Content-Type: application/json" \
-d '{
"username": "musiclover",
"password": "SecurePass123",
"email": "user@example.com"
}'curl -X POST http://localhost:8888/playlist/2/add/ \
-H "Content-Type: application/json" \
-d '{
"username": "musiclover",
"password": "SecurePass123",
"uuid": "123e4567-e89b-12d3-a456-426614174000"
}'- Create new route handlers in
Server.java - Add validation logic in appropriate classes
- Update exception handling as needed
- Test thoroughly with various inputs
- Test all endpoints with valid and invalid data
- Verify error handling and response codes
- Test file upload/download functionality
- Validate playlist operations
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with Java and Google Gson for JSON handling
- MP3 metadata extraction using mp3agic library
- Socket-based communication for real-time operations
If you have any questions or need help, please open an issue on GitHub or contact the development team.
Made with β€οΈ for music lovers everywhere