update_tunein.php:#!/bin/bashexport LANG=ru_RU.UTF-8log=/var/log/icecast/playlist.log ## Playlist logscript=/home/modi/tuneinapi/update_tunein.php ## PHP script for call TuneIn APILASTFILE=""## Browse the log file of playlist.logtail -Fn0 $log | \while read line ; do## Get the last line of the file and encode itINFOCOMPLETE=$(echo $line | sed -e 's/ /_/g' -e 's/|/ /g' | awk '{print $4}' | sed -e 's/_/ /g'|base64)NEWFILE=$INFOCOMPLETE## If the last line is different from the penultimate call a PHP scriptif [ "$NEWFILE" != "$LASTFILE" ]thenphp $script $INFOCOMPLETELASTFILE=$NEWFILEfidone
<?phpheader('Content-Type: text/html; charset=utf-8');// Collect information from BASH script$args = $_SERVER['argv'];// Decode the parameter passed to the script$arguments = $args[1];if (isset($args[2])) $arguments = $args[1].$args[2]; // Sometimes, encoding base 64 does not generate second argument$infos = base64_decode($arguments);//$infos = convert_ascii($infos); // optional$meta = substr(utf8_encode($infos), 0); // Data from playlist file are encoded in iso8859 (why ??)$meta2 = str_replace( '&', '%26', $meta);preg_match('/(.*)[ ] ?- [ ]?(.*)/', $meta2, $infos_artist); // Extract artist and title$partnerId = "XXXXX";$partnerKey = "XXXXXX";$stationId = "sXXXXX";$artist_tunein = str_replace(' ','+', $infos_artist[1]);$title_tunein = str_replace(' ','+', $infos_artist[2]);$commercial = false;// You can detect commercial, here is my approach with a specific artist name//if ($infos_artist[2] == "XXXPublicityXXX") $commercial = true;$url_tunein = "http://air.radiotime.com/Playing.ashx?partnerId=".$partnerId."&partnerKey=".$partnerKey."&id=".$stationId."&title=".$title_tunein."&artist=".$artist_tunein."&commercial=".$commercial;$ch = curl_init();curl_setopt($ch, CURLOPT_URL,$url_tunein);curl_setopt($ch, CURLOPT_TIMEOUT, 10);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);$data = curl_exec($ch);$server_output = simplexml_load_string($data);curl_close($ch);// Here a example for get the status code and error message in a log fileif ($server_output->head->status != '200') $message = $server_output->head->status." : ".$server_output->head->fault." - ".$url_tunein;else $message = $server_output->head->status." - ".$url_tunein;$log = fopen("tuneinlog.txt", "a");fputs($log, 'result: "'.$message.'"'.PHP_EOL);fclose ($log);?>
It looks like you're new here. If you want to get involved, click one of these buttons!