A Python Flask API for an audio metadata file server which uses a MongoDB NoSQL database backend
MIT License
Version: 1.0.0 Platform: Google Cloud Platform - Cloud Run Language: Python 3.7 and 3.8
This repository is a Flask Application that simulates an audio file server while using a MongoDB NoSQL database. The application is hosted on Google Cloud Platform as container that runs on the Cloud Run platform.
Application URL - https://audioserver-3wow3hatda-de.a.run.app please contact the repository owner if the above URL is not functional
This package contains the classes Song
, Podcast
and Audiobook
all of which derive
from the Audio
class. It also contains a couple of custom exception MetadataValueError
and MetadataGenerationError
.
The classes are all implemented as dataclasses, which was introduced in Python 3.7. This was because the classes are only storing metadata values and do not have any other function, which is exactly the intended use-case for dataclasses.
The full documentation for the package is available in the docs directory
The audio files are stored in the database in the formats discussed below.
Song
The object only requires the 'name' and 'duration' fields in the metadata dictionary.
{
"_id": <int>,
"type": "Song",
"name": <str> (100 chars),
"duration": <int> (positive),
"uploadtime": <str> (ISO8601)
}
Podcast
The object only requires the 'name', 'host' and 'duration' fields in the metadata dictionary. The 'participants' field is optional and is stored as an empty list if not provided.
{
"_id": <int>,
"type": "Podcast",
"name": <str> (100 chars),
"host": <str> (100 chars),
"participants": <list> (opt, 10 str members of 100 chars each max),
"duration": <int> (positive),
"uploadtime": <str> (ISO8601)
}
Audiobook
The object only requires the 'name', 'author', 'narrator' and 'duration' fields in the metadata.
{
"_id": <int>,
"type": "Audiobook",
"name": <str> (100 chars),
"author": <str> (100 chars),
"narrator": <str> (100 chars),
"duration": <int> (positive),
"uploadtime": <str> (ISO8601)
}
The AudioServer application has 4 API endpoints which are discussed below
This functionality is available at the /create endpoint of the application URL.
{
"audioFileType": <str>,
"audioFileMetadata": <dict>
}
audioFileType
key must be one of "Song", "Podcast" and "Audiobook". Case Insensitive.AudioFileMetadata
key must contain the appropriate fields for the specified types in the{
"status": 200,
"message": "Create Complete",
"result": f"{audioFileType} file with ID {DocumentID} has been created",
"document": {DocumentID} (int)
}
This functionality is available at the /delete endpoint of the application URL.
delete/<audioFileType>/<audioFileID>
audioFileType
key must be one of "Song", "Podcast" and "Audiobook". Case Insensitive.audioFileID
key must be an integer that corresponds to the file to delete. If no file{
"status": 200,
"message": "Delete Complete",
"result": f"No document deleted"
}
{
"status": 200,
"message": "Delete Complete",
"result": f"{audioFileType} file with ID {DocumentID} has been deleted",
"document": {DocumentID} (int)
}
This functionality is available at the /update endpoint of the application URL.
update/<audioFileType>/<audioFileID>
{
"audioFileType": <str>,
"audioFileMetadata": <dict>
}
audioFileType
key must be one of "Song", "Podcast" and "Audiobook". Case Insensitive. ItaudioFileType
provided in the URL route.AudioFileMetadata
key must contain the appropriate fields for the specified types in theaudioFileID
key must be an integer that corresponds to the file to delete. If no file{
"status": 200,
"message": "Update Complete",
"result": f"{audioFileType} file with ID {DocumentID} has been updated",
"pre-update": <dict>,
"post-update": <dict>,
"document": {DocumentID} (int)
}
This functionality is available at the /get endpoint of the application URL.
get/<audioFileType>
get/<audioFileType>/<audioFileID>
audioFileType
key must be one of "Song", "Podcast" and "Audiobook". Case Insensitive.audioFileID
key must be an integer that corresponds to the file to delete. If no fileaudioFileType
is in the route (format 1), all files of the given type will be{
"status": 200,
"message": "Get Complete",
"result": f"{ResultCount} result(s) found",
"documents": <list> (list of dict),
"matches": ResultCount (int)
}
{
"status": 400,
"message": "Bad Request",
"error": <str>
}
{
"status": 500,
"message": "Internal Server Error",
"error": <str>
}