Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Monday, October 5, 2009

Using pylucene to index audio files

Lucene is a quite efficient full-text indexing solution. I tried to use it to index my audio file tags to be able to launch mplayer or command line audio player without having to use complex and time consuming 'find' command to build playlists.

Here is a quick'n'dirty solution:


The search function is quite simple too:



A quick demo:
Indexing music database:

time ./tsearch.py index /home/fv/music/SANE /home/fv/musicindex
16701 files indexed 
Done 16702
./tsearch.py index /home/fv/music/SANE /home/fv/musicindex  21,67s user 10,18s system 3% cpu 14:14,36 total

Searching:

time ./tsearch.py search "love OR hate" /home/fv/musicindex > playlist.m3u
./tsearch.py search "love OR hate" /home/fv/musicindex  0,52s user 0,09s system 14% cpu 4,310 total

A more complex search:


time ./tsearch search "love OR hate OR (title: rain in blood AND artist: slayer)" /home/fv/musicindex > playlist.m3u
./tsearch.py search  /home/fv/musicindex  0,48s user 0,07s system 74% cpu 0,730 total

Although this code sample is not perfect but consider it more as a proof of concept than a ready to use solution.

The full code:



The next step is to clean my audio files tags by retrieving tags from Last.fm webservice and put them in the "genre" tag. Then automatically retrieve songs lyrics and index it using the same method.

Monday, September 21, 2009

Reading RSS feeds in GNU screen

As a lot of system administrator I use GNU screen most of the time.

GNU screen is a really wonderfull tool to keep your working sessions along days.

Screen can be configured to have a status line witch can display various standard format strings. A particularly useful configuration directive is the backtick directive. This directive allows to run a custom command and update the hardstatus line each time the command emit a new line.

Using this features I developped screenfeeder: an rss reader witch can display rss feed into my harstatus line.

Configuring your ~/.screenrc

Here is my hardstatus and backtick configuration:

#Run the rss reader as #42 backtick 
backtick 42 0 0 "/home/fv/.screenfeeder/screenfeeder" "/home/fv/.screenfeeder/feeds"
# CTRL+A f open the webbrowser to the current feed entry url
bind f screen -t 'rss_feed' 10 /home/fv/.screenfeeder/screenfeeder
# display the #42 backtick in the hardstatus line 
hardstatus alwayslastline "%{+b kw}%H%{kg}|%c|%42`|%{ky}%d.%m.%Y|%{kr}(load:%l)%-0=%{kw}"

Copy the screenfeeder script into ~/.screenfeeder/screenfeeder
Put your favorits feeds into ~/.screenfeeder/feeds like this (one feed per line):

http://www.openframeworks.cc/forum/rss.php
http://www.lemonde.fr/rss/une.xml
http://linuxfr.org/backend/news/rss20.rss

The script works by saving the current url into a file named ~/currenturl-. The pid of the parent process id (the current screen process id). When screenfeeder is invoked without arguments from the same screen process it calls the webborowser module to open the url stored in this file by gessing the parent process id.

As a result. When you use CRTL-a f shortcut, the browser should open the current item.


screenfeeder demo:


Screenfeeder from dopuskh3 on Vimeo.


References:
screen manual page
screenfeeder project page on github