Tag Archives: Tool

New Version of bib2tpl

Last weekend, I published a new version of bib2tpl, a PHP class to convert BibTeX to anything I wrote a while ago. There certainly were some bumps to iron out; these are the major changes made:

  • Entry filtering now works on all fields.
  • Templates can contain multiple occurrences of group and entry subtemplates now.
  • Condition tags can perform more detailed comparisons now.
  • Improved control over entry ordering.
  • Grouping tags are no longer necessary if grouping is turned off.
  • It is now possible to reuse parsed BibTeX for multiple conversions.
  • @entryid@ has been removed; use @entrykey@ instead, which is now guaranteed to be unique.

You can find a more complete list of changes here, and more information on bib2tpl here.

Coding Scala with Geany and SBT

When I started programming in Scala I was naturally looking for a suitable IDE. Due to former experience and preference, I disregarded Eclipse and tried Netbeans with its Scala plugin but could not get it running properly. I had more luck with IntelliJ IDEA, that is it worked. But it is performing sluggishly and has a lot of bugs. In particular, many compiler errors are not found by IDEA, and some things it marks as errors are none. Scala’s complex type system is not all well implemented, so syntax completion is no help, either. That the Scala compiler itself runs at turtle speed was merely the last drop in my barrel of discomfort. As it was, working productively was impossible. Therefore, I decided to switch to a regular editor and simple-build-tool, something I saw mentioned everywhere people asked for good Scala IDEs. Read more »

Control Pulseaudio from Shell

As you know I mainly use Fluxbox on a minimal Ubuntu installation without access to all the every-day functionality provided by panel applets in Gnome, including volume control. Therefore, I have been using pavucontrol for controlling Pulseaudio. It is a really nice application that gives you very finegrained control, for instance over which application should be how loud. Lately I have been annoyed with opening a whole application just for the sake of adjusting volume a little bit, so I set out to find a way to control it via shell. Turns out there is no convenient interface to pulseaudio at all, leaving me to script something together, this time in Ruby. It uses a very unwieldy interface to Pulseaudio named pacmd, contained in Ubuntu package pulseaudio-utils.

def current
  c = IO::popen("pacmd \"list-sinks\" | grep volume | head -1").readlines[0]
  return c.split(" ").last.sub("%", "").strip.to_i

def max
  c = IO::popen("pacmd \"list-sinks\" | grep \"volume steps\" | head -1").readlines[0]
  return c.split(" ").last.strip.to_i - 1

def index
  c = IO::popen("pacmd \"list-sinks\" | grep index | head -1").readlines[0]
  return c.split(" ").last.strip.to_i

def set(v)
  IO::popen("pacmd \"set-sink-volume #{index} #{v}\"").readlines

def muted
  c = IO::popen("pacmd \"list-sinks\" | grep muted | head -1").readlines[0]
  return c.split(" ").last.strip == "yes"

def toggle
  t = 1
  if ( muted )
    t = 0
  IO::popen("pacmd \"set-sink-mute #{index} #{t}\"").readlines

interval = 5

if ( ARGV.size == 0 )
  puts current
elsif (ARGV[0] == "?" )
  puts muted
elsif ( ARGV[0] == "+" )
  set([current + interval, 100].min * (max / 100.0).round)
elsif ( ARGV[0] == "-" )
  set([current - interval, 0].max * (max / 100.0).round)
elsif ( ARGV[0] == "!" )

This is certainly not the most efficient way to do it, retrieving all the info multiple times, but it works and I do not perceive any delays. Note that the script will just use the first sink that pacmd prints, so if you have a setup with multiple sinks you will have to be more clever.

Of course, the obligatory Fluxbox key bindings

None XF86AudioLowerVolume :execCommand pavol -
None XF86AudioRaiseVolume :execCommand pavol +
None XF86AudioMute :execCommand pavol !

and conky volume display:

Vol: ${exec if [ `pavol ?` != 'true' ]; then echo `pavol`%; else echo 'Muted'; fi}

Update: The script now has a home on GitHub.

Cover Art With conky And mpd

After one year of using mpd on my Fluxbox machine I have started to sift through my music collection, fixing tags and adding album covers. Since there is no need for having album art if you do not show it, I set out to make conky show the images on my disk. I was lucky to find script in the depth of some forum (reference lost) that inspired the following piece of bash code.

IFS=$'\t' mpd_array=( $(MPD_HOST=localhost MPD_PORT=6600 \
          mpc --format "\t%artist%\t%album%\t%file%\t") );


if [[ ! -f /tmp/"${mpd_array[1]}".album ]] ; then
  rm -f /tmp/*.album &> /dev/null;

  album=`dirname "/path/to/music/${mpd_array[2]}"`;
  cover=$album"/"`ls $album | egrep "jpeg|jpg|png|gif" | head -n 1`;

  if [[ ! -f $cover ]]; then
    cp $placeholder /tmp/$filename;
    convert $cover -resize "130>x" -alpha On -channel A \
                   -evaluate set 25% /tmp/$filename;

When this script is run, the currently playing album’s artist and name are retrieved and the corresponding image — or a dummy — is copied to /tmp for conky to pick up. Note that always the first image in the album’s folder is chosen and then manipulated with imagemagick; you might have to do a little coding yourself if you store your music or covers differently. Note that all time consuming stuff is done only once per album run.

On the conky side, life is easy now. Just add something like this to your .conkyrc:

${if_running mpd}
MPD: ${alignr}${mpd_status}${if_mpd_playing}
 ${mpd_artist 25}
 ${mpd_album 25}
 ${mpd_title 25}
 ${mpd_bar 3,130}
 ${exec ~/bin/conky_mpd_art}${image /tmp/conky_cover.png -p 3,772 -s 130x130 -n}

You have to adapt the visual thingies to your liking, of course.

Universal Subtitles

Due to a weird idea for a project that would include uploading many videos I checked out how subtitles are supported by different video hosters. The results were rather disappointing; if support is implemented only the original uploader can provide the source files. This causes a lot of work even if the crowd provides subtitle files. Also, there is apparently not a superior solution for creating subtitle files, let alone with videos on the web.

Then, I stumbled on Universal Subtitles. It is a Mozilla powered project still in its infancy that aims at providing a subtitle service that is independent from video hosters but supports them all. Everyone who watches a video can add or correct subtitles in his native language(s) directly in the browser. I love this concept and had to try it. I subtitled this video in German:

Try for yourselves! It is not entirely bugfree and definitely resource-hungry but for a beta, I am impressed!