fix #3 #4
|
@ -17,6 +17,7 @@ spec = APISpec(
|
|||
# Define schemas
|
||||
class FingerprintOuputSchema(Schema):
|
||||
response = fields.String(description="A message.", required=True)
|
||||
fingerPrint = fields.String(description="FingerPrint", required=True)
|
||||
|
||||
class FingerprintInputSchema(Schema):
|
||||
cid = fields.String(description="IPFS cid", required=True)
|
||||
|
|
|
@ -4,6 +4,7 @@ from dejavu.logic.recognizer.file_recognizer import FileRecognizer
|
|||
import os
|
||||
import ipfshttpclient
|
||||
import tempfile
|
||||
import psycopg2
|
||||
mazash = Blueprint(name="mazash", import_name=__name__)
|
||||
|
||||
config = {
|
||||
|
@ -16,6 +17,13 @@ config = {
|
|||
"database_type": os.getenv("DATABASE_TYPE", "mysql")
|
||||
}
|
||||
|
||||
SELECT_HASH_BY_SONG_ID = """
|
||||
SELECT upper(encode(songs.file_sha1, 'hex')) AS file_sha1
|
||||
FROM songs
|
||||
WHERE songs.song_name = %s;
|
||||
"""
|
||||
|
||||
|
||||
def transform_resultToJsonable(r):
|
||||
jsonable = {
|
||||
"song_id": r["song_id"],
|
||||
|
@ -66,9 +74,18 @@ def fingerprint():
|
|||
temp_file.close()
|
||||
djv.fingerprint_directory("/tmp/", [extension])
|
||||
os.remove(link_filename)
|
||||
output = {"reponse":"success"}
|
||||
output = {"reponse":"success", "fingerPrint":""}
|
||||
dbConnection = psycopg2.connect(database=config["database"]["database"], user=config["database"]["user"], password=config["database"]["password"], host=config["database"]["host"])
|
||||
cursor = dbConnection.cursor()
|
||||
try:
|
||||
cursor.execute(SELECT_HASH_BY_SONG_ID, (song_name,))
|
||||
except psycopg2.Error as e:
|
||||
return jsonify({"error_message":e})
|
||||
row = cursor.fetchone()
|
||||
output["fingerPrint"] = row[0]
|
||||
else :
|
||||
return 400, "waiting JSON valid"
|
||||
dbConnection.close()
|
||||
return jsonify(output)
|
||||
|
||||
@mazash.route('/recognize', methods=['POST'])
|
||||
|
|
Loading…
Reference in New Issue