Bottle: Python Web Framework

Hits: 287  

I really like Bottle: Python Web Framework. Bottle is very simple, fast and powerful Python micro-framework. It is perfect for small web applications and rapid prototyping where you need simple/small API server.

Bottle is a fast, simple and lightweight WSGI micro web-framework for Python.


Install Bottle with pip install bottle or download the source package at PyPI.

Download and Install

Install the latest stable release (Bottle runs with Python 2.7 and 3.3+.)

#pip install bottle


#easy_install -U bottle


download (unstable) into your project directory.


Example: “Hello World” (

from bottle import route, run

def index(name=’World’):
return ‘Hello %s!‘ % name

run(host=’localhost’, port=8080)

Bottle Python

Point your browser to http://localhost:8080/hello/sandeep


Below find simple routing, template, static CDN, Ajax, redirect functions

Test URL for above bottle python code run on port 7800

# python

http://localhost:7800/tpl (“test” is text file on [Web-App-Root])
http://localhost:7800/static/god.jpg (“god.jpg” saved on [Web-App-Root])

FFMPEG make Video Lyrics using JPG MP3 SRT File

Hits: 359  

FFMPEG make Video Lyrics using JPG MP3 SRT File

Input Files

– Image (test.jpg)
– MP3 File (test.mp3)
– SRT Lyrics (

FFMPEG Command

# ffmpeg -loop 1 -y -i test.jpg -i test.mp3 -vf subtitles=”’FontName=Arial,FontSize=14″ -shortest test1.mp4

Output File: test1.mp4

SRT Lyrics Preview

00:00:00,330 --> 00:00:04,936
Hello Feifei. I didn't know you shopped at this supermarket too.

00:00:05,354 –> 00:00:12,303
Hi Finn. Usually I don’t. But it’s close to the office and I have to rush home to welcome an important guest.

00:00:13,378 –> 00:00:15,321
Who is it? Someone I know?

00:00:15,402 –> 00:00:29,763
No, it’s my landlady. She’s coming to collect some of her post and… well, I want to make her like me because next month, the contract on my flat is due to be renewed and she might want to increase the rent.

00:00:30,426 –> 00:00:34,919
Yeah, I see what you mean. So you’d better butter her up then!

00:00:35,450 –> 00:00:43,498
Butter? Oh, yes. But I’m a pretty bad cook. If I baked a cake it would probably be horrible!

00:00:44,474 –> 00:00:56,703
No. I don’t mean butter for a cake. In English, when you say you’ll ‘butter someone up’, you mean you’ll be especially nice to them in the hope they’ll do something good for you in return.

00:00:57,498 –> 00:01:08,424
Oh, I see. So I’ll be nice to her and pay her compliments so that she likes me and keeps the rent low. I’ll ‘butter her up’! But isn’t it a bit insincere?

00:01:09,522 –> 00:01:22,522
Well, it can have a negative connotation, yes. Let’s hear some examples of how to use ‘to butter someone up’ or ‘to butter up someone’, which is today’s expression in The English We Speak.

How to add MP3 audio delayed in MP4 video?

Hits: 378  

FFMPEG Command: Add MP3 Audio file delayed in MP4 video file

# ffmpeg.exe -i “fox-story.mp4” -itsoffset 5.00 -i “fox-story.mp3” -map 0:v -map 1:a -vcodec copy -acodec copy “The Fox and Crow Story.mp4”

Input: fox-story.mp4 and fox-story.mp3
Output: The Fox and Crow Story.mp4

-itsoffset 5.00 -i “movie.mp3”
Offsets timestamps of audio streams by 5.00 seconds

-map 1:v -map 0:a
Takes audio stream from the second (delayed) input and video stream from the first input

Song Lyrics: lrc2srt and srt2json

Hits: 385  



function lrc2srt( $lrc ) {
	$lrc = explode( "\n", $lrc );
	$srt = "";
	$lines = array();
	foreach ( $lrc as $lrcl ) {
		if ( preg_match( "|\[(\d\d)\:(\d\d)\.(\d\d)\](.+)|", $lrcl, $m ) ) {
			$lines[] = array(
				'time' => "00:{$m[1]}:{$m[2]},{$m[3]}0", // convert to SubRip-style time
				'lyrics' => trim( $m[4] )
	for ( $i = 0; $i < count( $lines ); $i++ ) {
		$n = $i + 1;
		$nexttime = isset( $lines[$n]['time'] ) ? $lines[$n]['time'] : "99:00:00,000";
		$srt .= "$n\n"
		     .  "{$lines[$i]['time']} --> {$nexttime}\n"
		     .  "{$lines[$i]['lyrics']}\n\n";
	return $srt;

echo "<pre>";
echo lrc2srt( file_get_contents("FileName.lrc") );
echo "</pre>";




define('SRT_STATE_TIME',      1);
define('SRT_STATE_TEXT',      2);
define('SRT_STATE_BLANK',     3);

$lines   = file("");

$subs    = array();
$subNum  = 0;
$subText = '';
$subTime = '';

foreach($lines as $line) {
    switch($state) {
            $subNum = trim($line);
            $state  = SRT_STATE_TIME;

        case SRT_STATE_TIME:
            $subTime = trim($line);
            $state   = SRT_STATE_TEXT;

        case SRT_STATE_TEXT:
            if (trim($line) == '') {
                $sub = new stdClass;
                $sub->number = $subNum;
                list($sub->startTime, $sub->stopTime) = explode(' --> ', $subTime);
                $sub->text   = $subText;
                $subText     = '';
                $state       = SRT_STATE_SUBNUMBER;

                $subs[]      = $sub;
            } else {
                $subText .= $line;

echo "<pre>";
echo "</pre>";

$count = count($subs);

$playlist['ID'.$i] = array($subs[$i]->text, $subs[$i]->startTime, $subs[$i]->startTime, $subs[$i]->stopTime);


echo  json_encode($playlist);



Hits: 4579  

It’s easy to convert PHP Array to Select Dropdown Box… you need to loop for all element in array to display as dropdown. But may be you ever think for reverse process. Yes, it’s also easy!

You need to scrape / crawl Select box HTML to get PHP Array back from HTML Select Box. Please read our articles for xpath here



$s = '<select name="country">
<option value="">Country...</option>
<option value="AF">Afghanistan</option>
<option value="AL">Albania</option>
<option value="DZ">Algeria</option>
<option value="AS">American Samoa</option>
<option value="AD">Andorra</option>
<option value="AG">Angola</option>
<option value="AI">Anguilla</option>
<option value="AG">Antigua &amp; Barbuda</option>
<option value="AR">Argentina</option>
<option value="AA">Armenia</option>
<option value="AW">Aruba</option>
<option value="AU">Australia</option>
<option value="AT">Austria</option>
<option value="AZ">Azerbaijan</option>
<option value="BS">Bahamas</option>
<option value="BH">Bahrain</option>
<option value="BD">Bangladesh</option>
<option value="BB">Barbados</option>
<option value="BY">Belarus</option>
<option value="BE">Belgium</option>
<option value="BZ">Belize</option>
<option value="BJ">Benin</option>
<option value="BM">Bermuda</option>
<option value="BT">Bhutan</option>
<option value="BO">Bolivia</option>
<option value="BL">Bonaire</option>
<option value="BA">Bosnia &amp; Herzegovina</option>
<option value="BW">Botswana</option>
<option value="BR">Brazil</option>
<option value="BC">British Indian Ocean Ter</option>
<option value="BN">Brunei</option>
<option value="BG">Bulgaria</option>
<option value="BF">Burkina Faso</option>
<option value="BI">Burundi</option>
<option value="KH">Cambodia</option>
<option value="CM">Cameroon</option>
<option value="CA">Canada</option>
<option value="IC">Canary Islands</option>
<option value="CV">Cape Verde</option>
<option value="KY">Cayman Islands</option>
<option value="CF">Central African Republic</option>
<option value="TD">Chad</option>
<option value="CD">Channel Islands</option>
<option value="CL">Chile</option>
<option value="CN">China</option>
<option value="CI">Christmas Island</option>
<option value="CS">Cocos Island</option>
<option value="CO">Colombia</option>
<option value="CC">Comoros</option>
<option value="CG">Congo</option>
<option value="CK">Cook Islands</option>
<option value="CR">Costa Rica</option>
<option value="CT">Cote D\'Ivoire</option>
<option value="HR">Croatia</option>
<option value="CU">Cuba</option>
<option value="CB">Curacao</option>
<option value="CY">Cyprus</option>
<option value="CZ">Czech Republic</option>
<option value="DK">Denmark</option>
<option value="DJ">Djibouti</option>
<option value="DM">Dominica</option>
<option value="DO">Dominican Republic</option>
<option value="TM">East Timor</option>
<option value="EC">Ecuador</option>
<option value="EG">Egypt</option>
<option value="SV">El Salvador</option>
<option value="GQ">Equatorial Guinea</option>
<option value="ER">Eritrea</option>
<option value="EE">Estonia</option>
<option value="ET">Ethiopia</option>
<option value="FA">Falkland Islands</option>
<option value="FO">Faroe Islands</option>
<option value="FJ">Fiji</option>
<option value="FI">Finland</option>
<option value="FR">France</option>
<option value="GF">French Guiana</option>
<option value="PF">French Polynesia</option>
<option value="FS">French Southern Ter</option>
<option value="GA">Gabon</option>
<option value="GM">Gambia</option>
<option value="GE">Georgia</option>
<option value="DE">Germany</option>
<option value="GH">Ghana</option>
<option value="GI">Gibraltar</option>
<option value="GB">Great Britain</option>
<option value="GR">Greece</option>
<option value="GL">Greenland</option>
<option value="GD">Grenada</option>
<option value="GP">Guadeloupe</option>
<option value="GU">Guam</option>
<option value="GT">Guatemala</option>
<option value="GN">Guinea</option>
<option value="GY">Guyana</option>
<option value="HT">Haiti</option>
<option value="HW">Hawaii</option>
<option value="HN">Honduras</option>
<option value="HK">Hong Kong</option>
<option value="HU">Hungary</option>
<option value="IS">Iceland</option>
<option value="IN">India</option>
<option value="ID">Indonesia</option>
<option value="IA">Iran</option>
<option value="IQ">Iraq</option>
<option value="IR">Ireland</option>
<option value="IM">Isle of Man</option>
<option value="IL">Israel</option>
<option value="IT">Italy</option>
<option value="JM">Jamaica</option>
<option value="JP">Japan</option>
<option value="JO">Jordan</option>
<option value="KZ">Kazakhstan</option>
<option value="KE">Kenya</option>
<option value="KI">Kiribati</option>
<option value="NK">Korea North</option>
<option value="KS">Korea South</option>
<option value="KW">Kuwait</option>
<option value="KG">Kyrgyzstan</option>
<option value="LA">Laos</option>
<option value="LV">Latvia</option>
<option value="LB">Lebanon</option>
<option value="LS">Lesotho</option>
<option value="LR">Liberia</option>
<option value="LY">Libya</option>
<option value="LI">Liechtenstein</option>
<option value="LT">Lithuania</option>
<option value="LU">Luxembourg</option>
<option value="MO">Macau</option>
<option value="MK">Macedonia</option>
<option value="MG">Madagascar</option>
<option value="MY">Malaysia</option>
<option value="MW">Malawi</option>
<option value="MV">Maldives</option>
<option value="ML">Mali</option>
<option value="MT">Malta</option>
<option value="MH">Marshall Islands</option>
<option value="MQ">Martinique</option>
<option value="MR">Mauritania</option>
<option value="MU">Mauritius</option>
<option value="ME">Mayotte</option>
<option value="MX">Mexico</option>
<option value="MI">Midway Islands</option>
<option value="MD">Moldova</option>
<option value="MC">Monaco</option>
<option value="MN">Mongolia</option>
<option value="MS">Montserrat</option>
<option value="MA">Morocco</option>
<option value="MZ">Mozambique</option>
<option value="MM">Myanmar</option>
<option value="NA">Nambia</option>
<option value="NU">Nauru</option>
<option value="NP">Nepal</option>
<option value="AN">Netherland Antilles</option>
<option value="NL">Netherlands (Holland, Europe)</option>
<option value="NV">Nevis</option>
<option value="NC">New Caledonia</option>
<option value="NZ">New Zealand</option>
<option value="NI">Nicaragua</option>
<option value="NE">Niger</option>
<option value="NG">Nigeria</option>
<option value="NW">Niue</option>
<option value="NF">Norfolk Island</option>
<option value="NO">Norway</option>
<option value="OM">Oman</option>
<option value="PK">Pakistan</option>
<option value="PW">Palau Island</option>
<option value="PS">Palestine</option>
<option value="PA">Panama</option>
<option value="PG">Papua New Guinea</option>
<option value="PY">Paraguay</option>
<option value="PE">Peru</option>
<option value="PH">Philippines</option>
<option value="PO">Pitcairn Island</option>
<option value="PL">Poland</option>
<option value="PT">Portugal</option>
<option value="PR">Puerto Rico</option>
<option value="QA">Qatar</option>
<option value="ME">Republic of Montenegro</option>
<option value="RS">Republic of Serbia</option>
<option value="RE">Reunion</option>
<option value="RO">Romania</option>
<option value="RU">Russia</option>
<option value="RW">Rwanda</option>
<option value="NT">St Barthelemy</option>
<option value="EU">St Eustatius</option>
<option value="HE">St Helena</option>
<option value="KN">St Kitts-Nevis</option>
<option value="LC">St Lucia</option>
<option value="MB">St Maarten</option>
<option value="PM">St Pierre &amp; Miquelon</option>
<option value="VC">St Vincent &amp; Grenadines</option>
<option value="SP">Saipan</option>
<option value="SO">Samoa</option>
<option value="AS">Samoa American</option>
<option value="SM">San Marino</option>
<option value="ST">Sao Tome &amp; Principe</option>
<option value="SA">Saudi Arabia</option>
<option value="SN">Senegal</option>
<option value="RS">Serbia</option>
<option value="SC">Seychelles</option>
<option value="SL">Sierra Leone</option>
<option value="SG">Singapore</option>
<option value="SK">Slovakia</option>
<option value="SI">Slovenia</option>
<option value="SB">Solomon Islands</option>
<option value="OI">Somalia</option>
<option value="ZA">South Africa</option>
<option value="ES">Spain</option>
<option value="LK">Sri Lanka</option>
<option value="SD">Sudan</option>
<option value="SR">Suriname</option>
<option value="SZ">Swaziland</option>
<option value="SE">Sweden</option>
<option value="CH">Switzerland</option>
<option value="SY">Syria</option>
<option value="TA">Tahiti</option>
<option value="TW">Taiwan</option>
<option value="TJ">Tajikistan</option>
<option value="TZ">Tanzania</option>
<option value="TH">Thailand</option>
<option value="TG">Togo</option>
<option value="TK">Tokelau</option>
<option value="TO">Tonga</option>
<option value="TT">Trinidad &amp; Tobago</option>
<option value="TN">Tunisia</option>
<option value="TR">Turkey</option>
<option value="TU">Turkmenistan</option>
<option value="TC">Turks &amp; Caicos Is</option>
<option value="TV">Tuvalu</option>
<option value="UG">Uganda</option>
<option value="UA">Ukraine</option>
<option value="AE">United Arab Emirates</option>
<option value="GB">United Kingdom</option>
<option value="US">United States of America</option>
<option value="UY">Uruguay</option>
<option value="UZ">Uzbekistan</option>
<option value="VU">Vanuatu</option>
<option value="VS">Vatican City State</option>
<option value="VE">Venezuela</option>
<option value="VN">Vietnam</option>
<option value="VB">Virgin Islands (Brit)</option>
<option value="VA">Virgin Islands (USA)</option>
<option value="WK">Wake Island</option>
<option value="WF">Wallis &amp; Futana Is</option>
<option value="YE">Yemen</option>
<option value="ZR">Zaire</option>
<option value="ZM">Zambia</option>
<option value="ZW">Zimbabwe</option>

$doc = new DOMDocument();
$xpath = new DOMXPath($doc);

$options = $xpath->query('*/select/option');


$values = array();
foreach ($options as $option) {

     $in = $option->getAttribute('value'); 
	 if($in=="") $in = rand(0,2);
	 $values[$in] = $option->textContent;

echo "$"."z = ".var_export($values, true).";";


You can apply same logic for more HTML elements using xpath...

Download Select2Array.php

Shoutcast V2 aacPlus AAC+ Player

Hits: 6210  

Shoutcast AAC+ V2

MP3 Radio Streams (Shoutcast/Icecast) are best for Radio Streaming with best bit-rate, but MP3 Streaming need license to broadcast source streams. Radio MP3 music globally play on all devices & platforms. MP3 live radio streaming easily work over HTML5/HTTP.

Whereas AAC+ live radio streaming work on over RTMP. It need flash streaming via RTMP.

Shoutcast V2 aacPlus AAC+ Stream in iOS (iPhone/iPod/iPad) using HTML5 Audio Player

<audio id=”radioaac” src=”” controls=”true” style=”width:200px; height:50px;”></audio>

Note: AAC+ live streaming over RTMP, and MP3 live streaming over HTML5/HTTP.

Radio Song Album Artwork Cover by YouTube

Hits: 3746  

An album cover is the front / other side of the packaging of a commercially released audio recording product, or album.

You can find online APIs or Websites where artwork available

– Amazon
– LastFM
– Soundcloud
– Apple iTune
– Google Play
– Gracenote
– Free Music Archive

And many more ….

But YouTube is the best source where you can get Album / Song Cover Image for every Title

YouTube provide gdata API to search songs as video title to get image

Deprecated Features for YouTube API v2.0

YouTube Data API (v3)<search term>


$q = isset($_REQUEST['q'])?$_REQUEST['q']:"";

//thumbnail -> sqDefault, hqDefault

// orderby -> title, relevance, published

<div id="videos"></div>
<!-- Include the latest jQuery library -->
<script src=""></script>
<script type="text/javascript">

jQuery.getJSON('<?php echo $q; ?>&max-results=1&v=2&alt=jsonc&orderby=relevance', function(data) {
    var output="<ul>";
    for (var i in {
		output+="<li><img src='" +[i].thumbnail.hqDefault + "' /></li>";
		output+="<li>" +[i].title + "</li>";
	var output="</ul>";


How you can get cover image?

song album artwork

JSON2CSV – convert json files to csv

Hits: 8342  

JSON2CSV is a python script that converts json data to a csv file.



Download above text file “json2csv.py_.txt” then rename “”

>> python “input.json” “output.csv”

JSON – input.json

“createdAt”: “2014-02-20T18:15:56.818Z”,
“fbID”: “34534534534”,
“lessonQuestions”: 5,
“lessonScore”: 2750,
“lesson_no”: 2,
“objectId”: “htmsuPr6F6”,
“updatedAt”: “2014-02-22T15:42:38.166Z”
“createdAt”: “2014-02-21T16:45:52.550Z”,
“fbID”: “100001132788807”,
“lessonQuestions”: 5,
“lessonScore”: 1100,
“lesson_no”: 3,
“objectId”: “xgmJxEyBHl”,
“updatedAt”: “2014-02-22T18:14:38.107Z”

CSV – output.csv

createdAt, fbID, lessonQuestions, lessonScore, lesson_no, objectId, updatedAt
2014-02-20T18:15:56.818Z, 34534534534, 5, 2750, 2, htmsuPr6F6, 2014-02-22T15:42:38.166Z
2014-02-21T16:45:52.550Z, 100001132788807, 5, 1100, 3, xgmJxEyBHl, 2014-02-22T18:14:38.107Z


Install Centova Cast

Hits: 4238  

Centova Cast is an internet radio stream hosting control panel. It is used for hosting radio streams and manage Radio Server like ShoutCast and IceCast. You can manage Auto DJ using Centova Cast v2 Auto DJ System plus Server Control Panel.

Centova Cast Admin

System Requirements for Centova Cast: You can install it on any Linux-based servers.

Operating system: CentOS 4/5/6, RHEL, Debian Linux
Database server: MySQL v4.1+, v5.0, v5.1, or v5.5
Streaming server: SHOUTcast v2.0, SHOUTcast v1.9, IceCast v2.x
Streaming source: ices-cc, sc_trans v2.0, ices v2, ices v0.4, ezstream 0.5.3, sc_trans 0.4.0

# apt-get install liblwp-useragent-determined-perl libconfig-tiny-perl libnet-snmp-perl libxml-simple-perl libconfig-simple-perl libmp3lame-dev libxml2-dev

# apt-get install libxml2 libvorbis-dev libogg-dev libxslt1-dev libcurl3-gnutls libogg0 libspeex1 libtheora0 libvorbis0a libxslt1.1

# wget -O
# chmod a+x ./

# ./ –shoutcast-all
# /usr/local/centovacast/sbin/update –add shoutcast1
# apt-get install ia32-libs

# ./ –icecast-all

Secure Expired MP3 File

Hits: 3207  

Secure Expired MP3 File can be used for hiding real mp3 link inside html source using base64_encode, mcrypt_encrypt, base64_decode, mcrypt_decrypt and md5. MP3 link will be expired in few seconds then it will return No Access Page to protect MP3 files to hot linked.

I was working on Secured & Expired MP3 Link in HTML5 MP3 Player. Hope you already read previous article “Amazon S3 Expiring Link”

These functions are also useful when you need to secure & expire media links …

Remote Secure Token
Secure Token Plugin with PHP
– JavaScript Encryption Library

Secure Expired MP3