2011.04.27 include_once('../include/subject_includes.php'); include_once('../include/ensemble_echonest_api.php'); $_SESSION['submit_stimulus_id'] = TRUE; // get info from experiment_x_form and form tables include_once('query_form_info.php'); // set params to construct this playlist $_SESSION['stim_root'] = 'https://atonal.ucdavis.edu/ensemble/stimuli/'; $_SESSION['en_params'] = array(); $_SESSION['en_params']['api_key'] = 'QVKVLGQZD44CKT8CX'; $_SESSION['en_params']['preferred'] = TRUE; $_SESSION['en_params']['playlist_type'] = 'static'; $_SESSION['en_params']['playlist_params'] = array(); $_SESSION['en_params']['playlist_params']['api_key'] = $_SESSION['en_params']['api_key']; $_SESSION['en_params']['playlist_params']['format'] = 'json'; $_SESSION['en_params']['playlist_params']['type'] = 'artist-description'; $_SESSION['en_params']['playlist_params']['limit'] = 'true'; $_SESSION['en_params']['playlist_params']['bucket']['id']='CAOHBSP12F74BFBF10'; $_SESSION['en_params']['playlist_params']['bucket']['tracks'] = ''; $_SESSION['en_params']['playlist_params']['variety'] = 1; $_SESSION['en_params']['playlist_params']['results'] = 100; $_SESSION['en_params']['playlist_params']['description'] = array(); $_SESSION['en_params']['playlist_params']['description']['style'] = get_stomp_genres($_SESSION['en_params']['preferred']); // debugging $outpath = '/home/fbarrett/data/logs/echonest_ensemble/js_muschoose_ENplaylist_ajax.php'; $oh = fopen($outpath,'a+'); fwrite($oh,"\n----------------------\nDate:" . date('MdYHis') . "\n"); // if no en_playlist is set, retrieve one! if (!isset($_SESSION['en_playlist'])) { fwrite($oh,"\ngetting EN playlist, type {$_SESSION['en_params']['playlist_type']}\n"); // get an EchoNest playlist $pltype = $_SESSION['en_params']['playlist_type']; $_SESSION['en_playlist'] = get_echonest_data('playlist/'.$pltype,$_SESSION['en_params']['playlist_params']); fwrite($oh,"GOT IT\n"); } // if no songs are left, return an error if (!count($_SESSION['en_playlist'])) { fwrite($oh,"no songs in playlist??\n"); error("js_muschoose_ENplaylist_ajax:en_playlist:error"); } // get the next stimid $ENstim = array_pop($_SESSION['en_playlist']->{'songs'}); $ENid = $ENstim->{'foreign_ids'}[0]->{'foreign_id'}; preg_match('/.*:(\d*)/',$ENid,$matches); // if we couldn't find the stimid, return an error if (!count($matches)) { error("js_muschoose_ENplaylist_ajax:matches:error"); } // get the location of the next stim $sql = "SELECT location FROM stimulus WHERE stimulus_id=" . $matches[1]; $results = mysql_query($sql); $nrows = mysql_num_rows($results); // if we couldn't find the stim in the database, return an error if (!$nrows) { error("js_muschoose_ENplaylist_ajax:mysql error:".mysql_error()); } // return the data in json format $sresult = mysql_fetch_assoc($results); $qua = '{"url":"' . $_SESSION['stim_root'] . $sresult['location'] . '","stimid","' . $matches[1] . '"}'; $arr = array('url' => $_SESSION['stim_root'] . $sresult['location'],'stimid'=>$matches[1]); fwrite($oh,"json: " . json_encode($arr) . "\n"); fwrite($oh,"qua: $qua\n"); fclose($oh); //echo json_encode($arr); echo $qua; ?>