Exemplo n.º 1
0
 def GET(self):
     user_data = web.input()
     songId = user_data.id
     uri = py7D.preview_url(songId)
     response = requests.get(uri)
     if response.status_code == 200:
         return uri
     else:
         return 'static/notfound.mp3'
Exemplo n.º 2
0
def track_previews():

    response = py7D.request('track', 'search', q='Aja', pageSize=3)
    tracks = response['response']['searchResults']['searchResult']
    

    for track in tracks:
        print track
        track['preview'] = py7D.preview_url(track['track']['@id'])
    
    return tracks
Exemplo n.º 3
0
def searchTrack(request):
    query = request.GET['query']
    query = query.replace(' ','%20')
    track_id,artist_name,title = trackQueryHelper(query)
    if track_id == "":
        return HttpResponse(0)
    else:
        preview_url = py7D.preview_url(track_id)
        getTrackTags(artist_name, title, track_id)
        isLove = checkIfLove(request.user,track_id)
        if isLove is True:
            love_flag = '1'
        else:
            love_flag = '0'
        return HttpResponse(preview_url + SPLIT_BAR + artist_name + SPLIT_BAR + title + SPLIT_BAR + track_id + SPLIT_BAR + SPLIT_BAR + love_flag)
Exemplo n.º 4
0
def getTrack(request):
    lastfm_title,lastfm_artist = getHotTracks()
    query = lastfm_title + ' ' + lastfm_artist
    query = query.replace(' ','%20')
    track_id,artist_name,title = trackQueryHelper(query)
    if track_id == "":
        return HttpResponse(0)
    else:
        preview_url = py7D.preview_url(track_id)
        getTrackTags(artist_name, title, track_id)
        isLove = checkIfLove(request.user,track_id)
        if isLove is True:
            love_flag = '1'
        else:
            love_flag = '0'
        return HttpResponse(preview_url + SPLIT_BAR + artist_name + SPLIT_BAR + title + SPLIT_BAR + track_id + SPLIT_BAR + SPLIT_BAR + love_flag)
Exemplo n.º 5
0
def getRecommendation(request):
    cur_title = request.GET['curTitle']
    cur_artist = request.GET['curArtist']
    last_title,last_artist = getSimilarTrack(cur_title,cur_artist)
    query = queryAppender(last_title,last_artist)
    track_id,artist_name,title = trackQueryHelper(query)
    if track_id == "":
        return HttpResponse(0)
    else:
        preview_url = py7D.preview_url(track_id)
        getTrackTags(artist_name, title, track_id)
        isLove = checkIfLove(request.user,track_id)
        if isLove is True:
            love_flag = '1'
        else:
            love_flag = '0'
        return HttpResponse(preview_url + SPLIT_BAR + artist_name + SPLIT_BAR + title + SPLIT_BAR + track_id + SPLIT_BAR + SPLIT_BAR + love_flag)
    return HttpRespons(preview_url)
Exemplo n.º 6
0
no_audio = []
no_jam = []
conn = sqlite3.connect("processed_data.db")
c = conn.cursor()

for (directory, _, files) in os.walk("."):
    for h5 in glob.glob(os.path.join(directory, "*.h5")):
        print h5
        f = tables.open_file(h5, mode="r")
        track_id = f.root.analysis.songs.cols.track_id[0]
        audio_name = track_id + ".mp3"
        audio_path = os.path.abspath(os.path.join(directory, audio_name))
        seven_id = f.root.metadata.songs.cols.track_7digitalid[0]
        # create db entry and get audiofile
        if not (os.path.exists(audio_path) and seven_id != -1):
            audio_url = py7D.preview_url(seven_id)
            r = requests.get(audio_url, headers={"Connection": "close"})
            if r.ok:
                # write audio file
                with open(audio_path, "wb") as handle:
                    for block in r.iter_content(8 * 1024):
                        handle.write(block)
                # create db_entry
                query = "INSERT INTO tracks (msd_id, track_7digitalid, jam_id, audio_path, h5_path) VALUES ('%s',%d,'%s','%s','%s')"
                if jam_ids.has_key(track_id):
                    query = query % (track_id, seven_id, jam_ids[track_id], audio_path, os.path.abspath(h5))
                else:
                    query = query % (track_id, seven_id, -1, audio_path, h5)
                    no_jam.append(track_id)
                c.execute(query)
                conn.commit()
Exemplo n.º 7
0
        insidePath = msdPath + '/' + folder
        if (os.path.isdir(insidePath)):
            for folder2 in os.listdir(insidePath):
                insidePath2 = insidePath + '/' + folder2
                if (os.path.isdir(insidePath2)):
                    for file in os.listdir(insidePath2):
                        previewFilePath = insidePath2 + '/' + os.path.splitext(
                            file)[0] + '.mp3'
                        print previewFilePath
                        if file.endswith(
                                'h5') and not os.path.isfile(previewFilePath):
                            h5FilePath = insidePath2 + '/' + file
                            # print 'Processing ' + h5FilePath

                            try:
                                h5 = hdf5_getters.open_h5_file_read(h5FilePath)
                                id7Digital = hdf5_getters.get_track_7digitalid(
                                    h5)
                                h5.close()

                                url = py7D.preview_url(id7Digital)
                                urlretrieve = urllib.urlretrieve(
                                    url, previewFilePath)
                            except Exception as e:
                                print "Error accured: " + str(e)

                        if file.endswith('h5'):
                            # update_progress(int(i/7620 * 100))
                            sys.stdout.write("\r%d%%" % int(i / 7620 * 100))
                            sys.stdout.flush()
                            i += 1
    msdPath = sys.argv[1]
    i = 0.0
    for folder in os.listdir(msdPath):
        insidePath = msdPath+'/'+folder
        if (os.path.isdir(insidePath)):
            for folder2 in os.listdir(insidePath):
                insidePath2 = insidePath + '/' + folder2
                if (os.path.isdir(insidePath2)):
                    for file in os.listdir(insidePath2):
                        previewFilePath = insidePath2 + '/' + os.path.splitext(file)[0] + '.mp3'
                        print previewFilePath
                        if file.endswith('h5') and not os.path.isfile(previewFilePath):
                            h5FilePath = insidePath2+'/'+file
                            # print 'Processing ' + h5FilePath

                            try:
                                h5 = hdf5_getters.open_h5_file_read(h5FilePath)
                                id7Digital = hdf5_getters.get_track_7digitalid(h5)
                                h5.close()

                                url = py7D.preview_url(id7Digital)
                                urlretrieve = urllib.urlretrieve(url, previewFilePath)
                            except Exception:
                                print "Error accured"

                        if file.endswith('h5'):
                            # update_progress(int(i/7620 * 100))
                            sys.stdout.write("\r%d%%" % int(i/7620 * 100))
                            sys.stdout.flush()
                            i += 1
def get_preview_from_trackid(trackid):
    return py7D.preview_url(trackid)
Exemplo n.º 10
0
def guess_song():
    count = 0
    while count < 3:
        try:
            songs = pysong.search(
                title=request.form["song"],
                buckets=["id:7digital-US", "tracks", "song_discovery"],
                limit=True,
                results=50,
                sort="song_hotttnesss-desc",
            )
            song = songs[0]
            break
        except:
            count += 1
            if count == 3:
                return render_template("index.html", cant_find=True)
        print "Timed out, try again"
    artist_x = song.artist_name
    # pp.pprint([(song.title, song.artist_name) for song in songs[:5]])
    # pp.pprint(song.get_tracks('7digital-US'))
    for_song = song.get_tracks("7digital-US")[0]
    cover_url = for_song["release_image"]
    # print cover_url
    foreign_id = for_song["foreign_id"].split(":")[-1]
    # print foreign_id
    try:
        response = py7D.request("track", "details", trackID=str(foreign_id), pageSize=3)
        rel_year = response["response"]["track"]["release"]["releaseDate"].split("-")[0]
    except:
        return render_template("index.html", cant_find=True)

    listen = py7D.preview_url(foreign_id)
    print
    print listen
    print
    # pp.pprint(response['response']['track'])
    a_sum = song.audio_summary
    duration = a_sum["duration"]
    features, viz_dict = get_features(song)
    if not features:
        return render_template("index.html", cant_find=True)
    year = model.predict(features)
    year = str(int(year[0]))
    print year, rel_year
    return render_template(
        "index.html",
        song_name=songs[0].title,
        predicted_year=year,
        artist=artist_x,
        actual_year=rel_year,
        img_url=cover_url,
        dancy=viz_dict["dancy"],
        energy=viz_dict["energy"],
        loudness=viz_dict["loudness"],
        tempo=viz_dict["tempo"],
        tempo_rate=viz_dict["tempo_rate"],
        key=viz_dict["key"],
        a_hot=viz_dict["artist_hottness"],
        s_hot=viz_dict["song_hotttnesss"],
        a_fam=viz_dict["artist_familiarity"],
        song_currency=viz_dict["song_currency"],
        valence=viz_dict["valence"],
        speech=viz_dict["speech"],
        acousticness=viz_dict["acousticness"],
        liveness=viz_dict["liveness"],
        song_disc=viz_dict["song_discovery"],
        mp3=listen,
    )
Exemplo n.º 11
0
no_audio = []
no_jam = []
conn = sqlite3.connect("processed_data.db")
c = conn.cursor()

for (directory, _, files) in os.walk('.'):
    for h5 in glob.glob(os.path.join(directory, "*.h5")):
        print h5
        f = tables.open_file(h5, mode='r')
        track_id = f.root.analysis.songs.cols.track_id[0]
        audio_name = track_id + ".mp3"
        audio_path = os.path.abspath(os.path.join(directory, audio_name))
        seven_id = f.root.metadata.songs.cols.track_7digitalid[0]
        #create db entry and get audiofile
        if not (os.path.exists(audio_path) and seven_id != -1):
            audio_url = py7D.preview_url(seven_id)
            r = requests.get(audio_url, headers={'Connection': 'close'})
            if r.ok:
                #write audio file
                with open(audio_path, 'wb') as handle:
                    for block in r.iter_content(8 * 1024):
                        handle.write(block)
                #create db_entry
                query = "INSERT INTO tracks (msd_id, track_7digitalid, jam_id, audio_path, h5_path) VALUES ('%s',%d,'%s','%s','%s')"
                if jam_ids.has_key(track_id):
                    query = query % (track_id, seven_id, jam_ids[track_id],
                                     audio_path, os.path.abspath(h5))
                else:
                    query = query % (track_id, seven_id, -1, audio_path, h5)
                    no_jam.append(track_id)
                c.execute(query)
Exemplo n.º 12
0
def guess_song():
    count = 0
    while count < 3:
        try:
            songs = pysong.search(
                title=request.form['song'],
                buckets=['id:7digital-US', 'tracks', 'song_discovery'],
                limit=True,
                results=50,
                sort="song_hotttnesss-desc")
            song = songs[0]
            break
        except:
            count += 1
            if count == 3:
                return render_template('index.html', cant_find=True)
        print "Timed out, try again"
    artist_x = song.artist_name
    # pp.pprint([(song.title, song.artist_name) for song in songs[:5]])
    # pp.pprint(song.get_tracks('7digital-US'))
    for_song = song.get_tracks('7digital-US')[0]
    cover_url = for_song['release_image']
    # print cover_url
    foreign_id = for_song['foreign_id'].split(":")[-1]
    # print foreign_id
    try:
        response = py7D.request('track',
                                'details',
                                trackID=str(foreign_id),
                                pageSize=3)
        rel_year = response['response']['track']['release'][
            'releaseDate'].split("-")[0]
    except:
        return render_template('index.html', cant_find=True)

    listen = py7D.preview_url(foreign_id)
    print
    print listen
    print
    # pp.pprint(response['response']['track'])
    a_sum = song.audio_summary
    duration = a_sum['duration']
    features, viz_dict = get_features(song)
    if not features:
        return render_template('index.html', cant_find=True)
    year = model.predict(features)
    year = str(int(year[0]))
    print year, rel_year
    return render_template('index.html',
                           song_name=songs[0].title,
                           predicted_year=year,
                           artist=artist_x,
                           actual_year=rel_year,
                           img_url=cover_url,
                           dancy=viz_dict['dancy'],
                           energy=viz_dict['energy'],
                           loudness=viz_dict['loudness'],
                           tempo=viz_dict['tempo'],
                           tempo_rate=viz_dict['tempo_rate'],
                           key=viz_dict['key'],
                           a_hot=viz_dict["artist_hottness"],
                           s_hot=viz_dict["song_hotttnesss"],
                           a_fam=viz_dict["artist_familiarity"],
                           song_currency=viz_dict["song_currency"],
                           valence=viz_dict["valence"],
                           speech=viz_dict["speech"],
                           acousticness=viz_dict["acousticness"],
                           liveness=viz_dict["liveness"],
                           song_disc=viz_dict["song_discovery"],
                           mp3=listen)
Exemplo n.º 13
0
def get_preview_from_trackid(trackid):
    return py7D.preview_url(trackid)