Monday 26 March 2012

On Adolescent Coders

Warning: Rant mode engaged

It appears to me that the Open Source Software (OSS) mantle has been passed on to a gaggle of post adolescent coders with some sort of group ADD disability.

Or something.

It started with the total fiasco that was KDE4, and all the idiocy that was apparently introduced on its release.

I didn't use KDE though, so although I was aware of all the angst, it didn't directly affect me.

Now we have Gnome 3, or more accurately, Gnome Shell, which is part of the new Gnome 3.

What an abomination. You can understand why Canonical balked at presenting their users with the steaming pile that is Gnome Shell, and it is almost understandable that they decided to promote their Unity shell from the netbook remix (where it belonged, and was actually quite useful in that context),  but in the age of HD, multi-monitor setups Unity too is totally underwhelming.

Alternatives such as Mate and Cinnamon are worthwhile projects which will hopefully mature to become usable desktops but right now the state of user interfaces in the OSS sphere is totally unsatisfactory (and yes, I have tried XFCE and KDE4 and I don't like them either. I like my menu bar at the top, my task bar at the bottom and the freedom to put icons wherever the hell I please, thank you.


However, as much as it may seem otherwise, this rant is not about the sorry state of OSS desktops at all.

It is about the state of OSS video players. Specifically, VLC, Totem and XBMC.

You see, back in the old days you would get an AVI file, or maybe an MPG file, and you could open that file in one of the afore-mentioned players and life was good.

However, if the movie was in a language you were not familiar with, you had a problem. To solve that problem some bright spark came up with the idea of having a subtitles file (.srt), which was OK, if a bit cumbersome.

Or, occasionally some mentally challenged dingbat would hard code subtitles into the actual video stream and not actually mention that fact when presenting the resulting file to the general public.

I've done my fair share of shouting spittle laden expletives at people who do that I assure you.

It would be better if somehow the subtitles and the audio/video could all be encapsulated in one file, right?

Clearly this is a good idea.

While you are at it, maybe we could include separate audio tracks for other languages. You could even put in the commentary track! Just like a DVD!

So the ever resourceful guys in OSS land went to work, and gave us "containers" (initially MKV but now also the venerable AVI files) that held all this extra data in one convenient file.

Life, you would think, is good.

But no.

Having spent all this time very cleverly making all this stuff work it seems the adolescents at the wheel have decided that we must all have the results of their handiwork shoved in our faces every time we watch a movie.

This is why, when you play a movie these days, a movie that has a whole lot of nice  subtitles conveniently bundled up into the container file, it plays with the subtitles ON by default.

Oh, I can hear you now. "Well, if it such a problem for you, then you can just turn them off!"

If it were only that simple.

Yes, you can turn them off every time you start a movie and it is not that hard. It is ctrl+t if I recall.

However, I don't want to have to do that every time I watch a movie, and if I am on my media centre I don't want to have to find where my keyboard is under a cushion on the couch (or where ever) just so I can turn the goddamn subtitles off.

Again!

I just want to watch the goddam movie.

Without subtitles.

I also wouldn't mind so much if it was a simple thing to turn them off globally, although I would still contend that having them on by default is borderline retarded and only required because the ADD sufferers who implemented the subtitle functionality wanted to make damn sure you got to experience the wonder of their coding prowess, but given a method to easily and permanently turn off subtitles I could forgive the ADD sufferers and give them their 15 seconds of fame.

After all, they earned it by contributing to the OSS pool, right?

Unfortunately,  the reality is somewhat different. The sad fact is that it is far from easy to turn subtitles off by default in VLC and to a lesser degree XBMC. I have not tried it with Totem because I don't use it much, but I have noticed it behaves this way as well.

Try doing a google search for "permanently disable subtitles vlc" and you will find vast numbers of people asking how to do it with a number of proposed, convoluted, obfuscated solutions, none of which seem to work on the latest version of VLC.

I spent half an hour on trying to do that without any success.

I've found it is easier to download mkvtoolnix  and actually remove the subtitle track than it is to fucking disable it permanently in VLC.

In Xbox Media Centre things are slightly better. You can't (apparently) disable subtitles globally in XBMC via the front end, but it is, at least, possible to go and edit a configuration file in a text editor to turn them off.

How very user friendly.

The fact is there is absolutely no reason to have subtitles on by default, certainly not when the default language is set to English. Sure, if my OS was configured to use Spanish by default then you could make a case to set subtitles to on, on the assumption that I wanted to watch the typical idiocy inducing rubbish that pours out of Hollywood with only an English soundtrack.

But I am not Spanish.

The unfortunate truth here is that this is the ADD adolescents telling users "we spent all this time making this shit work, and you are damn well going to use it, whether you like it or not."

It it weren't for the god-awful mess that MS appear to be making with Windows 8 it would almost be enough to push me back to the dark side I swear.

Wednesday 21 March 2012

PHP: Create variable names from XML element names

I needed to convert an xml file into an array. You can use an element name to name a variable using this example.

        $string = "<postcode>5253</postcode>";
        $xml = new SimpleXMLElement($string);

        $varname = $xml->getName();

        ${$varname} = trim($xml);

        echo($varname." is ".${$varname}."\n");
        echo($varname." is ".$postcode."\n");
 
Output:
 
postcode is 5253
postcode is 5253 

Thursday 8 March 2012

Remove Unwanted Audio Tracks From AVI Files

If you have downloaded videos from certain sources lately, you may have noticed that it is now possible to create a video container (AVI,MKV) that includes multiple audio channels just like on a DVD.

This is a great thing because it allows people of different languages to use the same video file. Alternately it allows the directors commentary to be included.

That said, I am an English speaker, and I have never had any interest in directors commentaries so all these extra audio tracks represent unwanted data in my movie library.

Also, some files default to playing the commentary or the non English track in some players which is also mildly annoying.

So, in shuch circumstances you can use ffmpeg to remove the unnecessary tracks from an AVI file (I have not tried it for MKV, I will update this page if I do.

Things you need to install are vlc and avconv (avconv is the replacement for ffmpg which is now deprecated)

sudo apt-get install vlc libav-tools

Note: On RedHat based distributions you must install libav. ie:
yum install libav
You can see what audio tracks are available, and select them by opening the video file in vlc and looking in Audio>Audio Track.

Once you have determined which track you want to keep, you can run the file through avconv to strip the unwanted tracks. In this example I use the second map parameter to keep track 2 (ie lose track 1);

avconv -i sourcefile.avi -map 0:0 -map 0:2 -acodec copy -vcodec copy outfile.avi

And that's it, happy Linuxing (is that a word?)

Internet Mail With Postfix

Setting up an Internet mail server with postfix is pretty easy.

apt-get install postfix mailutils alpine

Choose "internet site" when asked.



You will require fully qualified domain name (FQDN) and with properly configured MX record.

You can use the "dig" command to verify your MX record. The output will include the following lines;

dig mydomain.com mx

;; ANSWER SECTION:
mydomain.com.    2857    IN    MX    10 mail.mydomain.com.

;; ADDITIONAL SECTION:
mail.mydomain.com.    2862    IN    A    123.2.101.184


Your MX record should point to the A record for your mail server as it does in the above example.


The mail server must of course be contactable from the Internet.



Now, we need to configure a few things in postfix. Edit mail.cf

sudo vi /etc/postfix/main.cf

Modify the following lines with the details shown as bold

myhostname = mydomain.com 
mydestination = mydomain.com, localhost.localdomain, localhost

If you are running behind NAT/proxy you will need to ensure that port 25 is forwarded from your router and advise postfix it is operating behind a NAT/firewall.

Add this line to the main.cf file;

proxy_interfaces = 123.2.101.184 
 
The address must be the same as the mail server IP that is shown in the ADDITIONAL SECTION from our dig command from before.
 
Restart postfix;
 
 sudo service postfix restart 

Try sending an email to an external address;

mail -s Test me@gmail.com
 
Assuming you get the mail you should reply to it.
 
You can check whether it arrives using alpine;
 
alpine
 
Select "Folder List" ("L" key) to see any messages.