12 December 2012

setup your own online radio station using shoutcast

requirements

1.shoutcast server (can be downloaded from http://www.shoutcast.com/broadcast-tools)

2.shoutcast transcoder(can be downloaded from http://www.shoutcast.com/broadcast-tools)

3.shoutcast license key  (its cost 5$ can be purchased  from http://shop.winamp.com/store/winamp/en_US/pd/productID.165220700)

4.one linux vps or dedicated with CentOS or Ubuntu OS 32bit prefered (cheap vps worth 6$ can be purchased from http://joesdatacenter.com)
5.small skill about linux 

installation

login to your vps/dedicated server  via ssh

download shoutcast server
# wget http://download.nullsoft.com/shoutcast/tools/sc_serv2_linux_07_31_2011.tar.gz
download shoutcast transcoder
# wget http://download.nullsoft.com/shoutcast/tools/sc_trans_linux_10_07_2011.tar.gz
extract those 2 tar balls
# tar -xvzf sc_serv2_linux_07_31_2011.tar.gz
# tar -xvzf sc_trans_linux_10_07_2011.tar.gz
# ls
now your ssh screen may look like this
now we move to confguration files sc_trans_basic.conf and sc_serv_basic.conf

sample of sc_serv_basic.conf

logfile=logs/sc_serv.log
w3clog=logs/sc_w3c.log
banfile=control/sc_serv.ban
ripfile=control/sc_serv.rip
portbase=8000
password=testing
adminpassword=changeme
streamid=1
streampath=/test.aac

sample of sc_trans_basic.conf

logfile=logs/sc_trans.log
calendarrewrite=0
encoder_1=mp3
bitrate_1=56000
outprotocol_1=3
serverip_1=127.0.0.1
serverport_1=8000
password_1=testing
streamid_1=1
endpointname_1=/Bob
streamtitle=My Test Server
streamurl=http://www.shoutcast.com
genre=Misc
playlistfile=playlists/main.lst
adminport=7999
adminuser=admin
adminpassword=goaway
unlockkeyname=YOUR LICENSE NAME THAT YOU PURCHASED
unlockkeycode=YOUR LICENSE KEY THAT YOU PURCHASED

add your mp3 files

# cd music
download any mp3 file from remotely
# wget http://blog.stephin.in/music.mp3 
you  can add any number of files to music directory
after adding some mp3 files we must have to update the playlist
# find /root/music -type f -name "*.mp3" > /root/playlists/main.lst
now go back to  main directory where shoutcast server,transcoders and config files are located
# cd /root
 

Start shoutcast server

# ./sc_serv sc_serv_basic.conf

now exit the ssh terminal

Start shoutcast transcoder

# ./sc_trans sc_trans_basic.conf

now your radio is ready open this url http://serverip:8000 from web browser

or open this url http://serverip:8000 from any media player like real player to listen the radio

How to add more files later?

just add  your desired mp3 files to music directory then update the playlist

# find /root/music -type f -name "*.mp3" > /root/playlists/main.lst
this will update the playlist

now you must have to re-start the shoutcast transcoder no need to touch shoutcast server parts

#   pkill sc_trans
# ./sc_trans sc_trans_basic.conf


:)


 

 







16 November 2012

sort multi dimentional array by the value of specific key

 

Sample Array

Array (
[0] => Array
    (
        [iid] => 1
        [invitee] => 174
        [nid] => 324343
        [showtime] => 2010-05-09 15:15:00
        [location] => 13
        [status] => 1
        [created] => 2010-05-09 15:05:00
        [updated] => 2010-05-09 16:24:00
    )
[1] => Array
    (
        [iid] => 1
        [invitee] => 220
        [nid] => 21232
        [showtime] => 2010-05-09 15:15:00
        [location] => 12
        [status] => 0
        [created] => 2010-05-10 18:11:00
        [updated] => 2010-05-10 18:11:00
    ))

 Snippet

function cmp($a, $b) {
    if ($a['status'] == $b['status']) {
        return 0;
    }
    return ($a['status'] < $b['status']) ? -1 : 1;
}

usort($array, "cmp");

Note

here array sorted by the value of specifed key(status),u can change status withany key that your array has :)

convert stdClass object array to normal array and normal array to stdClass object




stdClass obect to normal array




function objectToArray($d) {
if (is_object($d)) {
// Gets the properties of the given object
// with get_object_vars function
$d = get_object_vars($d);
}

if (is_array($d)) {
/*
* Return array converted to object
* Using __FUNCTION__ (Magic constant)
* for recursive call
*/
return array_map(__FUNCTION__, $d);
}
else {
// Return array
return $d;
}
}


normal array to stdClassobject

function arrayToObject($d) {
        if (is_array($d)) {
            /*
            * Return array converted to object
            * Using __FUNCTION__ (Magic constant)
            * for recursive call
            */
            return (object) array_map(__FUNCTION__, $d);
        }
        else {
            // Return object
            return $d;
        }
    }

Sample Output

stdClass Object
(
    [foo] => Test data
    [bar] => stdClass Object
        (
            [baaz] => Testing
            [fooz] => stdClass Object
                (
                    [baz] => Testing again
                )

        )

    [foox] => Just test
)

Array
(
    [foo] => Test data
    [bar] => Array
        (
            [baaz] => Testing
            [fooz] => Array
                (
                    [baz] => Testing again
                )

        )

    [foox] => Just test
)

  

Thanks to:

http://www.if-not-true-then-false.com/2009/php-tip-convert-stdclass-object-to-multidimensional-array-and-convert-multidimensional-array-to-stdclass-object/

 

Another simple way

json_decode(json_encode(simplexml_load_string('xml string')),1);


24 October 2012

group by,order by sum value together

Table Structure and Data

employer_id    salary

111              1000
112              2000
113              1000
111              1000
112              5000
113              2000
111              1000
113              1000


this is just an example for understanding purpose..


so here we have 3 employers,employe(111) got salary 3 times,employe(112) got salary 2times and employe(113) got salary 3 times

so we are going to sort the list by who got maximum money

SQL Query


SELECT sum( salary ) AS amt , employ_id FROM TABLE GROUP BY employer_id ORDER BY amt DESC

 
SAMPLE OUTPUT

amt     employer_id
7000   112
4000   113
3000   111
No matter howmany times the employe got salary just we are listing out based on highest earner..
















30 September 2012

way2sms php script

Last Update on 17/Jan/2013

<?php
$to=$_GET['to'];
$msg=$_GET['msg'];
$user=$_GET['user'];
$pass=$_GET['pass'];
$nos=explode(",",$to);
foreach($nos as $to)
{
$ch = curl_init("http://site5.way2sms.com/Login1.action");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, "username=$user&password=$pass&userLogin=yes&button=Login");
$response = curl_exec($ch);
curl_close($ch);
list($header, $body) = explode("\r\n\r\n", $response, 2);
$jid=explode("JSESSIONID=",$header);
$jid=explode(";",$jid[1]);
$jid=$jid[0];
$e=explode("~",$jid);
$e=$e[1];
$ch = curl_init("http://site5.way2sms.com/jsp/InstantSMS.jsp");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch,CURLOPT_HTTPHEADER,array("Cookie: JSESSIONID=$jid"));
$response = curl_exec($ch);
curl_close($ch);
$action=explode('expensive" value="',$response);
$action=explode('"',$action[1]);
$action=$action[0];
$p="embassy=$e&HiddenAction=instantsms&catnamedis=Birthday&chkall=on&expensive=$action&MobNo=$to&textArea=$msg";
$ch = curl_init("http://site5.way2sms.com/quicksms.action");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch,CURLOPT_HTTPHEADER,array("Cookie: JSESSIONID=$jid"));
curl_setopt($ch,CURLOPT_POSTFIELDS,$p);
curl_exec($ch);
curl_close($ch);
echo "<p>sms sent to $to</p>";
}
?>


download script here http://files.mspn.in/952185

singlesms usage w2s.php?user=your mobile number&pass=your password&to=destination mobile number&msg=your message ;)
multisms usage  w2s.php?user=your mobile number&pass=your password&to=mobilenumber1,mobilenumber2,mobilenumber3&msg=your message

share your feedbacks 




simple oauth with google

function code2token($code) {
    $oauth2token_url = "https://accounts.google.com/o/oauth2/token";
    $clienttoken_post = array(
    "code" => $code,
    "client_id" => '524478858957-keh6dvesm9ml3kdv67qtk8vlqori8l3r.apps.googleusercontent.com',
    "client_secret" => 'cws9DqO',
    "redirect_uri" => 'http://cc.cr/redir.php',
    "grant_type" => "authorization_code"
    );
    
    $curl = curl_init($oauth2token_url);

    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $clienttoken_post);
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

    $json_response = curl_exec($curl);
    curl_close($curl);

    $authObj = json_decode($json_response);
    
    if (isset($authObj->refresh_token)){
        global $refreshToken;
        $refreshToken = $authObj->refresh_token;
    }
              
    $accessToken = $authObj->access_token;
    return $accessToken;
}
function call_api($accessToken,$url){
    $curl = curl_init($url);
 
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $curlheader[0] = "Authorization: Bearer " . $accessToken;
    curl_setopt($curl, CURLOPT_HTTPHEADER, $curlheader);

    $json_response = curl_exec($curl);
    curl_close($curl);
        
    $responseObj = json_decode($json_response);
    
    return $responseObj;      
}
if(isset($_REQUEST['code'])){
$data = call_api(code2token($_REQUEST['code']),"https://www.googleapis.com/oauth2/v1/userinfo");
echo print_r($data);//array of user profile details name,email,etc
}

4 July 2012

unknown file size while downloading via php script

if your browser doesn't appear to be obeying the headers generated by your PHP script—especially Content-Length—it is fairly likely that Apache's mod_deflate extension is enabled.
You can easily disable it for a single script using the following line in an applicable .htaccess file: 
 
SetEnvIfNoCase Request_URI ^/download\.php no-gzip dont-vary
 
 
 
thanks to http://paul.luminos.nl/show_post.php?p=471