Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 102 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,122 @@
# Simple Flask Music Streaming App
# 🎵 Enhanced Flask Music Streaming

A simple Flask app for streaming music
This project is a fully enhanced music streaming built using **Flask** and served with **Tornado**. It supports uploading, playing, updating, and deleting `.mp3` music files through both a **web UI** and a **RESTful API** with **Swagger documentation**.

## Getting Started
---

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
## 🚀 Features

### Prerequisites
- 🎼 **Persistent music library** stored in `music_db.json`
- 🔼 **Upload `.mp3` files** via web form
- 🔁 **Full CRUD support**:
- Create, Read, Update, and Delete music metadata and files
- 🎧 **Stream music on demand** by ID
- 🌐 **Two UI views**:
- `/` — Minimalist "Simple" player
- `/design` — Bootstrap-styled "Design" player
- 🧠 **Swagger/OpenAPI Documentation** at `/apidocs`
- 🛡️ **Validation**:
- Accepts only `.mp3` files
- Safe file naming with `secure_filename()`
- 📋 **Request logging** with HTTP method, path, and response status

What things you need to install the software and how to install them
---

## 📂 Project Structure

```
Python 3
Flask
Tornado Web Server
├── app.py # Main Flask app with Tornado integration
├── music_db.json # Stores music metadata persistently
├── static/
│ └── music/ # Uploaded `.mp3` files
├── templates/
│ ├── simple.html # Minimal Streaming UI
│ └── design.html # Bootstrap-based Streaming UI
```

### Installing
---

## 🔗 API Endpoints

| Method | Endpoint | Description |
|--------|---------------------------|----------------------------------|
| GET | `/api/music` | List all music entries |
| GET | `/<int:stream_id>` | Stream a music file by ID |
| POST | `/api/music` | Upload a new music file |
| PUT | `/api/music/<id>` | Update metadata for a music file |
| DELETE | `/api/music/<id>` | Delete a music entry and file |

---

## 🧪 Example API Usage

### Upload Music

Installing dependencies
```
pip install -r requirements.txt
POST /api/music
Content-Type: multipart/form-data
Fields:
- name: My Song
- genre: Rock
- rating: 5
- file: [MP3 file]
- redirect_to: simple | design
```
Once all packages are downloaded and installed run.

### Update Music Metadata

```
python app.py
PUT /api/music/1
Content-Type: application/x-www-form-urlencoded
Fields:
- name: New Name
- genre: Pop
- rating: 4
```

## Running the tests
### Delete Music

Open up your browser and visit
```
http://localhost:5000
DELETE /api/music/1
```

---

## 📦 Requirements

- Python 3.x
- Flask
- Tornado
- flasgger
- werkzeug

Install with:

```bash
pip install -r requirements.txt
```

---

## 🧰 Running the App

```bash
python app.py
```

Visit:

```
http://localhost:5000/
http://localhost:5000/design
http://localhost:5000/apidocs
```

---

## 📝 Notes

- The server runs using Tornado for enhanced asynchronous handling.
- Music files are streamed directly from the `static/music` folder.
- Only `.mp3` files are accepted for upload.
- Use Swagger UI to test endpoints interactively.
Binary file added __pycache__/app.cpython-311.pyc
Binary file not shown.
Binary file added __pycache__/testing.cpython-311-pytest-8.3.5.pyc
Binary file not shown.
Loading