PHP:Icecastで再生中のスクリプトが機能しない

ジョーイカンゴ

https://code.google.com/p/icecast-now-playing-script/からIcecastNow PlayingPHPスクリプトを使用しようとしています

config.phpを変更した後、すべてのファイルをWebサーバーにアップロードしました。ブラウザーにexample.phpをロードすると、次の情報が返されます。

Array (
    [info] => Array
        (
            [status] => OFF AIR
        )

)

問題の原因がわかりません。Icecastサーバーの情報が正しいことを確認しました。オープニング:http://70.35.120.203:8000/zedg_mb.mp3.m3uストリームの再生を開始します。コードは次のとおりです。

Example.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head profile="http://gmpg.org/xfn/11">
<title>Icecast Now Playing Script</title>
</head>
<body>
<p>
Code by Jude (<a href="mailto:[email protected]">[email protected]</a>)
</p>

<pre>
<?php
include('icecast.php');
print_r($stream);
?>
</pre>

</body>
</html>

Config.php

<?php

//error_reporting(0);
define(SERVER, 'http://70.35.120.203:8000');//your icecast server address, without the ending "/"
define(MOUNT, '/zedg_mb.mp3.m3u'); //your radio's mount point, with the leading "/"
define(LAST_FM_API, 'xxxxxxxxxxxxxxxxxxxxxxx'); //your last.fm API key, get from http://www.last.fm/api/account
define(DEFAULT_ALBUM_ART, 'http://www.channelztheedge.com/_images/others/othersZEDG-150sqd.png');//the default album art image, will be used if failed to get from last.fm's API
define(GET_TRACK_INFO, true); //get information of the current song from last.fm
define(GET_ALBUM_INFO, true); //get extra information of the album from last.fm, if enabled, may increase script execute time
define(GET_ARTIST_INFO, true); //get extra information of the artist from last.fm, if enabled, may increase script execute time
define(GET_TRACK_BUY_LINK, false); //get buy links on Amazon, iTune and 7digital
define(GET_LYRICS, true); //get lyrics of the current song using chartlyrics.com's API
define(CACHE_ALBUM_ART, true);//cache album art images to local server
define(RECORD_HISTORY, true);//record play history of your radio


?>

icecast.php

<?php 
/*
        by Jude <[email protected]>
        http://jude.im/
        works with Icecast 2.3.2
*/

require('config.php');
$stream = getStreamInfo();
if($stream['info']['status'] == 'OFF AIR'){
        cacheVar($stream);
}
else{
        $last_song = @file_get_contents('last.txt');
        if($last_song != base64_encode($stream['info']['song'])){
                $stream = init($stream);
                $stream = getInfo($stream);
                file_put_contents('last.txt', base64_encode($stream['info']['song']));
                cacheVar($stream);
                if(RECORD_HISTORY == true){
                        cacheHistory($stream);
                }
        }
        else{
                $stream = array_decode(json_decode(@file_get_contents('var/info.json'), TRUE));
        }
}
//print_r($stream);

function obj_to_array($obj){
        $array = (is_object) ? (array)$obj : $obj;
        foreach($array as $k=>$v){
                if(is_object($v) OR is_array($v))
                        $array[$k] = obj_to_array($v);
        }
        return $array;
}

function getStreamInfo(){
        $str = @file_get_contents(SERVER.'/status.xsl?mount='.MOUNT);
        if(preg_match_all('/<td\s[^>]*class=\"streamdata\">(.*)<\/td>/isU', $str, $match)){
                $stream['info']['status'] = 'ON AIR';
                $stream['info']['title'] = $match[1][0]; 
                $stream['info']['description'] = $match[1][1]; 
                $stream['info']['type'] = $match[1][2]; 
                $stream['info']['start'] = $match[1][3]; 
                $stream['info']['bitrate'] = $match[1][4]; 
                $stream['info']['listeners'] = $match[1][5]; 
                $stream['info']['msx_listeners'] = $match[1][6]; 
                $stream['info']['genre'] = $match[1][7]; 
                $stream['info']['stream_url'] = $match[1][8];
                $stream['info']['artist_song'] = $match[1][9];
                        $x = explode(" - ",$match[1][9]); 
                $stream['info']['artist'] = $x[0]; 
                $stream['info']['song'] = $x[1];
        }
        else{
                $stream['info']['status'] = 'OFF AIR';
        }
        return $stream;
}

//get information of the current song use last.fm's API
function getTrackInfo($stream){
        $url = str_replace('#','','http://ws.audioscrobbler.com/2.0/?method=track.getinfo&artist='.urlencode($stream['info']['artist']).'&track='.urlencode($stream['info']['song']).'&api_key='.LAST_FM_API);
        $xml = simplexml_load_file($url,'SimpleXMLElement', LIBXML_NOCDATA);
        $xml = obj_to_array($xml);
//      print_r($xml);
        if($xml['track']['album']['image']){
                $stream['album']['image_s'] = $xml['track']['album']['image'][0];
                $stream['album']['image_m'] = $xml['track']['album']['image'][1];
                $stream['album']['image_l'] = $xml['track']['album']['image'][2];
                $stream['album']['image_xl'] = $xml['track']['album']['image'][3];
        }
        if($xml['track']['wiki']['summary']){
                $stream['track']['summary'] = $xml['track']['wiki']['summary'];
                $stream['track']['info'] = $xml['track']['wiki']['content'];
        }
        if($xml['track']['album']['title']){
                $stream['album']['title'] = $xml['track']['album']['title'];
                $stream['album']['lastfm_url'] = $xml['track']['album']['url'];
        }
        $stream['track']['lastfm_url'] = $xml['track']['url'];
        if($xml['track']['artist']['url']){
                $stream['artist']['lastfm_url'] = $xml['track']['artist']['url'];
        }
        return $stream;
}

//get extra information of the album
function getAlbumInfo($stream){
        $url = str_replace('#','', 'http://ws.audioscrobbler.com/2.0/?method=album.getinfo&artist='.urlencode($stream['info']['artist']).'&album='.($stream['album']['title']).'&api_key='.LAST_FM_API);
        $xml = simplexml_load_file($url,'SimpleXMLElement', LIBXML_NOCDATA);
        $xml = obj_to_array($xml);
        if ($xml['album']['releasedate'] && strlen($xml['album']['releasedate']) > 10){
                $stream['album']['releasedate'] = reset(explode(",",$xml['album']['releasedate']));
        }
        if($xml['album']['tracks']['track']){
                foreach($xml['album']['tracks']['track'] as $track){
                        $stream['album']['track_list'][] = array('title' => $track['name'],'url' => $track['url']);
                }
        }
        if($xml['album']['wiki']['summary']){
                $stream['album']['summary'] = $xml['album']['wiki']['summary'];
                $stream['album']['info'] = $xml['album']['wiki']['content'];
        }
        return $stream;
}

//get extra information of the artist           
function getArtistInfo($stream){
        $url = 'http://ws.audioscrobbler.com/2.0/?method=artist.gettopalbums&artist='.urlencode($stream['info']['artist']).'&api_key='.LAST_FM_API.'&autocorrect=1';
        $xml = simplexml_load_file($url,'SimpleXMLElement', LIBXML_NOCDATA);
        $xml = obj_to_array($xml);
//      print_r($xml);
        if($xml['topalbums']['album']){
                foreach($xml['topalbums']['album'] as $album){
                        $stream['artist']['top_albums'][] = array('title'=>$album['name'], 'url'=>$album['url'], 'image'=>$album['image']);
                }
        }

        $url = 'http://ws.audioscrobbler.com/2.0/?method=artist.getInfo&artist='.urlencode($stream['info']['artist']).'&api_key='.LAST_FM_API.'&autocorrect=1';
        $xml = simplexml_load_file($url,'SimpleXMLElement', LIBXML_NOCDATA);
        $xml = obj_to_array($xml);
//      print_r($xml);
        if($xml['artist']['bio']['summary']){
                $stream['artist']['summary'] = $xml['artist']['bio']['summary'];
                $stream['artist']['info'] = $xml['artist']['bio']['content'];
        }
        return $stream;
}

//get buylink   
function getTrackBuyLink($stream){
        $url = 'http://ws.audioscrobbler.com/2.0/?method=track.getbuylinks&artist='.urlencode($stream['info']['artist']).'&track='.urlencode($stream['info']['song']).'&api_key='.LAST_FM_API.'&country='.urlencode('united states').'&autocorrect=1';
        $xml = simplexml_load_file($url,'SimpleXMLElement', LIBXML_NOCDATA);
        $xml = obj_to_array($xml);
//      print_r($xml);
        if($xml['affiliations']['physicals']['affiliation']){
                foreach($xml['affiliations']['physicals']['affiliation'] as $buy){
                        $supplier = str_replace('iTuens', 'iTunes', $buy['supplierName']);
                        if($buy['isSearch'] == 0){
                                $new = array('link' => $buy['buyLink'], 'price'=>$buy['price']['amount'], 'currency'=>$buy['price']['currency'], 'icon'=>$buy['supplierIcon']);
                        }
                        else{
                                $new = array('link' => $buy['buyLink'],'icon'=>$buy['supplierIcon']);
                        }
                        $stream['track']['buylink']['physical'][$supplier] = $new;
                }
        }
        if($xml['affiliations']['downloads']['affiliation']){
                foreach($xml['affiliations']['downloads']['affiliation'] as $buy){
                        $supplier = str_replace('Amazon MP3', 'Amazon', $buy['supplierName']);
                        if($buy['isSearch'] == 0){
                                $new = array('link' => $buy['buyLink'], 'price'=>$buy['price']['amount'], 'currency'=>$buy['price']['currency'], 'icon'=>$buy['supplierIcon']);
                        }
                        else{
                                $new = array('link' => $buy['buyLink'],'icon'=>$buy['supplierIcon']);
                        }
                        $stream['track']['buylink']['download'][$supplier] = $new;
                }
        }
        return $stream;
}


//cache album art images to local server, change the image size if you want
function cacheAlbumArt($image_url){
        $filename = end(explode('/', $image_url));
        $local_image = 'cache/'.$filename;
        if (!is_file($stream['album']['local_image'])){
                copy($image_url, $local_image);
        }
        return $local_image;
}

//get lyrics from chartlyrics.com's API
function getLyric($artist, $song){
        $url = str_replace('\'','','http://api.chartlyrics.com/apiv1.asmx/SearchLyricDirect?artist='.urlencode($artist).'&song='.urlencode($song));
        $xml = simplexml_load_file($url,'SimpleXMLElement', LIBXML_NOCDATA);
        $xml = obj_to_array($xml);
//      print_r($xml);
        if($xml['LyricId'] && ($xml['Lyric'] != array())){
                return $xml['Lyric'];
        }
        else{
                return 'Sorry, there\'s no lyric found for this song';
        }
}

function getInfo($stream){
        if(!$stream['info']['song']){
                $stream['info']['song'] == 'Not found';
                return $stream;
        }
        if(GET_TRACK_INFO == TRUE){
                $stream = getTrackInfo($stream);
        }
        if(GET_ALBUM_INFO && isset($stream['album']['title'])){
                $stream = getAlbumInfo($stream);
        }
        if(GET_ARTIST_INFO == TRUE){
                $stream = getArtistInfo($stream);
        }
        if(GET_TRACK_BUY_LINK == TRUE){
                $stream = getTrackBuyLink($stream);
        }
        if(CACHE_ALBUM_ART == TRUE){
                $stream['album']['local_image'] = cacheAlbumArt($stream['album']['image_l']);
        }
        if(GET_LYRICS == TRUE){
                $stream['track']['lyric'] = getLyric($stream['info']['artist'], $stream['info']['song']);
        }
        $stream['fetch_time'] = time();
        return $stream;
}

function array_encode($array){
        foreach($array as $key=>$value){
                if(is_array($value)){
                        $array[$key] = array_encode($value);
                }
                else{
                        $array[$key] = base64_encode($value);
                }
        }
        return $array;
}

function array_decode($array){
        foreach($array as $key=>$value){
                if(is_array($value)){
                        $array[$key] = array_decode($value);
                }
                else{
                        $array[$key] = base64_decode($value);
                }
        }
        return $array;
}

function cacheVar($stream){
        $stream = array_encode($stream);
        file_put_contents('var/info.json', json_encode($stream));
}

function cacheHistory($stream){
        if($stream['song'] == 'Not found'){
                return;
        }
        $year = date('Y');
        $month = date('m');
        $day = date('d');
        if(!is_dir('history')){
                mkdir('history', 0777);
        }
        if(!is_dir('history/'.$year)){
                mkdir('history/'.$year);
        }
        if(!is_dir('history/'.$year.'/'.$month)){
                mkdir('history/'.$year.'/'.$month);
        }
        $file = 'history/'.$year.'/'.$month.'/'.$day.'.json';
        $history['time'] = gmdate('c');
        $history['artist'] = $stream['info']['artist'];
        $history['song'] = $stream['info']['song'];
        $history['image'] = $stream['album']['image_s'];
        $history['itunes'] = $stream['track']['buylink']['download']['iTunes']['link'];
        $history['Amazon'] = $stream['track']['buylink']['download']['Amazon']['link'];
        $history = array_encode($history);
        file_put_contents($file, json_encode($history));
        createHistory();
}

function createHistory(){
        $history = json_decode(@file_get_contents('var/history.json'), TRUE);
        $year = date('Y');
        $month = date('m');
        $day = date('d');
        $history[$year][$month][$day] = $year.$month.$day;
        $file = 'history/'.$year.'/'.$month.'/'.$day.'.json';
        file_put_contents('var/history.json', json_encode($history));
}


function init($stream){
        $stream['album']['image_s'] = $stream['album']['image_m'] = $stream['album']['image_l'] = $stream['album']['image_xl'] = DEFAULT_ALBUM_ART;
        $stream['track']['summary']  = $stream['track']['info'] = "No information found for this track, try searching for <a target='_blank' href='http://www.google.com/search?q=".urlencode($stream['info']['artist']." - ".$stream['info']['song'])."'>".$stream['info']['artist']." - ".$stream['info']['song']."</a> on Google";
        $stream['album']['title'] = 'Not found';
        $stream['album']['lastfm_url'] = 'http://www.google.com/search?q='.urlencode($stream['info']['artist']." - ".$stream['info']['song']);
        $stream['track']['download_cn'] = 'http://www.google.cn/music/search?q='.urlencode($stream['info']['artist']." - ".$stream['info']['song']);
        $stream['album']['summary'] = $stream['album']['info'] = 'No information found for this album, try searching for <a target="_blank" href="http://www.google.com/search?q='.urlencode($stream['info']['artist']." - ".$stream['info']['song']).'">'.$stream['info']['artist']." - ".$stream['info']['song'].'</a> on Google';
        $stream['album']['releasedate'] = 'Unknown';
        $stream['artist']['summary'] = $stream['artist']['info'] = 'No information found for this artist, try searching for <a target="_blank" href="http://www.google.com/search?q='.urlencode($stream['info']['artist']).'">'.$stream['info']['artist'].'</a> on Google';
        return $stream;
}

?>

私はPHPにまったく慣れておらず、手順を完全には理解していません。投稿された手順は次のとおりです。

自分のサイトでスクリプトを使用する方法:

last.fmからAPIキーを取得します。http://www.last.fm/api/accountスクリプトを取得し、構成ファイル(config.php)を編集します。使用可能な変数を使用して、必要なものをエコーし​​ます。次のリストもあります。このwikiページで利用可能な変数:code.google.com/p/icecast-now-playing-script/wiki/Variables PHPをサポートするWebスペースにスクリプトをアップロードし、スクリプトの属性を書き込み可能に変更します>ディレクトリ( "666 " 例えば)

UPDATE GViewのアドバイスを使用し、file_get_contentsの前の「@」を削除してvar_dump($ str)を呼び出すと、次のエラーが返されます。

 Warning:  file_get_contents(http://70.35.120.203:8000/status.xsl?mount=/zedg_mb.mp3.m3u) [function.file-get-contents]: failed to open stream: Connection refused in /home/content/14/7785714/html/NowPlaying/icecast.php on line 40

bool(false)
Array
(
    [info] => Array
        (
            [status] => OFF AIR
        )

)       Please! Does anyone have any suggestions?
gview

私の推測では、サーバーはHTTPストリームラッパーを許可していません。

icecast.phpスクリプトでは、関数getStreamInf()が呼び出されており、上部で次のコマンドを使用してストリームを開こうとします。

$str = @file_get_contents(SERVER.'/status.xsl?mount='.MOUNT);

これをデバッグするには、2つのことを行います。まず、file_get_contents呼び出しでのエラー出力を抑制する@を削除します。次に、一時的なデバッグ出力を追加します。

$str = file_get_contents(SERVER.'/status.xsl?mount='.MOUNT);
var_dump($str);

データが返されるのではなく、セキュリティ関連のエラーが発生した場合は、サーバーのphp.iniファイルを確認する必要があります。

allow_url_fopen = on

このスクリプトが試みるように、file_get_contentsがURLを開くことができるように設定する必要があります。サーバーがオフに設定されている場合は、サーバーでその設定を変更できる必要があります。また、これらの変更を有効にするには、Webサーバーを再起動できる必要があります。

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

PHPスクリプトがPleskで機能しない

分類Dev

PHP:PythonスクリプトのexecがRaspberry PI2で機能しない

分類Dev

スクリプトで中括弧の展開が機能しない

分類Dev

クエリ自体が機能するのに、phpスクリプトのこのクエリが機能しないのはなぜですか?

分類Dev

この単純なPHPログインスクリプトが機能しないのはなぜですか?

分類Dev

この単純なphpスクリプトが機能しないのはなぜですか?

分類Dev

スクリプトが変更中のプロジェクト構造で機能しない

分類Dev

Ajaxwindow.locationがPHPログインスクリプトで機能しない

分類Dev

XCOPYがスクリプトで機能しないのはなぜですか?

分類Dev

スクリプトでSETLINESIZEが機能しないのはなぜですか?

分類Dev

SSISのスクリプトタスクが機能しない

分類Dev

CSS、phpでのajax呼び出し後にJavaスクリプトが正しく機能しない

分類Dev

PHPスクリプトからのAJAX応答が機能しない

分類Dev

PHPスクリプトからのJson応答が機能しない

分類Dev

アプリアクションでのテスト中にスライスのsetSeeMoreAction()が機能しない

分類Dev

PHPのHTTPリクエストが特定のAPIで機能しない

分類Dev

PHPが機能しない状態でいくつかのPythonスクリプトを実行する

分類Dev

SQLスクリプトが機能しないのはなぜですか?

分類Dev

crontabスクリプトが機能しないのはなぜですか?

分類Dev

bashスクリプトが機能しないのはなぜですか?

分類Dev

スクリプトが機能しないのはなぜですか?

分類Dev

なぜJavaスクリプトが機能しないのですか?

分類Dev

phpスクリプトが無料ホスティングで機能するのにvpsでは機能しないのはなぜですか?

分類Dev

この特定のスクリプトでinnerHTMLが機能しない

分類Dev

シェルスクリプトでカット機能が機能しない

分類Dev

SQLクエリを含むスクリプトでPHPリダイレクトが機能しない

分類Dev

App Bundleのビルド中にGradleスクリプトが機能しない

分類Dev

.animateと.offsetがjQueryスクリプトで機能しない

分類Dev

PowershellスクリプトがISEで機能しない

Related 関連記事

  1. 1

    PHPスクリプトがPleskで機能しない

  2. 2

    PHP:PythonスクリプトのexecがRaspberry PI2で機能しない

  3. 3

    スクリプトで中括弧の展開が機能しない

  4. 4

    クエリ自体が機能するのに、phpスクリプトのこのクエリが機能しないのはなぜですか?

  5. 5

    この単純なPHPログインスクリプトが機能しないのはなぜですか?

  6. 6

    この単純なphpスクリプトが機能しないのはなぜですか?

  7. 7

    スクリプトが変更中のプロジェクト構造で機能しない

  8. 8

    Ajaxwindow.locationがPHPログインスクリプトで機能しない

  9. 9

    XCOPYがスクリプトで機能しないのはなぜですか?

  10. 10

    スクリプトでSETLINESIZEが機能しないのはなぜですか?

  11. 11

    SSISのスクリプトタスクが機能しない

  12. 12

    CSS、phpでのajax呼び出し後にJavaスクリプトが正しく機能しない

  13. 13

    PHPスクリプトからのAJAX応答が機能しない

  14. 14

    PHPスクリプトからのJson応答が機能しない

  15. 15

    アプリアクションでのテスト中にスライスのsetSeeMoreAction()が機能しない

  16. 16

    PHPのHTTPリクエストが特定のAPIで機能しない

  17. 17

    PHPが機能しない状態でいくつかのPythonスクリプトを実行する

  18. 18

    SQLスクリプトが機能しないのはなぜですか?

  19. 19

    crontabスクリプトが機能しないのはなぜですか?

  20. 20

    bashスクリプトが機能しないのはなぜですか?

  21. 21

    スクリプトが機能しないのはなぜですか?

  22. 22

    なぜJavaスクリプトが機能しないのですか?

  23. 23

    phpスクリプトが無料ホスティングで機能するのにvpsでは機能しないのはなぜですか?

  24. 24

    この特定のスクリプトでinnerHTMLが機能しない

  25. 25

    シェルスクリプトでカット機能が機能しない

  26. 26

    SQLクエリを含むスクリプトでPHPリダイレクトが機能しない

  27. 27

    App Bundleのビルド中にGradleスクリプトが機能しない

  28. 28

    .animateと.offsetがjQueryスクリプトで機能しない

  29. 29

    PowershellスクリプトがISEで機能しない

ホットタグ

アーカイブ