Exemple #1
0
def parse_json(c):
        code = c["code"]
        m = c["metadata"]
        if "track_id" in m:
            trid = m["track_id"].encode("utf-8")
        else:
            trid = fp.new_track_id()
        length = m["duration"]
        version = m["version"]
        artist = m.get("artist", None)
        title = m.get("title", None)
        release = m.get("release", None)
        decoded = fp.decode_code_string(code)

        data = {"track_id": trid,
            "fp": decoded,
            "length": length,
            "codever": "%.2f" % version
        }

        if artist: data["artist"] = artist
        if release: data["release"] = release
        if title: data["track"] = title

    	return data
Exemple #2
0
    def POST(self):
        params = web.input(
            track_id="default", fp_code="", artist=None, release=None, track=None, length=None, codever=None
        )
        if params.track_id == "default":
            track_id = fp.new_track_id()
        else:
            track_id = params.track_id
        if params.length is None or params.codever is None:
            return web.webapi.BadRequest()

        # First see if this is a compressed code
        if re.match("[A-Za-z\/\+\_\-]", params.fp_code) is not None:
            code_string = fp.decode_code_string(params.fp_code)
            if code_string is None:
                return json.dumps(
                    {"track_id": track_id, "ok": False, "error": "cannot decode code string %s" % params.fp_code}
                )
        else:
            code_string = params.fp_code

        data = {"track_id": track_id, "fp": code_string, "length": params.length, "codever": params.codever}
        if params.artist:
            data["artist"] = params.artist
        if params.release:
            data["release"] = params.release
        if params.track:
            data["track"] = params.track
        fp.ingest(data, do_commit=True, local=False)

        return json.dumps({"track_id": track_id, "status": "ok"})
Exemple #3
0
def parse_json(c):
    code = c["code"]
    m = c["metadata"]
    if "track_id" in m:
        trid = m["track_id"].encode("utf-8")
    else:
        trid = fp.new_track_id()
    length = m["duration"]
    version = m["version"]
    artist = m.get("artist", None)
    title = m.get("title", None)
    release = m.get("release", None)
    decoded = fp.decode_code_string(code)

    data = {
        "track_id": trid,
        "fp": decoded,
        "length": length,
        "codever": "%.2f" % version
    }

    if artist: data["artist"] = artist
    if release: data["release"] = release
    if title: data["track"] = title

    return data
Exemple #4
0
def parse_json_dump(jfile):
    codes = json.load(open(jfile))

    bigeval = {}
    fullcodes = []
    for c in codes:
    	try: 
	        if "code" not in c:
	            continue
	        code = c["code"]
	        m = c["metadata"]
	        if "track_id" in m:
	            trid = m["track_id"].encode("utf-8")
	        else:
	            trid = fp.new_track_id()
	        length = m["duration"]
	        version = m["version"]
	        artist = m.get("artist", None)
	        title = m.get("title", None)
	        release = m.get("release", None)
	        decoded = fp.decode_code_string(code)
	        
	        bigeval[trid] = m
	        
	        data = {"track_id": trid,
	            "fp": decoded,
	            "length": length,
	            "codever": "%.2f" % version
	        }
	        if artist: data["artist"] = artist
	        if release: data["release"] = release
	        if title: data["track"] = title
	        fullcodes.append(data)
	    except Exception, e:
	    	print 'Exception:', e    
Exemple #5
0
def ingest(params, mp3):
    fp_code = generate_fingerprint(mp3)
    if fp_code is dict:
        return False
    if params.get('track_id', "default") == "default":
        track_id = fp.new_track_id()
    else:
        track_id = params['track_id']
    if not params.get('length', None):
        return False

    # First see if this is a compressed code
    if re.match('[A-Za-z\/\+\_\-]', fp_code) is not None:
        code_string = fp.decode_code_string(fp_code)
        if code_string is None:
            result = json.dumps({"track_id": track_id, "ok": False,
                                 "error": "cannot decode code string %s" % fp_code})
            return False, result
    else:
        code_string = fp_code

    data = {"track_id": track_id,
            "fp": code_string,
            "length": params['length'],
            "codever": params['codever']}
    if params.get('artist'):
        data["artist"] = params.get('artist')
    if params.get('release'):
        data["release"] = params.get('release')
    if params.get('track'):
        data["track"] = params.get('track')
    fp.ingest(data, do_commit=True, local=False)
Exemple #6
0
def parse_json_dump(jfile):
    codes = json.load(open(jfile))

    bigeval = {}
    fullcodes = []
    for c in codes:
        if "code" not in c:
            continue
        code = c["code"]
        m = c["metadata"]
        if "track_id" in m:
            trid = m["track_id"].encode("utf-8")
        else:
            trid = fp.new_track_id()
        length = m["duration"]
        version = m["version"]
        artist = m.get("artist", None)
        title = m.get("title", None)
        release = m.get("release", None)
        decoded = fp.decode_code_string(code)

        bigeval[trid] = m

        data = {
            "track_id": trid,
            "fp": decoded,
            "length": length,
            "codever": "%.2f" % version
        }
        if artist: data["artist"] = artist
        if release: data["release"] = release
        if title: data["track"] = title
        fullcodes.append(data)

    return (fullcodes, bigeval)
Exemple #7
0
    def POST(self):
        params = web.input(track_id="default",
                           fp_code="",
                           artist=None,
                           release=None,
                           track=None,
                           length=None,
                           codever=None,
                           source=None,
                           genre=None,
                           bitrate=None,
                           sample_rate=None)
        print params
        if params.track_id == "default":
            track_id = fp.new_track_id()
        else:
            track_id = params.track_id
        if params.length is None or params.codever is None:
            return web.webapi.BadRequest()

        # First see if this is a compressed code
        if re.match('[A-Za-z\/\+\_\-]', params.fp_code) is not None:
            code_string = fp.decode_code_string(params.fp_code)
            if code_string is None:
                return json.dumps({
                    "track_id":
                    track_id,
                    "ok":
                    False,
                    "error":
                    "cannot decode code string %s" % params.fp_code
                })
        else:
            code_string = params.fp_code

        data = {
            "track_id": track_id,
            "fp": code_string,
            "length": params.length,
            "codever": params.codever
        }
        if params.artist: data["artist"] = params.artist
        if params.release: data["release"] = params.release
        if params.track: data["track"] = params.track
        if params.source: data["source"] = params.source
        if params.genre: data["genre"] = params.genre
        if params.bitrate: data["bitrate"] = params.bitrate
        if params.sample_rate: data["sample_rate"] = params.sample_rate

        fp.ingest(data, do_commit=True, local=False)

        return json.dumps({"track_id": track_id, "status": "ok"})
Exemple #8
0
def ingest(request):
    # TODO: Add Track object
    params = request.POST
    mp3 = request.FILES['mp3']
    fp_code = generate_fingerprint(mp3)
    if fp_code is dict:
        return HttpResponse(fp_code['error'], status=400)
    if params.get('track_id', "default") == "default":
        track_id = fp.new_track_id()
    else:
        track_id = params['track_id']
    if not params.get('length', None):
        return HttpResponse("Invalid data", status=400)

    # First see if this is a compressed code
    if re.match('[A-Za-z\/\+\_\-]', fp_code) is not None:
        code_string = fp.decode_code_string(fp_code)
        if code_string is None:
            result = json.dumps( {"track_id": track_id, "ok": False,
                                  "error": "cannot decode code string %s" % fp_code})
            return HttpResponse(result, status=400)
    else:
        code_string = fp_code

    artist = params.get('artist')
    release = params.get('release')
    title = params.get('track')
    year = params.get('year')
    youtube_code = params.get('youtube_code')
    # Track creation
    track = Track(band=artist, release=release,
                  name=title,
                  year=year,
                  youtube_code=youtube_code)
    track.save()
    # Remove all - (due to limitation in fingerprint-server track_id match)
    track_id = track.echoprint_id
    data = {"track_id": track_id,
            "fp": code_string,
            "length": params['length'],
            "codever": params['codever']}
    if params.get('artist'):
        data["artist"] = params.get('artist')
    if params.get('release'):
        data["release"] = params.get('release')
    if params.get('track'):
        data["track"] = params.get('track')
    fp.ingest(data, do_commit=True, local=False)

    data = json.dumps({"track_id": track_id, "fp": fp_code,"status": "ok"})
    return HttpResponse(data, status=200)
Exemple #9
0
    def POST(self):
        params = web.input(track_id="default", fp_code="", artist=None, release=None, track=None, length=None, codever=None)
        if params.track_id == "default":
            track_id = fp.new_track_id()
        else:
            track_id = params.track_id
        if params.length is None or params.codever is None:
            return web.webapi.BadRequest()
        
        # First see if this is a compressed code
        if re.match('[A-Za-z\/\+\_\-]', params.fp_code) is not None:
           code_string = fp.decode_code_string(params.fp_code)
#           if code_string is None:
               return json.dumps({"track_id":track_id, "ok":False, "error":"cannot decode code string %s" % params.fp_code})
Exemple #10
0
def local_ingest_json(json):
    fp_codes = []
    #fp.local_load("disk.pkl")

    if len(json):
	track_id = fp.new_track_id()
	code_str = fp.decode_code_string(json[0]["code"])
        meta = json[0]["metadata"]
        l = meta["duration"] * 1000
        a = meta["artist"]
        r = meta["release"]
        t = meta["title"]
        v = meta["version"]
        fp_codes.append({"track_id": track_id, "fp": code_str, "length": str(l), "codever": str(round(v, 2)), "artist": a, "release": r, "track": t})
    fp.ingest(fp_codes, local=True)
    
    #fp.local_save("disk.pkl")
    return track_id
Exemple #11
0
    def parse_json_dump(self, json_data):
        codes = json_data

        bigeval = {}
        fullcodes = []
	track_ids = []
        for c in codes:
            if "code" not in c:
                continue
            code = c["code"]
            m = c["metadata"]
            if "track_id" in m:
                trid = m["track_id"].encode("utf-8")
            else:
                trid = fp.new_track_id()
	    track_ids.append(trid)
            length = m["duration"]
            version = m["version"]
            artist = m.get("artist", None)
            title = m.get("title", None)
            release = m.get("release", None)
            youtube = m.get("youtube", None)
            characters = m.get("characters", None)
            decoded = fp.decode_code_string(code)
        
            bigeval[trid] = m
        
            data = {"track_id": trid,
                "fp": decoded,
                "length": length,
                "codever": "%.2f" % version
            }
            if artist: data["artist"] = artist
            if release: data["release"] = release
            if title: data["track"] = title
            if youtube: data["youtube"] = youtube
            if characters: data["characters"] = characters
            fullcodes.append(data)

        return (fullcodes, bigeval, track_ids)
Exemple #12
0
def parse_json_block(json_block):
    codes = json.loads(json_block)
    code = codes[0]

    if not 'code' in code:
        return None

    raw_code = code["code"]

    m = code["metadata"]
    if "track_id" in m:
        trid = m["track_id"].encode("utf-8")
    else:
        trid = fp.new_track_id()

    length = m["duration"]
    version = m["version"]
    artist = m.get("artist", None)
    title = m.get("title", None)
    release = m.get("release", None)
    decoded = fp.decode_code_string(raw_code)
    
    ingest_data = {
        "track_id": trid,
        "fp": decoded,
        "length": length,
        "codever": "%.2f" % version
    }
    if artist: 
        ingest_data["artist"] = artist
    if release: 
        ingest_data["release"] = release
    if title: 
        ingest_data["track"] = title

    return trid, raw_code, ingest_data
Exemple #13
0
def parse_json_block(json_block):
    codes = json.loads(json_block)
    code = codes[0]

    if not 'code' in code:
        return None

    raw_code = code["code"]

    m = code["metadata"]
    if "track_id" in m:
        trid = m["track_id"].encode("utf-8")
    else:
        trid = fp.new_track_id()

    length = m["duration"]
    version = m["version"]
    artist = m.get("artist", None)
    title = m.get("title", None)
    release = m.get("release", None)
    decoded = fp.decode_code_string(raw_code)

    ingest_data = {
        "track_id": trid,
        "fp": decoded,
        "length": length,
        "codever": "%.2f" % version
    }
    if artist:
        ingest_data["artist"] = artist
    if release:
        ingest_data["release"] = release
    if title:
        ingest_data["track"] = title

    return trid, raw_code, ingest_data