示例#1
0
def setCurrentCalcNext( context = dict() ):
    global p
    global g_p
    global g_7digital_cur
    global g_7digital_nexts
    global g_song_features

    g_7digital_nexts      = MX_traverse.pickNextSongsWrapped( g_7digital_cur );
    g_song_features       = MX_traverse.get_song_by_7digital( g_7digital_cur )
    g_nexts_features      = [MX_traverse.get_song_by_7digital( x ) for x in g_7digital_nexts[0]]
    song_url              = MX_traverse.get_song_url( g_7digital_cur )
    if g_p['save_playlist']:
        g_p['playlist_file'] = g_p['playlist_pref'] + time.strftime("%Y%m%d-%H%M%S") + '.csv'
        MX_traverse.addSongToPlaylist( g_p['playlist_file'], g_song_features, song_url )
    
    context['song_url']    = song_url+'#t='+str(g_p['play_interval'][0])+","+str(g_p['play_interval'][1])
    context['id_7digital'] = g_7digital_cur
    context['title']       = g_song_features[p['invkey']['title']]
    context['artist']      = g_song_features[p['invkey']['artist_name']]

    for i in range(len(g_nexts_features)):
        context['n'+str(i)+'_id_7digital'] = g_nexts_features[i][p['invkey']['track_7digitalid']]
        context['n'+str(i)+'_title']       = g_nexts_features[i][p['invkey']['title']]
        context['n'+str(i)+'_artist']      = g_nexts_features[i][p['invkey']['artist_name']]

    return context
示例#2
0
def bandura_lucky():
    global g_7digital_cur
    global g_7digital_nexts
    global g_song_features
    global g_nexts_features

    print "bandura_lucky"

    context = packContext( 0 );

    if 1: #request.method == "POST":
        #if request.method == "POST":
        #    updateParamsFromSite( request.form )

        random_match = MX_traverse.pickRandomSong()

        g_next_choice = 0
        g_7digital_nexts = [[random_match]]
        g_nexts_features = list()
        print g_7digital_nexts[0][g_next_choice]
        g_nexts_features.append( tuple(MX_traverse.get_song_by_7digital( g_7digital_nexts[0][g_next_choice] )) )
        print "random choice: " + g_nexts_features[g_next_choice][0]

    render_template("bandura.html", **context);
    return redirect("/bandura")
示例#3
0
def bandura_search():
    global g_7digital_cur
    global g_7digital_nexts
    global g_song_features
    global g_nexts_features

    print "bandura_search"

    if request.method == "POST":
        print "'bandura search' called by POST"

        #updateParamsFromSite( request.form )

        context = packContext( 0 );

        search_term = request.form["search_term"]
        if search_term != '':

            # seach the exact term in the DB
            best_match = [MX_traverse.get_song_id_by_token(search_term)]

            if best_match[0]=='':
                # if the exact term wasn't found in the DB, perform a more flexible search using the EchoNest API
                g_7digital_cur = ''
                n_search_results = 2
                while best_match[0]=='' and n_search_results<=1000:
                    n_search_results *= 5              
                    z = py7D.request('track', 'search', q=search_term, pagesize=n_search_results)
                    if int(z['response']['searchResults']['totalItems'])>0:
                        search_results = z['response']['searchResults']['searchResult']
                        search_results2 = list()
                        print "possible matches: " + str(len(search_results))
                        for result in search_results:
                            record=dict()
                            record['track_7digitalid']  = result['track']['@id']
                            record['title']             = result['track']['title']
                            record['artist']            = result['track']['artist']['name']
                            print record['track_7digitalid'], record['title'], record['artist']
                            search_results2.append(record)
                        # intersect the EchoNest results with our DB    
                        best_match = MX_traverse.findInSongsDB( [x['track_7digitalid'] for x in search_results2] )

            if best_match[0]!='':
                g_next_choice = 0
                g_7digital_nexts = [[best_match[0]]]
                g_nexts_features = list()
                g_nexts_features.append( tuple(MX_traverse.get_song_by_7digital( g_7digital_nexts[0][g_next_choice] )) )
                print "best match: " + g_nexts_features[g_next_choice][0]
            else:
                print "no match..."
        else:
            print "No search term..."
    else:
        context = dict()
        "'bandura_search' called by GET"
    render_template("bandura.html", **context);
    return redirect("/bandura")
示例#4
0
def bandura():
    global p
    global g_p
    global g_7digital_cur
    global g_7digital_nexts  
    global g_song_features
    global g_nexts_features
    global g_next_choice

    print "bandura"
    context = packContext( 0 );

    if 1: #request.method == "POST":
        if request.method == "POST":
            print "'bandura' called by POST"
            updateParamsFromSite( request.form )

        context = packContext( 0 ); 

        if g_7digital_nexts:
            print "cur song id exists"
            print g_7digital_nexts
            g_7digital_cur   = g_7digital_nexts[0][g_next_choice]
            g_song_features  = g_nexts_features[g_next_choice]
            song_url         = OAuth.get_song_url(g_7digital_cur);
            g_7digital_nexts = MX_traverse.pickNextSongsWrapped( g_7digital_cur );
            g_nexts_features = [MX_traverse.get_song_by_7digital( x ) for x in g_7digital_nexts[0]]
            if g_p['save_playlist']:
                MX_traverse.addSongToPlaylist( g_p['playlist_file'], g_song_features, song_url )

            context['song_url']     = song_url+"#t="+str(g_p['play_interval'][0])+","+str(g_p['play_interval'][1])
            context['id_7digital']  = g_7digital_cur
            context['title']        = g_song_features[p['invkey']['title']]
            context['artist']       = g_song_features[p['invkey']['artist_name']]
                        
            for i in range(len(g_nexts_features)):
                context['n'+str(i)+'_id_7digital'] = g_nexts_features[i][p['invkey']['track_7digitalid']]
                context['n'+str(i)+'_title']       = g_nexts_features[i][p['invkey']['title']]
                context['n'+str(i)+'_artist']      = g_nexts_features[i][p['invkey']['artist_name']]
        else:
            print "cur song id does NOT exists"
    else:
        print "'bandura' called by GET"
    print "rendering bandura"
    return render_template("bandura.html", **context);