fix #3 #4
|
@ -17,6 +17,7 @@ spec = APISpec(
|
||||||
# Define schemas
|
# Define schemas
|
||||||
class FingerprintOuputSchema(Schema):
|
class FingerprintOuputSchema(Schema):
|
||||||
response = fields.String(description="A message.", required=True)
|
response = fields.String(description="A message.", required=True)
|
||||||
|
fingerPrint = fields.String(description="FingerPrint", required=True)
|
||||||
|
|
||||||
class FingerprintInputSchema(Schema):
|
class FingerprintInputSchema(Schema):
|
||||||
cid = fields.String(description="IPFS cid", required=True)
|
cid = fields.String(description="IPFS cid", required=True)
|
||||||
|
|
|
@ -4,6 +4,7 @@ from dejavu.logic.recognizer.file_recognizer import FileRecognizer
|
||||||
import os
|
import os
|
||||||
import ipfshttpclient
|
import ipfshttpclient
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import psycopg2
|
||||||
mazash = Blueprint(name="mazash", import_name=__name__)
|
mazash = Blueprint(name="mazash", import_name=__name__)
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
|
@ -16,6 +17,13 @@ config = {
|
||||||
"database_type": os.getenv("DATABASE_TYPE", "mysql")
|
"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):
|
def transform_resultToJsonable(r):
|
||||||
jsonable = {
|
jsonable = {
|
||||||
"song_id": r["song_id"],
|
"song_id": r["song_id"],
|
||||||
|
@ -66,9 +74,18 @@ def fingerprint():
|
||||||
temp_file.close()
|
temp_file.close()
|
||||||
djv.fingerprint_directory("/tmp/", [extension])
|
djv.fingerprint_directory("/tmp/", [extension])
|
||||||
os.remove(link_filename)
|
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 :
|
else :
|
||||||
return 400, "waiting JSON valid"
|
return 400, "waiting JSON valid"
|
||||||
|
dbConnection.close()
|
||||||
return jsonify(output)
|
return jsonify(output)
|
||||||
|
|
||||||
@mazash.route('/recognize', methods=['POST'])
|
@mazash.route('/recognize', methods=['POST'])
|
||||||
|
|
Loading…
Reference in New Issue