Archive for the ‘Computers’ Category

ytplay – wrapper for youtube-dl.py

Wednesday, February 17th, 2010

Due to my slightly outdated computer flash is a huge problem. So, for viewing youtube videos, youtube-dl.py is a great solution. However, I wanted something more comfortable.

ytplay wraps around youtube-dl.py, it searches for a video, orders youtube-dl to get it, and starts playing it in vlc.

Usage is simple:
> ytplay foobar
will search youtube for videos about foobar and play the first one found.

The code is still quite dirty, especially the subprocess part. However, it should work, have fun!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/python
# -*- coding: utf-8 -*-
#		parser.add_option('-P', '--play', action='store_true',
#				dest='play', help='play in vlc', default=False)
 
from optparse import OptionParser
from subprocess import Popen, PIPE
from urllib2 import urlopen 
from urllib import quote_plus
from re import search, match
from os import system
 
parser = OptionParser(version='2010.02.13')
 
parser.add_option('-p', '--player',
dest='player', metavar='PROGRAM', help='media player to use', default='vlc')
 
(opts, args) = parser.parse_args()
 
if match("http://",args[0]):
	videopageurl = args[0]
else:
	searchargs = '+'.join(args)
	searchurl = "http://www.youtube.com/results?search_type=&aq=f&oq=&search_query=" + quote_plus(searchargs)
	searchresult = urlopen(searchurl).read()
	p=search(r'(watch\?[^"]*)',searchresult)
	if p==None:
		print "No Videos found"
		exit()
	videopageurl="http://www.youtube.com/" + p.group(1)
 
 
print "Starting youtube-dl for " + videopageurl
ytdl = Popen("youtube-dl.py -t -b " + videopageurl,shell=True,stdout=PIPE)
 
while not ytdl.stdout.closed:
	line = ytdl.stdout.readline()
	print line,
	if line == '': exit()
	p = search(r'\[download\] Destination: (\S*)',line)
	if p != None:
		print "Starting player: " + opts.player + " " + p.group(1)
		system(opts.player + " " + p.group(1) + " &")

filetype ytplay (1.28 kiB, 2010-02-14)


GPS plasmoid

Thursday, April 9th, 2009

Having recently acquired a bluetooth GPS receiver for as little as 20 €, and just having switched to KDE 4, i tried to combine those two, and write a little plasmoid to show the current position on the desktop.

And that is basically everything to say, enjoy the little applet.

Installation

Make sure gpsd is installed and set up properly. Also make sure the python bindings are installed.
In Ubuntu you would need to:

sudo apt-get install gpsd python-gps
sudo dpkg-reconfigure gpsd
sudo apt-get install python-plasma python-dev

After those are installed, you can proceed to install the plasmoid with plasmapkg -i.

readESM – Reading Digital Tachograph files

Tuesday, February 10th, 2009

For several years now, new trucks sold in the European union are equipped with digital tachographs, that record the driving times and replace the older chart-based mechanical tachographs.

For companies in road transport that means, although in theory they get nice data about their drivers and vehicles, in practice they have to pay a lot of money for the digital tachograph and the associated equipment, which is then used against them – the old fraud schemes no longer work, the machine cruelly gives every police officer the driving times of the last 28 days (and could give much more).

GPS Mouse in Python

Saturday, November 8th, 2008

Some months ago I aquired a cheap gps mouse (Royaltek RGM-2000, really cheap, 2 € + shipping) at ebay. My plans to use it in combination with an microcontroller and a display haven’t worked out, it is a lot of work and the garmin units do that job fine.
However, playing around with it in python lead to better results. Getting the data to google earth works nicely, and at least qlandkarte can read the generated gpx tracks.

Usage

  • Start the Program, add a parameter for the port your nmea device is attached to (/dev/ttyUSB0 is the default

kernel config based on lsmod output

Monday, October 6th, 2008

After reading about the amazing 5-seconds bootup I decided to once again compile a kernel myself. Compiling a kernel is almost trivial these days, but customizing the configuration can still be quite confusing. For example, the names of the modules in lsmod aren’t the ones you select as config options. To map them, I found some scripts in the LQWiki, but they weren’t that easily to use, and also programming in bash is just painful.

So i wrote a python variant, that takes an input config(for example your distributions config) and changes the reply to “y” for all config options if the respective module is loaded(ie. if ext3 is loaded, CONFIG_EXT3_FS=y will be set).

Feeding a screensaver from the digikam database

Monday, June 2nd, 2008

After several months of living without any screensaver, I decided it just would be nice to once again have something nice to watch and show while idling. I really like the photo slideshow that ships with windows vista, but as my laptop runs linux only that was not possible. The next best thing i found was glslideshow from the xscreensaver compilation. Like most slideshow programs, glslideshow will look into a given directory, and show files out of it in random order. However, there are downsides to that simple approach: My photo folder contains some private pictures, and also some pictures that are just ugly. So i decided to connect it to my digikam database, which was surprisingly simple.

Deleting multiple tables with a common prefix

Tuesday, March 4th, 2008
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
//Connect to the database server and select our database
$link = mysql_connect('rdbms.strato.de', 'UXXXX', 'epsilon eridani') 
	or die('Could not connect: ' . mysql_error());
mysql_select_db('DBXXXX') or die('Could not select database');
 
//get table list
$result = mysql_query("SHOW TABLES") or die(mysql_error());
 
//kill tables
$tokillprefix = "jos_";
while($row=mysql_fetch_array($result)){
 	if(substr($row[0],0,strlen($tokillprefix)) == $tokillprefix){
	 	echo "killing $row[0] <br>\n";
		mysql_query("DROP TABLE $row[0]") or die(mysql_error());
	}
}
 
?>done

Debian Sarge GNU/Linux on a Fujitsu-Siemens Amilo M7425 Laptop

Friday, February 29th, 2008

Abstract

This is my Guide to a working Installation of Debian Sarge GNU/Linux on the Amilo M7425. It may be useful for other distributions too, i used a kernel.org 2.6.10 kernel. I’m not yet finished, but it runs well enough. If you are using Suse, check out the Lugoland Amilo M7425 manual. Since I don’t use debian any more, this page wo’t be updated again.

Some notes to Ubuntu

I recently switched to ubuntu. I was impressed how fine this machine works with ubuntu, no need for a selfcompiled kernel, WLan works during the installation process. All I had to do was adding "ac", "battery", "speedstep_centrino" and "cpufreq_ondemand" to /etc/modules and activate my little speedstep script ("update-rc.d speedstep defaults").

Linux and the BenQ/Siemens S81 phone

Friday, February 29th, 2008

Abstract

I didn’t find much about using the S81 in Linux, so I decided to test it myself, so far it works quite well.

About the Phone

The S81 is a rather cheap phone, I got one for Fr 100 (~60 €), paid another Fr 30 (~20 €) for a 2-GB micro-sd card. It works as a phone, and one can receive and send sms with it. It also works as mp3-player, camera (produces rather low-quality pictures, no comparison to my rather outdated Olympus UZ-700 digicam or even my Logitech Quickcam Fusion) and camcorder(really low resolution and not the best quality alltogether), emergency light, usb storage(only with micro-sd-card inserted, and only with cable always carried along, of course) and hopefully umts modem. One can greatly increase its usability by installing java programs, the most useful addition seemed to be a mobile bookreader, see below. The display is quite nice and well to read, but touch it and you’ll leave traces. So it’s perfect to take one’s fingerprints, but hard to keep it clean and shiny.