Record Live Streaming Radio to MP3


Hits: 39  

Sometime you want to record Live Radio Stream to MP3 file, you can find many online linux tools for recording radio stream to server and then download to your local computer.

You can use Linux “wget” or “curl”

CURL

# curl -sS -o stream.mp3 –max-time 150 http://Radio-Server:Port/stream
Bitrate: 128 kb/s [it will make approx 2MB MP3 file]

# curl -sS -o stream.mp3 –max-time 150 http://Radio-Server:Port/stream
Bitrate: 64 kb/s [it will make approx 1MB MP3 file]

WGET

# wget -O stream.mp3 “http://Radio-Server:Port/stream”

Wowza Live Stream thumbnail images with HTTP Provider


Hits: 3990  

To get thumbnail images from Wowza Transcoder with an HTTP Provider Wowza Media Server 3 or later is required.

Config file to edit for Wowza Live Stream Thumbnails
[wowza-install-dir]/conf/VHost.xml

<HTTPProvider>
<BaseClass>com.wowza.wms.transcoder.httpprovider.HTTPTranscoderThumbnail</BaseClass>
<RequestFilters>transcoderthumbnail*</RequestFilters>
<AuthenticationMethod>none</AuthenticationMethod>
</HTTPProvider>

 

PHP code

//No Authentication
exec(‘curl “http://[wowza-ip-address]:8086/transcoderthumbnail?application=[application-name]&streamname=[stream-name]&format=[jpeg or png]&size=[widthxheight]”‘);

//With Authentication
exec(‘curl – -digest -u [wowza-admin-user]:[wowza-admin-password] “http://[wowza-ip-address]:8086/transcoderthumbnail?application=[application-name]&streamname=[stream-name]&format=[jpeg or png]&size=[widthxheight]”‘);

[wowza-ip-address]: The IP address of the server running the Wowza media server
[application-name]: The application name the stream is running live
[stream-name]: The stream name of the live source stream.
[format]: Format of the image: either jpeg or png
[size]: Size of the thumbnail image.

Error

HTTPTranscoderThumbnail.onHTTPRequest[live/_definst_/[stream-name]]: Live stream encoder not found

Make sure Wowza is configured for Transcoding of live streams with Transcoder Addons.

live_stream_transcoder_addons

You will see some live encoded wowza streams based on selected transcoding template

live_stream_encoder

MistServer PHP API for Live Stream


Hits: 3918  

MistServer is a highly versatile, lightweight, customizable open-source multi-standard multimedia server. MistServer configuration is easy to use for full CDN solutions applications. Hope you already read our article to Install MistServer

Mistserver Manager Login

MistServer API provides a Server API and a Management API.

You can find MistServer PHP API Examples Here

Note: Make sure port 4242 used for MistServer is open on your web hosting firewall where you run MistServer PHP API for Live Stream

MistServer PHP API for Live Stream will try to put/get data using PHP CURL in port 4242

$server = new Mistserver();
$server->login(‘http://server-ip:4242/api’, ‘username’, ‘password’);

// you can add a live stream:
$server->add_stream( STREAM_NAME, push://@SOURCE, BUFFER_TIME);

mistserver-api-form

Your channel has been successfully created. Use the details below to broadcast:
Download: Download Flash Media Live Encoder 3.2
FMS URL: rtmp://server-ip:1935/live
Stream Name: churchstream

mistserver-stream

As you get Live Media Stream details you can use our article to make your event live…
Live video stream event for online Temple or Church

API Call Reference: http://www.mistserver.org/doxygen/api.html

Wowza Live Cam Secure Expired Token


Hits: 5604  
Wowza Live Cam Secure Expired Token
Wowza Live Cam Secure Expired Token

wowza-live-cam-secure-expired-token.php
// Encrypt original stream URL http://wowza-server:port/stream/playlist.m3u8
$base64ized = encryptDecrypt($secret_key, $streamURL, 0);

// Decrypt stream URL
$streamURL = encryptDecrypt($secret_key, $base64ized, 1);

stream.php

// Expire stream URL after time interval & check secure token
if (($current – $timestamp) <= $expired && ($checkhash == $hash)) { include("m3u8.php"); } m3u8.php

header(“content-type: application/vnd.apple.mpegurl”);
echo file_get_contents(“http://wowza-server:port/stream/playlist.m3u8”);

Upload Large Files from Amazon S3 Bucket to Dropbox Folder


Hits: 6823  

Dropbox Uploader is a BASH script (only needs cURL) which can be used to upload, download, list or delete files from Dropbox, an online file sharing, synchronization and backup service.

Usage: ./dropbox_uploader.sh COMMAND [PARAMETERS]…

Amazon S3 to Dropbox
Amazon S3 to Dropbox

Secure:It’s not required to provide your username/password to this script, because it uses the official Dropbox API for authentication process.

START DROPBOX UPLOADER

# chmod +x dropbox_uploader.sh
# ./dropbox_uploader.sh

It will ask “App key”, “App secret” and “Access level (App folder or Full Dropbox)”

As shell script authorize token…

Please visit this URL from your Browser, and allow Dropbox Uploader
to access your DropBox account:

–> https://www2.dropbox.com/1/oauth/authorize?oauth_token=xxxxxxxxxxxxxxx

Dropbox token for Command Line
Dropbox token for Command Line

If everything go well …

> Access Token request… OK

Setup completed!

Now you can download Amazon S3 Bucket files on server using “wget” then you can run command like…

# ./dropbox_uploader.sh COMMAND [PARAMETERS]…
# ./dropbox_uploader.sh upload /var/www/aws/s3/svnlabs.mp4 /DROPBOX-FOLDER/svnlabs.mp4

I have uploaded media file upto 500MB on dropbox successfully using this shell script 😉

Alternate Options:

You can try Node.js for reading files from Amazon S3 and then upload to Dropbox

Useful JavaScript Tools

http://loose-bits.com/2011/10/16/node-sunny-cloud-library.html
https://github.com/nuxusr/Node.js—Amazon-S3
https://github.com/appsattic/connect-stream-s3

https://github.com/evnm/dropbox-node
https://github.com/sintaxi/node-dbox
https://github.com/dropbox/dropbox-js

Amazon S3 Error Handling


Hits: 5994  

Amazon S3 PHP Class A standalone Amazon S3 (REST) client for PHP 5.2.x using CURL that does not require PEAR.

AWS Management Console Home
AWS Management Console Home

AMAZON S3 (Scalable Storage in the Cloud) PHP CLASS

AWS access info
AWS access info

// AWS access info
if (!defined(‘awsAccessKey’)) define(‘awsAccessKey’, ‘CHANGE-KEY’);
if (!defined(‘awsSecretKey’)) define(‘awsSecretKey’, ‘CHANGE-KEY’);

OO method (e,g; $s3->getObject(…)):
$s3 = new S3(awsAccessKey, awsSecretKey);

Statically (e,g; S3::getObject(…)):
S3::setAuth(awsAccessKey, awsSecretKey);

Warning: S3::getBucket(): [PermanentRedirect] The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.

We need to End Point for our S3 Buckets by default it’s s3.amazonaws.com

$s3 = new S3(awsAccessKey, awsSecretKey);

S3 Management Console
S3 Management Console

Else we need to specify here… s3-ap-southeast-1.amazonaws.com

S3 Management Console
S3 Management Console

$s3 = new S3(awsAccessKey, awsSecretKey, true, ‘s3-ap-southeast-1.amazonaws.com‘);

Warning: S3::getBucket(): [60] SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

We need SSL enabled with CURL 😉

OpenSSL phpinfo()
OpenSSL phpinfo()
CURL With OpenSSL phpinfo()
CURL With OpenSSL phpinfo()

For class documentation see:
http://undesigned.org.za/files/s3-class-documentation/index.html

SponsorPay API in PHP


Hits: 3983  

SponsorPay – International Leader in Engagement Marketing and Performance Advertising for the Monetization of Virtual Currency and Digital Content on Social Networks, Online Games, Virtual Worlds and Entertainment Platforms.

Mobile Developers - SponsorPay
Mobile Developers – SponsorPay

Key Features:

* Boost branding and engagement
* Acquire users and improve engagement
* Engage and monetize all your users
* Drive customer acquisition and sales
* Grow revenues with innovative products
* Achieve true glocal monetization

SponsorPay Products

* Offer Wall
* Layover Offer Wall
* Offer Banners
* Offer Bar
* Offer Widget
* BrandEngage

SponsorPay Mobile Offer API

JSON Format
http://api.sponsorpay.com/feed/v1/offers.json?appid=[APP_ID]&uid=[USER_ID]&ip=[IP_ADDRESS]&locale=[LOCALE]&device_id=[DEVICE_ID]&ps_time=[TIMESTAMP]&pub0=[CUSTOM]&timestamp=[UNIX_TIMESTAMP]&offer_types=[OFFER_TYPES]&android_id=[ANDROID_ID]&hashkey=[HASHKEY]

XML Format
http://api.sponsorpay.com/feed/v1/offers.xml?appid=[APP_ID]&uid=[USER_ID]&ip=[IP_ADDRESS]&locale=[LOCALE]&device_id=[DEVICE_ID]&ps_time=[TIMESTAMP]&pub0=[CUSTOM]&timestamp=[UNIX_TIMESTAMP]&offer_types=[OFFER_TYPES]&android_id=[ANDROID_ID]&hashkey=[HASHKEY]

<?php

// Step 1: Gather all request parameters

$page = isset($_REQUEST['page'])?$_REQUEST['page']:"1";
$uid = isset($_REQUEST['uid'])?$_REQUEST['uid']:"svnlabs";
$pub0 = isset($_REQUEST['pub0'])?$_REQUEST['pub0']:"sv";
$appid = isset($_REQUEST['appid'])?$_REQUEST['appid']:"APP-ID";
$device_id = isset($_REQUEST['device_id'])?$_REQUEST['device_id']:"DEVICE-ID";
$ip = isset($_REQUEST['ip'])?$_REQUEST['ip']:"IP-ADDRESS";
$apikey = isset($_REQUEST['apikey'])?$_REQUEST['apikey']:"API-KEY";
$format = isset($_REQUEST['format'])?$_REQUEST['format']:"json";

$requestring = 'http://api.sponsorpay.com/feed/v1/offers.'.$format.'?';

$d = array(   
        'appid' => $appid,
        'device_id' => $device_id,
        'ip' => $ip,
        'locale' => 'en',
        'page' => $page,
        'pub0' => $pub0,
        'timestamp' => time(),
        'uid' => $uid,
    );
    
    
//Step 2: Order all request alphabetically    
    
ksort($d);

//Step 3: Concatenate all request parameters

$params = '';

foreach($d as $k=>$v)
{
  $params .= $k."=".$v."&"; 
}    

//Step 4: Concatenate the resulting string with your API Key
//Step 5: Hash the resulting string using SHA1

$hash = sha1($params.$apikey);

$url = $requestring.$params."hashkey=".$hash;

echo file_get_contents($url);

?>

 

SponsorPay is a really good solution for social media platform using more engaging ad units than traditional social media formats.

Install cURL on Ubuntu


Hits: 6130  

Run the following command to enable curl package php5-curl.

$ sudo apt-get install php5-curl

Reading package lists… Done
Building dependency tree
Reading state information… Done
The following NEW packages will be installed:
php5-curl
0 upgraded, 1 newly installed, 0 to remove and 17 not upgraded.
Need to get 27.1kB of archives.
After this operation, 127kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu/ lucid-updates/main php5-curl 5.3.2-1ubuntu4.15 [27.1kB]
Fetched 27.1kB in 5s (4818B/s)
Selecting previously deselected package php5-curl.
(Reading database … 43188 files and directories currently installed.)
Unpacking php5-curl (from …/php5-curl_5.3.2-1ubuntu4.15_amd64.deb) …
Processing triggers for libapache2-mod-php5 …
* Reloading web server config apache2 [ OK ]
Setting up php5-curl (5.3.2-1ubuntu4.15) …

Restart apache

$ sudo /etc/init.d/apache2 restart
* Restarting web server apache2 … waiting [ OK ]

Hope this solution will help to enable curl in ubuntu system.

PHP Download MP3 File by URL


Hits: 12468  

PHP Download MP3 File by URL

1. WGET
It will save files on web server then use php header for prompting to download file.

2. CURL
CURL will not work efficiently for big files i.e. MP3, ZIP, MP4 etc.

3. file_get_contents()
This will consume too much memory on server. It can first read remote URL then save and download.

4. Content-type: application/x-file-to-save

<?php

if(isset($_REQUEST['inputurl']) && $_REQUEST['inputurl']!="") {

$file = $_REQUEST['inputurl']; 

header("Content-type: application/x-file-to-save"); 
header("Content-Disposition: attachment; filename=".basename($file)); 
readfile($file); 

}

?>

<form name="from" method="post" action="">
<input name="inputurl" type="text" id="inputurl"  value="" />
<input type="submit" name="Button1" value="Get File" id="Button1" />
</form>

PHP detect if its run from a cron job?


Hits: 3843  

I was looking for way to detect if PHP script was run from a shell (cron job), or if it was run from the browser.

My Cron Job was working like

* * * * * curl -s -o /dev/null http://www.svnlabs.com/allcron.php

 

The best solution is to detect $_SERVER variable with a PHP script…

The first difference was “HTTP_USER_AGENT

[HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.168 Safari/535.19  (On Browser)

[HTTP_USER_AGENT] => curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.13.1.0 zlib/1.2.3 libidn/1.18 libssh2/1.2.2   (On CronTab)

 

$u_agent = $_SERVER[‘HTTP_USER_AGENT’];

if(preg_match(‘/Mozilla/i’,$u_agent))
{
// Mozilla Firefox
}

if(preg_match(‘/curl/i’,$u_agent))
{
// curl cron
}

Try to review more differences 😉

 

<?php

error_reporting(E_ALL^E_NOTICE^E_WARNING);
header('Content-type: text/html; charset=utf-8');

debug_log(dirname(__FILE__)."/logs/cli.txt",implode(" ",$_SERVER));

debug_log(dirname(__FILE__)."/logs/cli.txt","CLI: ->".php_sapi_name());

print_r_to_file($_SERVER,dirname(__FILE__)."/logs/cli.txt");

echo"<pre>";
print_r($_SERVER);

/* print_r to File */

function print_r_to_file($var,$file){
    // writing response to external file
    $f=fopen($file,'w');
    ob_start();
    print_r($var);
    $return=ob_get_contents();
    ob_end_clean();
    fwrite($f,$return);
    fclose($f);
}

/* debug log */

function debug_log($file_path,$text)
{
    $file_dir=dirname($file_path);
    if(!file_exists($file_dir)or!is_dir($file_dir)or!is_writable($file_dir))
        returnfalse;
    
    $write_mode='w';
    if(file_exists($file_path)&&is_file($file_path)&&is_writable($file_path))
        $write_mode='a';
    
    if(!$handle=fopen($file_path,$write_mode))
        returnfalse;
    
    if(fwrite($handle,$text."\n")== FALSE )
        returnfalse;
    
    @fclose($handle);
}

?>