Monday, September 29, 2008

-"We're sorry, this video is no longer available" YouTube downloader

More often than not, when the planets and moons aren't oriented in the right manner, I get the dreaded "We're sorry, this video is no longer available" from YouTube. I know that the video is certainly NOT "no longer available" because its clearly viewable by other people.

Fortunately in the linux world, there is this little python utility called youtube-dl which can be run from the command line to download any YouTube file. So when you get this error, copy the URL of the YouTube file, and do this:

# sudo apt-get install youtube-dl
# youtube-dl http://www.youtube.com/watch?v=videofile001

if it doesn't work, it will complain with this verbose error:

Retrieving video webpage... done.
Extracting URL "t" parameter... done.
Requesting video file... failed.
Error: unable to download video data.
Try again several times. It may be a temporary problem.
Other typical problems:

* Video no longer exists.
* Video requires age confirmation but you did not provide an account.
* You provided the account data, but it is not valid.
* The connection was cut suddenly for some reason.
* YouTube changed their system, and the program no longer works.

Try to confirm you are able to view the video using a web browser.
Use the same video URL and account information, if needed, with this program.
When using a proxy, make sure http_proxy has http://host:port format.
Try again several times and contact me if the problem persists.

You can then repeat this process over and over again, until it succeeds. Unfortunately this requires effort. And we computer users hate expending any unnecessary energy if possible. After all, focusing on the terminal, clicking the up arrow and hitting return is so so tedious.

So I wrote a little bash script to complement youtube-dl as it sports a few extra features:
  1. It will automatically try and retry to youtube-download the file until it is successful (thanks to $?)
  2. It will rename the resultant flv video filename to the current date and time, instead of the random garbage filename. (using date +%F...)
  3. It terminates gracefully when the user hits Ctrl-C (by setting a trap ...)
  4. It promotes world peace by waiting a few seconds before trying again (sleep is always good)
And here it is:

#!/bin/bash

i=1
fname=`date +%F-%H%M`

result=1

while [ $result = 1 ]; do
echo Attempt $i "$fname".flv
trap "echo User killing the download; exit" INT TERM
youtube-dl $1 -o "$fname".flv
result=$?
let i=i+1
if [ $result = 1 ]; then
sleep 10
fi
done

Try it out. The most I had to wait was 24 attempts. Thats 46 keypresses saved!


yk.

Wednesday, September 17, 2008

Rukun Negara - have you read it? really?

This is the Rukun Negara which was drummed into our little skulls when we were young:
  • BELIEF IN GOD
  • LOYALTY TO KING AND COUNTRY
  • UPHOLDING THE CONSTITUTION
  • RULE OF LAW
  • GOOD BEHAVIOUR AND MORALITY
Of course, when I first knew about it, it was in Malay, and I never really found out what the long and grand words like 'kesusilaan', 'keluruhan' and 'kedaulatan' (with regards to undangs) really meant. Even if I did, would you expect an 7 year old to differentiate between the Constitution and the Rule of Law?

However it was only recently that I found out that there was more to this story than these bullet points. The 'Rukun Negara' that we have learnt aren't actually the real principles (rukuns). They are merely tactical means to fulfill a grander plan; and the real National Principles are as follows:
Our nation, Malaysia, being dedicated :
  • to achieving a greater unity of all her peoples;
  • to maintaining a democratic way of life;
  • to creating a just society in which the wealth of the nation shall be equitably shared;
  • to ensuring a liberal approach to her rich and diverse cultural traditions;
  • to building a progressive society which shall be oriented to modern science and technology;
I really like, and can related to these original Rukuns; Unity, Democracy, a Just society, Equitable Shared Wealth, Liberal, Celebrating the diverse Cultures and Traditions, Progressive Society, and orientation towards Science and Tech! Who cannot like that?

This was written in 1970, just after the May13th disaster. It was intended to correct the path of our Nations growth. And yet, after almost 40 years on, we can see how the real Rukun Negara has been "forgotten", and this is clear with the "progress" of our country and society.

We see families split because of religulous body snatchers, money politics, judicial crisis, abuse of the NEP to cronies, fanaticism, restriction of traditions, regressive societies and a poorly implemented science roadmap.

I think its time we really understand the original principles of Rukun Negara, rather than the abstract version which we have all grown to ignore.

Please re-read your Rukun Negara, and help make Malaysia a better place.


yk
===

The Malay version:

BAHAWASANYA NEGARA KITA MALAYSIA mendukung cita-cita hendak :

  • mencapai perpaduan yang lebih erat di kalangan seluruh masyarakatnya ;
  • memelihara satu cara hidup demokratik ;
  • mencipta satu masyarakat adil di mana kemakmuran Negara akan dapat dinikmati bersama secara adil dan saksama ;
  • menjamin satu cara liberal terhadap tradisi-tradisi kebudayaannya yang kaya dan berbagai corak ; dan
  • membina satu masyarakat progresif yang akan menggunakan sains dan teknologi moden.

MAKA KAMI, rakyat Malaysia, berikrar akan menumpukan seluruh tenaga dan usaha kami untuk mencapai cita-cita tersebut berdasarkan atas prinsip-prinsip yang berikut :

  • KEPERCAYAAN KEPADA TUHAN
  • KESETIAAN KEPADA RAJA DAN NEGARA
  • KELUHURAN PERLEMBAGAAN
  • KEDAULATAN UNDANG-UNDANG
  • KESOPANAN DAN KESUSILAAN

Tuesday, September 16, 2008

Long Advertisements

Not many companies can afford super long advertisements nowadays. Its costs alot for airtime. Plus you really need compelling content to keep the audience interested.

This 2 minute advertisement from Nike which I saw prior to a movie which I think is great:



This 4 and a half minute advertisement from Microsoft, which was just launched, and is #2 in a series of ten, which I think is utter crap:



One makes you want to watch more to see how more interesting the ad can become (and it does!) while the other just makes you want to watch more to see how bad it can become (and that it does too.) One inspires and makes you worship the brand, while the other just makes you go "... meh?" One is young and exciting while the other is old, drab, out-of-touch and really patronising ("Traffic jam in my garage" - ouch!) One makes full use of the celebrities featured, while the other abuses the has-beens of celebrities. One is tight, well structured and coherent, while the other is rambling, confusing and irritating.

Surely with all the money in the world, they could have done better?

yk.

Monday, September 15, 2008

Copy and Pasting between a remote Windows desktop and Linux client

If you need to Copy & Paste between a remote Windows desktop and your Linux workstation, use "Terminal Server Client" to access the host Windows XP/Server with "Remote Desktop" enabled.

In the Terminal Server Client, make sure that the Protocol selected is RDPv5. The default is RDP, which doesn't have the bells & whistles.

Once selected, copy and pasting is fully integrated between machines!

yk.

Monday, September 08, 2008

Lotus Notes 8 and wrestling with attachments in Linux

A gripe about opening attachments in Lotus Notes 8 is that LN will fail silently, leaving the user guessing whether things are happening or not. If a user double clicks on an attachment, a dialog will pop up requesting if the user wants to "Open", "Edit", "View", "Save" or "Cancel".

Clicking on View for me gives a strange error: "Unable to create view: Device is disposed" and gives a whole load of eclipse errors in the details. I dont have the time to figure that one out.

So the next best thing is to "Open" the attachment. However that doesn't do anything, and LN fails to report that something has failed. The solution for this however is available here: "IBM - Attachments do not open from Lotus Notes for Linux Client when Open, Edit, or View is chosen in the 'Open Attachment' dialog" The trick is to remove IBM's own "openwith" program with whichever desktop manager you happen to install.

# sudo mv /opt/ibm/lotus/notes/openwith /opt/ibm/lotus/notes/openwith.old
# sudo ln -s $(which kde-open) /opt/ibm/lotus/notes/openwith


It works, but its amazing that we have to jump through these hoops just to open attachments!

yk

Thursday, September 04, 2008

Getting Aztech UM-3100 USB Modem to work on CentOS 5

Our old Hylafax external modems decided to kick the bucket over the weekend, and it was an opportunity to refresh the hardware. They lasted a good 9 years (or more!) and I dont think they make them anymore.

Additionally they had to be powered by large adaptors, which took up way too much room. So a good solution would be to use some USB modems; small, cheap, USB powered and easily replaceable.

We chose Aztech UM-3100 USB Modem. Relatively cheap at about RM70, we thought it would be a great solution. So I plugged it into the machine, and this was the dmesg output:

usb 1-2: new full speed USB device using uhci_hcd and address 2
usb 1-2: device descriptor read/64, error -71
usb 1-2: device descriptor read/64, error -71
usb 1-2: new full speed USB device using uhci_hcd and address 3
usb 1-2: device descriptor read/64, error -71
usb 1-2: device descriptor read/64, error -71
usb 1-2: new full speed USB device using uhci_hcd and address 4
usb 1-2: device not accepting address 4, error -71
usb 1-2: new full speed USB device using uhci_hcd and address 5
usb 1-2: configuration #1 chosen from 2 choices
drivers/usb/class/cdc-acm.c: Zero length descriptor references

cdc_acm: probe of 1-2:1.0 failed with error -22
usbcore: registered new driver cdc_acm
drivers/usb/class/cdc-acm.c: v0.25:USB Abstract Control Model driver for USB modems and ISDN adapters


So not very good news to start off the day. This usb-modem isn't supported out of the box, fortunately it isn't too much a problem, but it does require a recompilation of the cdc-acm (USB Communication Device Class definition - Abstract Control Module). Here is a brief lowdown on how to get the Aztech modem recognised in CentOS 5.0.

Prepping the system for module compilation

First, we need to bring down the linux kernel source.

# wget -c ftp://ftp.redhat.com/pub/redhat/linux/enterprise/5Server/en/os/SRPMS/kernel-2.6.18-8.1.8.el5.src.rpm
Length: 48176889 (46M)
8% [==> ] 4,018,200 124.1K/s eta 7m 27s

It took only about 7 minutes to download. A "rpm -hiv" extracted the sources in /usr/src/redhat. You will then need to extract the source from redhats patches by doing this:

# rpmbuild -bp --target=$(uname -m) /usr/src/redhat/SPECS/kernel-2.6.spec

which should recreate the kernel source in /usr/src/redhat/BUILD/kernel-2.6.18/linux-2.6.18.i686. Copy your config from the /boot directory to this directory

# cp /boot/config-`uname -r` ./.config

Now you are ready to compile the entire kernel ... if you want to. For me, I just want to compile the usb modem module, and not need to wait for the entire compilation process. But first, the modifications.

Adding support for the modem.

This ubuntu forum post "Shiro/Conexant (Rockwell) RD02-D400/Aztech UM3100 USB 56K Modem" provides the information to add support for the Aztech modem. First of all, we need to make sure that the ID as reported by lsusb is matches our modifications. To do so, type this:

# lsusb
Bus 001 Device 009: ID 0572:1328 Conexant Systems (Rockwell), Inc.


You will see that its 0x0572, 0x1328. This is what we will use in our modification. Modify the cdc-acm.c file:

# nano drivers/usb/class/cdc-acm.c

scroll down about 97%... put this in similar place, next to all the other devices
{ USB_DEVICE(0x0572, 0x1328), /* Aztech UM-3100 */
.driver_info = NO_UNION_NORMAL, /* has no union descriptor */
},
Save, and that's all with the source code modification. No big deal.

Compiling the specific module.

Instead of having to build the kernel and all the modules, we can tell 'make' to build from specific directories. First, you will have to compile some scripts which are used for MODPOST, which is important to make the .ko module files.

# make SUBDIRS=scripts/mod/
WARNING: Symbol version dump /usr/src/redhat/BUILD/kernel-2.6.18/linux-2.6.18.i686/Module.symvers
is missing; modules will have no dependencies and modversions.

CC scripts/mod/empty.o
HOSTCC scripts/mod/mk_elfconfig
MKELF scripts/mod/elfconfig.h
HOSTCC scripts/mod/file2alias.o
HOSTCC scripts/mod/modpost.o
HOSTCC scripts/mod/sumversion.o
HOSTLD scripts/mod/modpost
Building modules, stage 2.
MODPOST


Then you can actually build the modules which are of particular interest to you, in this case "drivers/usb/class"

# make SUBDIRS=drivers/usb/class modules
WARNING: Symbol version dump /usr/src/redhat/BUILD/kernel-2.6.18/linux-2.6.18.i686/Module.symvers
is missing; modules will have no dependencies and modversions.
Building modules, stage 2.
MODPOST
CC drivers/usb/class/cdc-acm.mod.o
LD [M] drivers/usb/class/cdc-acm.ko
CC drivers/usb/class/usblp.mod.o
LD [M] drivers/usb/class/usblp.ko


The file which you need is drivers/usb/class/cdc-acm.ko so just copy this to the real modules directory of your running kernel.

# cp drivers/usb/class/cdc-acm.ko /lib/modules/2.6.18-8.el5/kernel/drivers/usb/class

Loading up the new module

Unload the module if it was loaded before:

# rmmod cdc_acm
ERROR: Module cdc_acm does not exist in /proc/modules


And load up the new one

# insmod cdc_acm

To check that its there:

# lsmod |grep cdc
cdc_acm 15136 0


And now, plug in the Aztech modem, and see what happens:

# dmesg
cdc_acm: no version for "struct_module" found: kernel tainted.
cdc_acm 1-2:1.0: ttyACM0: USB ACM device
usbcore: registered new driver cdc_acm
drivers/usb/class/cdc-acm.c: v0.25:USB Abstract Control Model driver for USB modems and ISDN adapters


Congratulations, it looks like its been recognised as ttyACM0

Testing the modem

Make sure you have the 'cu' utility installed. It usually comes in the 'uucp' package:
# yum install uucp
Once 'cu' is available, use '-l' to speak directly to the line.
# cu -l ttyACM0
Connected.
You can then reset the phone, and try to call out.
atz
OK
atdt9,012xxxxxxx
(9 is to get a dialtone from my PABX, and the comma is to wait).
Also test the modems ability to auto pickup after 1 ring with this command
ats0=1
However Hylafax controls the pickup process, so make sure this is not set. Reset the modem with this:
atz
And quit from 'cu' with this tilda command:
~.
Disconnected
Conclusion

Your Aztech modem should be recognised by the system even after a reboot (test it, its the only reboot you'll need to do). You can now plug in more USB modems to cater for your Fax server's needs.

yk.

Mutt - forwarding attachments automatically

Some little tricks with mutt again. By default mutt doesn't forward MIME attachments in the email, and it previously involved a laborious process of saving each file (in the current directory) and reattaching the file (from the users mail directory, which involves traversing the directory structure). So a quick google solves this issue entitled "How do I forward a message including attachments?"

In your ~/.muttrc file (create it if it isn't there already), add these two settings:
 set mime_forward=yes
set mime_forward_rest=yes
Done. Less hassle.

yk.

Tuesday, September 02, 2008

Woah, buddy!

Check out these figures:

That looks like a series of numbers growing exponentially and spiralling out of control. I wonder what the deficits figures are?

yk.