'Shoutcast (stats / 7.html)', 'description' => __( 'Reads /stats?json=1 (v2) or /7.html (v1) on the stream host.', 'streamsera' ), 'usesUrl' => true, 'usesMount' => false, ); } /** * {@inheritdoc} * * @param array $source Source definition (url, mount, stream_url). */ public function fetch( array $source ) { $base = ! empty( $source['url'] ) ? $source['url'] : Resolver::status_url( $source['stream_url'], '' ); if ( ! $base ) { return null; } $base = untrailingslashit( preg_replace( '#/(stats|7\.html).*$#', '', $base ) ); // v2 JSON. $body = Resolver::http_get( $base . '/stats?json=1' ); if ( $body ) { $json = json_decode( $body, true ); if ( is_array( $json ) && isset( $json['songtitle'] ) && is_scalar( $json['songtitle'] ) ) { $parts = Resolver::split_title( (string) $json['songtitle'] ); return array( 'title' => $parts['title'], 'artist' => $parts['artist'], 'raw' => (string) $json['songtitle'], 'listeners' => isset( $json['currentlisteners'] ) ? (int) $json['currentlisteners'] : null, 'live' => ! empty( $json['streamstatus'] ), 'server' => 'shoutcast', 'bitrate' => isset( $json['bitrate'] ) ? (int) $json['bitrate'] : null, 'server_name' => isset( $json['servertitle'] ) && is_scalar( $json['servertitle'] ) ? (string) $json['servertitle'] : '', ); } } // v1 7.html: "current,status,peak,max,unique,bitrate,title". $body = Resolver::http_get( $base . '/7.html' ); if ( $body ) { $text = wp_strip_all_tags( $body ); $cols = explode( ',', $text, 7 ); if ( count( $cols ) >= 7 ) { $parts = Resolver::split_title( trim( $cols[6] ) ); return array( 'title' => $parts['title'], 'artist' => $parts['artist'], 'raw' => trim( $cols[6] ), 'listeners' => (int) $cols[0], 'live' => '1' === trim( $cols[1] ), 'server' => 'shoutcast', 'bitrate' => (int) $cols[5], 'server_name' => '', ); } } return null; } }