Thursday, December 31, 2015

Youtube API v3 - Get upload progress while uploading a video to YouTube

If you want to use YouTube API v3 from PHP, you will probably want to retrieve some kind of upload progress metric while your video is being transferred to YouTube.
If you check YouTube API documentation , especially videos.insert() function, you'll probably be disappointed. JavaScript version of file upload fully supports the upload progress retrieval, but PHP example has no notion of anything similar.

However, we can do something about it. Here's an idea:

If you carefully check the PHP example, you will see that current progress is easily obtainable in the while loop which sends your video chunk by chunk. We should grab this information, store it to a database or a file, and we're good to go.

For example, our loop might look like this:


 while (!$status && !feof($handle)) {
            $chunk = fread($handle, $chunkSizeBytes);

            $progress= $media->getProgress();

            $progress = $progress / ( $filesize * 1.0) * 100;

            $db->ExecuteUpdate("UPDATE progress_info SET Val= ?  WHERE KeyX=? AND UID=? " , array($progress , "progress" ,$UID ));

            $status = $media->nextChunk($chunk);


Now, if we want to retrieve current video's upload progress, we just query our database using AJAX. AJAX opens a tiny PHP script which reads the current video upload information from database.
Here's a sample script:


$UID = $reqHelper->GetParam("uid");

$res = $db->ExecuteSelect("SELECT * FROM progress_info WHERE KeyX=? AND UID=?" , array("progress" , $UID ) );

$row = $db->FetchRow($res);

$val = $row['Val'];

echo round($val,2) .  "%";


And that's it!

If you need help coding this, just let me know, I will throw in some sample code.

Sunday, December 27, 2015

XRDP - Ubuntu 12 , HR (Croatian) keyboard mappings

Here's a great help for anyone having trouble with Croatian (HR) keyboard layout when using XRDP in Ubuntu:

Basically, the author successfuly create km-041a.ini map for Croatian language and shared it with the rest of world! Thank you Tomislav!

Here's a mirror of the original author's files (you can find them on the link above as well):

Ubuntu 12.04 - Fix wrong keyboard layout when logged in via XRDP

If you are stuck with wrong keyboard layout when logged in to your Ubuntu machine using Remote Desktop, here's what you can try.

Login locally to your Ubuntu (not using XRDP).
Open console.

1. Run setxkbmap -model pc105 -layout no
Note: Replace "no" with your layout code

2. Run sudo xrdp-genkeymap /etc/xrdp/km-0414.ini
Note: Replace "km-0414.ini" with your numerical layout code (check list below)

3. Restart XRDP service via sudo service xrdp restart

4. Try to login again via RDP

In this test case, we have used km-041a.ini file which belongs to Norwegian keyboard layout.
You need to find the specific code for your keyboard layout. The list is here:

0x0436 af Afrikaans
0x041C sq Albanian
0x0001 ar Arabic
0x0401 ar-sa Arabic (Saudi Arabia)
0x0801 ar-iq Arabic (Iraq)
0x0C01 ar-eg Arabic (Egypt)
0x1001 ar-ly Arabic (Libya)
0x1401 ar-dz Arabic (Algeria)
0x1801 ar-ma Arabic (Morocco)
0x1C01 ar-tn Arabic (Tunisia)
0x2001 ar-om Arabic (Oman)
0x2401 ar-ye Arabic (Yemen)
0x2801 ar-sy Arabic (Syria)
0x2C01 ar-jo Arabic (Jordan)
0x3001 ar-lb Arabic (Lebanon)
0x3401 ar-kw Arabic (Kuwait)
0x3801 ar-ae Arabic (U.A.E.)
0x3C01 ar-bh Arabic (Bahrain)
0x4001 ar-qa Arabic (Qatar)
0x042D eu Basque
0x0402 bg Bulgarian
0x0423 be Belarusian
0x0403 ca Catalan
0x0004 zh Chinese
0x0404 zh-tw Chinese (Taiwan)
0x0804 zh-cn Chinese (China)
0x0C04 zh-hk Chinese (Hong Kong SAR)
0x1004 zh-sg Chinese (Singapore)
0x041A hr Croatian
0x0405 cs Czech
0x0406 da Danish
0x0413 nl Dutch (Netherlands)
0x0813 nl-be Dutch (Belgium)
0x0009 en English
0x0409 en-us English (United States)
0x0809 en-gb English (United Kingdom)
0x0C09 en-au English (Australia)
0x1009 en-ca English (Canada)
0x1409 en-nz English (New Zealand)
0x1809 en-ie English (Ireland)
0x1C09 en-za English (South Africa)
0x2009 en-jm English (Jamaica)
0x2809 en-bz English (Belize)
0x2C09 en-tt English (Trinidad)
0x0425 et Estonian
0x0438 fo Faeroese
0x0429 fa Farsi
0x040B fi Finnish
0x040C fr French (France)
0x080C fr-be French (Belgium)
0x0C0C fr-ca French (Canada)
0x100C fr-ch French (Switzerland)
0x140C fr-lu French (Luxembourg)
0x043C gd Gaelic
0x0407 de German (Germany)
0x0807 de-ch German (Switzerland)
0x0C07 de-at German (Austria)
0x1007 de-lu German (Luxembourg)
0x1407 de-li German (Liechtenstein)
0x0408 el Greek
0x040D he Hebrew
0x0439 hi Hindi
0x040E hu Hungarian
0x040F is Icelandic
0x0421 in Indonesian
0x0410 it Italian (Italy)
0x0810 it-ch Italian (Switzerland)
0x0411 ja Japanese
0x0412 ko Korean
0x0426 lv Latvian
0x0427 lt Lithuanian
0x042F mk FYRO Macedonian
0x043E ms Malay (Malaysia)
0x043A mt Maltese
0x0414 no Norwegian (Bokmal)
0x0814 no Norwegian (Nynorsk)
0x0415 pl Polish
0x0416 pt-br Portuguese (Brazil)
0x0816 pt Portuguese (Portugal)
0x0417 rm Rhaeto-Romanic
0x0418 ro Romanian
0x0818 ro-mo Romanian (Moldova)
0x0419 ru Russian
0x0819 ru-mo Russian (Moldova)
0x0C1A sr Serbian (Cyrillic)
0x081A sr Serbian (Latin)
0x041B sk Slovak
0x0424 sl Slovenian
0x042E sb Sorbian
0x040A es Spanish (Traditional Sort)
0x080A es-mx Spanish (Mexico)
0x0C0A es Spanish (International Sort)
0x100A es-gt Spanish (Guatemala)
0x140A es-cr Spanish (Costa Rica)
0x180A es-pa Spanish (Panama)
0x1C0A es-do Spanish (Dominican Republic)
0x200A es-ve Spanish (Venezuela)
0x240A es-co Spanish (Colombia)
0x280A es-pe Spanish (Peru)
0x2C0A es-ar Spanish (Argentina)
0x300A es-ec Spanish (Ecuador)
0x340A es-cl Spanish (Chile)
0x380A es-uy Spanish (Uruguay)
0x3C0A es-py Spanish (Paraguay)
0x400A es-bo Spanish (Bolivia)
0x440A es-sv Spanish (El Salvador)
0x480A es-hn Spanish (Honduras)
0x4C0A es-ni Spanish (Nicaragua)
0x500A es-pr Spanish (Puerto Rico)
0x0430 sx Sutu
0x041D sv Swedish
0x081D sv-fi Swedish (Finland)
0x041E th Thai
0x0431 ts Tsonga
0x0432 tn Tswana
0x041F tr Turkish
0x0422 uk Ukrainian
0x0420 ur Urdu
0x042A vi Vietnamese
0x0434 xh Xhosa
0x043D ji Yiddish
0x0435 zu Zulu

PSR-1 and PSR-2 coding standards for PHP

Visual aspects of code play a significant role in raising or drowning developer's productivity. In case that there's too much clutte...