Commit 038124eb authored by Fence's avatar Fence 🌈

add genre and playtime to Song

parent b8734348
......@@ -5,11 +5,11 @@ from flask import json_available, request, jsonify, Response
from flask_controller import FlaskController, route
from bson import ObjectId
from werkzeug.utils import secure_filename
from mutagen.mp3 import MP3
from minor.decorators import json_required, auth_required
from minor.model import Song
from minor.util import get_ext
@route("/api/music")
class MusicController(FlaskController):
def __init__(self, upload_dir):
......@@ -73,6 +73,9 @@ class MusicController(FlaskController):
artist=json["artist"],
year=json["year"]).save()
if "genre" in json:
song.genre = json["json"]
song.save()
song.reload()
return jsonify({"code": 200,
......@@ -94,6 +97,11 @@ class MusicController(FlaskController):
name = secure_filename(str(db_song.id) + "." + ext)
path = os.path.join(self._upload_dir, name)
file.save(path)
# update db entry with the length of the song
db_song.playtime = MP3(path).info.length
db_song.save()
return jsonify({"code": 200, "message": "ok"}), 200
return jsonify({"code": 400, "message": "bad_request"}), 400
......@@ -11,6 +11,8 @@ class Song(Document):
track = IntField()
album = StringField()
album_artist = StringField()
genre = StringField()
playtime = IntField()
class MajorInstance(Document):
......
flask
jwt
flask_mongoengine
git+https://github.com/AlexFence/FlaskController.git
\ No newline at end of file
git+https://github.com/AlexFence/FlaskController.git
mutagen
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment