Skip to content

Valentin387/TrackFinder_backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TrackFinder Backend

FastAPI Python GitHub last commit Issues Pull Requests

Backend for managing a music database with MongoDB Atlas, using FastAPI.

Features

  1. Search Songs: Flexible filtering based on various fields.
  2. List Collections: Retrieve a list of all collections in the database.
  3. Add Songs: Add a new song to a specified collection, with duplicate checks.

Structure

TrackFinder/
│
├── main.py               # Entry point of the application, runs the FastAPI app
├── models/
│   ├── __init__.py       # Initializes the models package
│   └── songModels.py     # Defines the SongMetadata model
├── music_folder/         # Contains JSON files with song metadata
│   └── *.json            # Example: rock.json contains metadata for rock songs
├── routers/
│   ├── __init__.py       # Initializes the routers package
│   └── general_use_router.py # Contains route definitions
├── .env                  # Environment variables for MongoDB connection
├── .gitignore            # Git ignore file
└── seeding_db.py         # Script for seeding the database with JSON files

Environment Setup

Ensure you have a .env file with the following content:

MONGO_DB_USER= ...
MONGO_DB_PASSWORD= ...

So the software can get those and use them here:
MONGO_DB_URL=mongodb+srv://<username>:<password>@cluster0.mongodb.net/<dbname>?retryWrites=true&w=majority

Seeding the Database

To seed the database with song metadata from JSON files, run:

python seeding_db.py

This will populate MongoDB Atlas with your song collections.

Running the Application

To run the application:

python main.py

This will host the API on http://127.0.0.1:8000 by default.

Endpoints

Search Songs

  • Endpoint: /search_songs
  • Method: POST
  • Description: Search for songs based on criteria.
  • Parameters: title, artist, album, release_year, genre ... (all optional).

List Collections

  • Endpoint: /collections
  • Method: GET
  • Description: Retrieve a list of all collections in the database.

Add a New Song

  • Endpoint: /add_song
  • Method: POST
  • Description: Add a new song to a specified collection. If the collection does not exist, it will be created.
  • Parameters:
    • collection_name: The name of the collection (path parameter).
    • SongMetadata: The song data (body parameter).

SongMetadata Model

from pydantic import BaseModel
from typing import Optional

class Song_metadata(BaseModel):
    name: str
    title: str
    sub_title: str
    bitrate: int
    commentaries: str
    main_artist: str
    collaborators: str
    album_artist: str
    album: str
    year: str
    track_number: str
    genre: str
    duration: int

Documentation

Access detailed API documentation generated by FastAPI at http://127.0.0.1:8000/docs after running the application.


Context:

How did all this start?

I don't like to use spotify, so I rather manually select and download music.

The thing is that now I have at least 900 songs divided in multiple folders. If I want to make a new playlist I do not know anymore if I already placed a song in another playlist before. So I proceeded to:

  1. Manually added the metadata for all the songs I downloaded (not funny at all)

  2. I used another project of mine called MusicToMetaData to extract the metadata into json files. Like that evey folder became a single json file (rock, salsa, etc) and inside every json file there is the metadata of the songs in the json format.

  3. I uploaded all the files to mondoDB atlas, making for evey file a collection and every song, a document.

  4. I developed this backend software so I can check if any new song I like in the future has been already added to a collection.

About

Backend for managing a music database with MongoDB Atlas, using FastAPI.

Resources

License

Stars

Watchers

Forks

Packages

No packages published