Monday, June 3, 2013

Thunderbird in Linux - Strange second window problem

Linux Mint 14 Nadia  /  Mozilla Thunderbird 17.0.5  /  FireTray 0.4.5

I've had a strange problem with Thunderbird recently where a second window mysteriously appears, almost as if there were two instances of Thunderbird running, except there's not and I don't want the extra window.

I've tracked it down to a glitch with the system tray extension, it seems to be quite generic and not specific to FireTray (which is a very nice tray addon) and found a quick work around to get rid of the phantom window when it decides to make an appearance.

This should work even if you have other system tray extensions as the fix is a simple one:

  • Go to Tools -> Add-ons
  • Disable the system tray extension
  • Shut down thunderbird completely (killall thunderbird to be sure)
  • Open thunderbird
  • Enable the system tray extension


Then the problem won't reoccur for quite some time, until randomly one day, it returns..

Tuesday, November 8, 2011

mv: cannot move `./directory1' to `../directory2': Directory not empty

I wanted to move all files from one directory structure to another, for me I had an updated version of a lot of website files and I wanted to update them all in one go so I tried:

mv ./directory1/* ./directory2/

Because I have lots of files within sub-directories on both folders the mv command wouldn't play nice and kept throwing this "Directory not empty" error, even doing an "mv -f" to force overrides didn't work..

After search around people have come up with elaborate bash scripts to do the task, and I like to throw a bash script together every now and again but in this situation it's really not necessary, we just need to use rsync:

rsync -avh ./directory2/ ./directory1/

That rsync command will override all the files in directory1 with the files in directory2 and recurse through all sub-directories, it will override them regardless if they're older/newer/different sized etc so do a backup of your original directory before running the command

Rsync is a great tool and you can do so much more than just synchronising local folders, for more advanced options (like only overwriting newer files etc) check out the man page for rsync here: http://linux.die.net/man/1/rsync

Hope this helps somebody out.

Monday, April 25, 2011

Converting flash video to mpg using ffmpeg in linux ubuntu

Converting flash video to mpg using ffmpeg in linux ubuntu.. I posted a script recently to extract flash videos from your web browsers cache in linux, sometimes flvs can be missing parts that stop you from skipping forward etc but ffmpeg converts most video formats easily so we just need to apt-get it:
sudo apt-get install ffmpeg
I'm not going to into too much depth with ffmpeg here other than to convert an flv to an mpg, I recommend checking out the ffmpeg documentation for anything specific, you can also google it from here:

Another option is, if your looking for the GUI way to convert videos in Linux, to use WinFF which you easily install by adding a repository in ubuntu: http://code.google.com/p/winff/wiki/UbuntuInstallation

What I wanted to be able to do was convert all of the flv's I had in a directory to mpg's, to do this using ffmpeg simply:
ffmpeg -i input.flv output.mpg
ffmpeg's clever enough to figure the rest out for itself, there are many options you can us, I decided just to set the frame size to 800x600 for simplicity (-s 800x600) so my final ffmpeg command was:
ffmpeg -i input.flv -s 800x600 output.mpg
In another post I posted a script to extract flash videos from the web browser cache and put them into a separate directory for storage (click here to read this post) so this script is an extension of that script to convert all flv's into mpeg and put them into a video directory:
#!/bin/bash
INPUTDIR=~/Videos/flvs
OUTPUTDIR=~/Videos

for f in $INPUTDIR/*.flv
do
    a=$(basename $f | cut -f1 -d '.')
    ffmpeg -i "$f" -s 800x600 "$OUTPUTDIR/$a.mpg"
done
This may take some time to complete depending on how many flash flv files you have the input directory.. I generally use my cache flash extractor bash script then sift through the flvs directory deleting what I don't want, then convert the videos I want to keep.

If you find it useful let me know..

Thursday, April 21, 2011

Creating an ISO of a DVD in Linux Ubuntu and mounting it as a drive

I'm going to create an ISO of a DVD and mount the .iso file so it appears as a DVD drive, I'll be doing this in Linux Ubuntu 10.

There's many reasons why you might want to do this, I've got some DVD's that I don't want to lose and by this time we've all reaslised that CD's and DVD's are almost as unreliable as floppy disks were.. that ever dreaded sound of the drive choking on your favourite movie.. lost forever, or having to wait for it to arrive from Amazon

We're going to create the ISO with Brasero which comes with Ubuntu, if it's not installed (Applications -> Sound & Video -> Brasero Disc Burner) then just apt-get it:
sudo apt-get install brasero
With brasero it's easy to either copy a CD/DVD or create an ISO of it however it didn't work for me out of the box due to a missing library:
Please install the following manually and try again:
libdvdcss.so.2 (library).
To fix this we need to add the medibuntu repository:
sudo wget --output-document=/etc/apt/sources.list.d/medibuntu.list http://www.medibuntu.org/sources.list.d/$(lsb_release -cs).list && sudo apt-get --quiet update && sudo apt-get --yes --quiet --allow-unauthenticated install medibuntu-keyring && sudo apt-get --quiet update
The medibuntu is a very useful repository that contains packages excluded from the main ubuntu repository's for legal reasons.

Then we're able to install the missing library we need:
sudo apt-get install libdvdcss2
Open up brasero and select "Disk Copy" under "Create a new Project" on the left, the "Copy CD/DVD" dialog will appear, select "Image File" from the "Select a disc to write to" drop down menu, click the "Properties" button to change the output file location and click "Create Image".

Depending on the size of the CD/DVD it may take some time to create the image.

Once it's complete you can mount the ISO of the DVD, remove the DVD from the drive and watch it direct from the hard drive.. it also improves speed when converting a DVD to a compressed video format which I'll cover in the next post, for now let's mount the iso as a drive.

To do this we mount the ISO as a loop device, but first we must create a directory to mount it to:
sudo mkdir -p /mnt/iso
 Then mount it:
sudo mount -o loop mydvd.iso /mnt/iso
The "Open DVD from folder" option in SMPlayer works perfectly and of course you can now burn this ISO to a blank DVD using Brasero.

Tuesday, April 19, 2011

Connecting a nokia n70 to Ubuntu 10 via usb

I've got some photos stored on a nokia n70 that I need to download to my laptop running Ubuntu 10, I have the usb cable ready so what happens when I connect it?

The Network Manager picks it up straight away as a mobile broadband device so it's looking good, but I don't need to use the phone to connect to the internet.. my Huawei usb dongle works straight out of the box with Ubuntu

To upload/download files to/from the Nokia n70 we need to use obexftp, it comes with a gui version called obextool so let's install them both:

sudo apt-get install obextool obexftp

I ran obextool straight away but it didn't work out of the box with the nokia for some reason.. so let's use obexftp to see if it can pick up the phone:

sudo obexftp -u
Found 2 USB OBEX interfaces


0 (Manufacturer: Nokia Product: Nokia N70 Serial: (null) Interface description: SYNCML-SYNC)
1 (Manufacturer: Nokia Product: Nokia N70 Serial: (null) Interface description: PC Suite Services)


Use '-u interface_number' to connect

It's found the phone, let's see if it can connect and list the drives on the phone (internal and memory card):

sudo obexftp -u 1 -l
Connecting..\done
Tried to connect for 16ms
Receiving "(null)"...|<?xml version="1.0"?>
<folder-listing version="1.0">
   <folder name="C:" user-perm="RW" mem-type="DEV" label="Phone memory"/>
   <folder name="E:" user-perm="RW" mem-type="MMC" label="Memory card"/>
</folder-listing>
Disconnecting../done

Success!

The obextool gui had trouble connecting before, so let's tell it how to connect:

sudo obextool --obexcmd "obexftp -u 1"

I can now download the images from my nokia n70 to my Ubuntu desktop:




I hope somebody finds this useful.. please make a comment if you have any questions

Friday, April 1, 2011

Saving watched online videos in linux, firefox cache flash extractor bash script

I recently upgraded to Ubuntu 10.10 and needed to rewrite a couple of useful scripts I use.

Here's a simplified version of a bash script that reads your firefox cache, finds flash files over a certain size, saves them in directory and opens the directory with nautilus to browse the extracted videos/flash files:

#!/bin/bash
# flvcache script

CACHE=~/.mozilla/firefox/xxxxxxxx.default/Cache
OUTPUTDIR=~/Videos/flvs
MINFILESIZE=2M

for f in `find $CACHE -size +$MINFILESIZE`
do
    a=$(file $f | cut -f2 -d ' ')
    o=$(basename $f)
    if [ "$a" = "Macromedia" ]
        then
            cp "$f" "$OUTPUTDIR/$o"
    fi
done

nautilus  "$OUTPUTDIR"&

Remember to chmod 755 the file so you can execute it from the command line.

Change the variable CACHE to your firefox cache location, it'll be somewhere like: ~/.mozilla/firefox/xxxxxxxx.default/Cache

Create a directory to save them into, I chose:
mkdir ~/Videos/flvs

I hope somebody finds this useful.

The script is presented in a simplified format to show bash scripting, you can see how to: use a for loop using bash, load output from external programs into a variable using bash and use an if statement using bash.

Saturday, March 27, 2010

PHP, foreign language dates and problems with setlocale()

I recently came across an issue when trying to display the date in a foreign language using PHP.

I was working on a web development project for a Spanish client which required that the date, or more specifically the day and month names, be displayed in Spanish.

A quick Google search or look through the php manual will point you to the setlocale() function.

Great, you change the locale to match your desired language and the date will be outputted accordingly, here's an example:

setlocale(LC_TIME,"es_ES.utf8");
echo strftime("%A, %B %d", time());

And the output should be:

sábado, marzo 27

For the majority of people this will work perfectly and is the ideal solution, but for some however, including myself, it would always display the date in English regardless.

Something to make sure of is that the locale is available on your system, to see what locales are available/installed on your system, use the following command:

-bash-3.2$ locale -a

If it's still not working and the locale you need is available/installed then the logical route at this point would be to determine if it's a problem with the PHP setup, or the system itself:

-bash-3.2$ export LC_TIME="es_ES.utf8"
-bash-3.2$ date
sáb mar 27 14:16:39 GMT 2010

The system's date function works without a problem but for some reason the PHP solution doesn't.

This seems to be a bug in certain versions of PHP and/or on certain flavours of Linux, at least that's what I can gather from searching on Google and finding many people in the same situation. If anybody finds out exactly what the cause is, please post a comment at the bottom of the page as I'm sure there are many people who would greatly appreciate it, including myself.

If your uploading your script to a web hosting server then you probably won't have the control you need to fix any configuration problem so we're in need of a workaround solution.

A quick fix that a lot of people have posted solutions for is to simply create an array of the days or months in that language:

$day_names=array("Domingo", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado");
echo $day_names[date("w")];

Which works fine but I wanted a solution I could reuse easily in the future without having to create an array of the days and months for every language I needed.

So I wrote a quick function to interface with the linux date command.

It sets the locale variable using putenv(), cleans up the date format so there's no need for backslashes, calls date with the arguments specified and returns the output.

This solution is not compatible with Windows however functions similarly to strftime(), here's the code:

function _date($format,$locale="en_GB.utf8",$date='') {
putenv("LC_TIME=$locale");
$cmd="date +" . preg_replace("/([^a-z0-9_%])/i","\\\\$1",$format);
if ($date!="") { $cmd.=" --date='$date'"; }
$p=popen($cmd,"r");
$date=fread($p,1024);
pclose($p);
return $date;
}

Here's an example of it working for English, Spanish, French, German and Russian:

echo _date("%A, %B %d","en_GB.utf8","2010-01-01 12:00");
echo _date("%A, %B %d","es_ES.utf8","2010-01-01 12:00");
echo _date("%A, %B %d","fr_FR.utf8","2010-01-01 12:00");
echo _date("%A, %B %d","de_DE.utf8","2010-01-01 12:00");
echo _date("%A, %B %d","ru_RU.utf8","2010-01-01 12:00");

And here's the output:

Friday, January 01
viernes, enero 01
vendredi, janvier 01
Freitag, Januar 01
Пятница, Январь 01

For information on the parameters to enter for the date format/first argument see the strftime() manual page here: http://php.net/manual/en/function.strftime.php or type "man date" in your terminal.

Please feel free to use the function however you wish and any links back to this page and comments are greatly appreciated.