Skip to content

Beyrad/xarin-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

103 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎡 Music Player Backend

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.

Java License Status

✨ Features

🎧 Music Management

  • 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 Management

  • 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

πŸ“š Playlist System

  • 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

πŸ” Security & Validation

  • Input Validation: Comprehensive validation for usernames, emails, and passwords
  • Exception Handling: Custom exception classes for better error management
  • Secure Storage: Serialized user data storage

πŸš€ Getting Started

Prerequisites

  • Java 17 or higher
  • IntelliJ IDEA (recommended) or any Java IDE
  • MP3 files for testing

Installation & Setup

  1. Clone the repository

    git clone https://github.com/yourusername/music-player-backend.git
    cd music-player-backend
  2. Download required JAR dependencies

  3. 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
  4. Run the server

    • Open src/Server.java in IntelliJ
    • Right-click on the main method β†’ "Run 'Server.main()'"
    • Or use the green play button next to the main method

The server will start on port 8888.

Alternative: Command Line (with JARs in classpath)

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" Server

Note: Make sure the JAR files are in the same directory as your source files when using command line.

πŸ“‘ API Endpoints

Authentication Endpoints

User Registration

POST /user/signup/

Payload:

{
  "username": "string",
  "password": "string",
  "email": "string"
}

User Login

POST /user/login/

Payload:

{
  "username": "string",
  "password": "string"
}

User Management

Get User Data

GET /user/get_data/

Payload:

{
  "username": "string",
  "password": "string"
}

Playlist Management

Get All Playlists

GET /playlist/

Returns all playlists for the authenticated user.

Get Specific Playlist

GET /playlist/{id}/

Returns a specific playlist by ID.

Create Playlist

POST /playlist/add/

Payload:

{
  "username": "string",
  "password": "string",
  "name": "string",
  "maxSize": "number"
}

Remove Playlist

POST /playlist/remove/

Payload:

{
  "username": "string",
  "password": "string",
  "id": "number"
}

Add Music to Playlist

POST /playlist/{id}/add/

Payload:

{
  "username": "string",
  "password": "string",
  "uuid": "string"
}

Remove Music from Playlist

POST /playlist/{id}/remove/

Payload:

{
  "username": "string",
  "password": "string",
  "uuid": "string"
}

Music Management

Get All Music

GET /audio/get/

Returns all available music in the system.

Get Specific Music

GET /audio/get/{uuid}/

Returns music information by UUID.

Download Music

GET /audio/download/{uuid}/

Downloads music file by UUID.

Upload Music

POST /audio/upload/

Payload:

{
  "username": "string",
  "password": "string",
  "base64": "string"
}

Utility Endpoints

Check if Music is Liked

POST /is_liked/

Payload:

{
  "username": "string",
  "password": "string",
  "uuid": "string"
}

πŸ—οΈ Project Structure

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

πŸ”§ Configuration

Server Configuration

  • Port: 8888 (configurable in Server.java)
  • Database Path: Database/ directory
  • User Files: Database/Users/ directory
  • Music Files: Database/Musics/ directory
  • Uploads: Database/Uploads/ directory

Dependencies

  • Gson 2.13.1: JSON parsing and serialization
  • MP3agic 0.9.1: MP3 metadata extraction and file handling

Validation Rules

Username

  • Lowercase letters and numbers only
  • No special characters

Password

  • Minimum 8 characters
  • Must contain uppercase, lowercase, and numbers
  • Cannot contain username
  • Alphanumeric characters only

Email

  • Standard email format validation
  • Must match pattern: x@y.z

πŸ“Š Response Format

All API responses follow a consistent JSON format:

{
  "status": "number",
  "message": "string",
  "data": "object"
}

Status Codes

  • 200: Success
  • 201: Created
  • 400: Bad Request
  • 401: Unauthorized
  • 403: Forbidden
  • 404: Not Found
  • 500: Internal Server Error

πŸš€ Usage Examples

Creating a User

curl -X POST http://localhost:8888/user/signup/ \
  -H "Content-Type: application/json" \
  -d '{
    "username": "musiclover",
    "password": "SecurePass123",
    "email": "user@example.com"
  }'

Adding Music to Playlist

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"
  }'

πŸ› οΈ Development

Adding New Features

  1. Create new route handlers in Server.java
  2. Add validation logic in appropriate classes
  3. Update exception handling as needed
  4. Test thoroughly with various inputs

Testing

  • Test all endpoints with valid and invalid data
  • Verify error handling and response codes
  • Test file upload/download functionality
  • Validate playlist operations

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Built with Java and Google Gson for JSON handling
  • MP3 metadata extraction using mp3agic library
  • Socket-based communication for real-time operations

πŸ“ž Support

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

About

Music Player Backend written in java for SBU AP spring 1404/2025 project

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors