Tag Archives: bash

Audio CD index

I’ve got a large Folk Music collection. And i wanted to have an overview of the Audio CD’s (mp3/flac) i’ve got from every Band or Artist.

So I made some PHP scripts and a scraping tool. To get a nice overview.

A part of it looks like this:

Most is auto-generated:

The scraper part needs eyed3 (made at a later date)

PHP Files

::::::::::::::
artist.php
::::::::::::::
<html><head><title></title>
<style type="text/css">
 img.clams { border: black dotted 1px; }
 </style>
</head><body vlink=black alink=black link=black>
<? $filebak=$file; ?>
<center><P>
<table border=2><tr><td bgcolor="#cccccc">
<P>
<?php include "list.php"; ?>
</td></tr></table>
<P>


<table>

<?php
$file=$filebak;
echo "<tr><td bgcolor=black><a name=\"$file\"><font color=white face=tahoma><b>$file</b></font></a></td></tr>"; include "readcovers.php";  
?> 

</table>
<P>
<?php if (file_exists("thumbs/$file/info.txt")){ include "thumbs/$file/info.txt"; } ?>
</body></html>
::::::::::::::
index.php
::::::::::::::
<html><head><title></title>
<style type="text/css">
 img.clams { border: black dotted 1px; }
 </style>
</head><body vlink=black alink=black link=black>
<a name="top">
<font face=tahoma color=red>missing</font> ::
<font face=tahoma color=orange>not complete</font> ::
<font face=tahoma color=blue>special</font> ::
<font face=tahoma color=green>got this one</font><P> 
<center><P>
<font face=Tahoma>TODO: List artists, per-page covers (per artist)<BR>
Sort A-Z<BR>Counters<BR>filter <i>got this one / Missing</i>
<table border=2><tr><td bgcolor="#cccccc">
<P>
<?php include "list.php"; ?>
</td></tr></table>
<P>


<table>

<?php
$dir = "thumbs/";

// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
	$dh = opendir($dir);
       	while (($file = readdir($dh)) !==false) {
           #echo "filename: $file : filetype: " . filetype($dir . $file) . "\n";
		if (filetype($dir . $file)=="dir" && $file!=="." && $file!=="..") { echo "<tr><td bgcolor=black><a name=\"$file\"><font color=white face=tahoma><b>$file</b></font></a><a href=\"#top\"> <f
ont face=tahoma color=\"grey\"><small>(top)</small></a></td></tr>"; include "readcovers.php";  }
       	}
}
       closedir($dh);
?> 

</table>
</body></html>
::::::::::::::
list.php
::::::::::::::
<html><head><title></title>
<style>
<!--
A:link {text-decoration: none; color: "#000000";}
A:visited {text-decoration: none; color: "#000000";}
A:hover {text-decoration:  none; }
//-->

</style>
</head><body>

<center><P>
<?php
$countart=0;
$dir = "thumbs/";

// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
	$dh = opendir($dir);
       	while (($file = readdir($dh)) !==false) {
		if (filetype($dir . $file)=="dir" && $file!=="." && $file!=="..") { echo "<a href=\"index.php#$file\"><font color=black face=tahoma><b>$file</b></font></a><a href=\"artist.php?file=$file\
">@</a> "; $countart=$countart+1; if ($countart==4) { $countart=0; echo "<BR>";} else { echo ":: ";}  }
       	}
}
       closedir($dh);
?> 
</body></html>
::::::::::::::
readcovers.php
::::::::::::::

<tr><td align=left>
<table><tr><td width=30></td>
<?php
$dir1 = "thumbs/$file";
$counter=0;
// Open a known directory, and proceed to read its contents
if (is_dir($dir1)) {
   if ($dh1 = opendir($dir1)) {
       while (($file1 = readdir($dh1)) !==false)  {
#echo "filename: $file : filetype: " . filetype($dir1 . $file) . "<BR>";
$fileinfo="leeg";
if ($counter==7) { echo "</tr><tr><td width=30></td>"; $counter=0; }
if ($file1!=="." && $file1!=="..") {
if (stristr("$file1", ".jpg")) { echo "<td valign=top width=105><center><img src=\"$dir1/$file1\" class=\"clams\">"; 
$fileinfo = str_replace("jpg", "txt", $file1); $counter=$counter+1;}
if (file_exists("$dir1/$fileinfo")) { echo "<br><font face=tahoma><small>"; include "$dir1/$fileinfo"; }
echo "</small></td>";
}
       }
       closedir($dh1);
   }
}
?> 
</tr></table>
</td></tr>

Scraper

mkdir -p /tmp/1
find  celtic/Celtic/ -type d | while read ; do
countmp3=$(ls "$REPLY" | egrep -i mp3$ | wc -l)
if [ $countmp3 -gt 0 ] ; then
	rm -f /tmp/1/*
	album=$( echo $REPLY | rev | cut -f1 -d/ | rev)
	artist=$( echo $REPLY | rev | cut -f2 -d/ | rev)
	countslash=$(echo "$REPLY"  | tr -cd '/' | wc -c)
	if [ $countslash -lt 4 ] ; then
		artist=$album
		album="" 
	fi 
	echo "artist : $artist - Album : $album"
	mkdir -p "thumbs/$artist"
	ls "$REPLY" | egrep -i "mp3$|flac$" | while read biggest; do  
		eyeD3 --write-images=/tmp/1  "$REPLY/$biggest"	

		if [ ! "$( ls -A /tmp/1/ )" ]  ; then cp empty.jpg /tmp/1/FRONT.jpg ;fi
		deze=$(ls -S /tmp/1/* | head -1)
		convert -resize 200x200 "$deze" "thumbs/$artist/$album.jpg" 
		echo "$album" > "thumbs/$artist/$album.txt"
	done
fi
done

I’m planning to make an version which shows every individual mp3, and shows me if they are valid mp3’s/flac and have a good cover.
(Using tiny thumbnails) (Made this, didin’t post)

Made a webinterface for my DIY webcam

Using a steppermotor controller with two motors. A video capturing device (videoblaster) and a mini B/W camera.

  • Up/down/left/right and diagonal
    • Red double speed green single speed
  • Reset view
  • 2 Presets with save and recall
Setup with parallel cable

Written software in html and some CGI scripts.
Perl and C.

#include <asm/io.h>

# C Code for moving left

int main(int agrc,char agrv[])
{
  int i,wachten;
  int richting1[8]={0x27,0x2d,0x1c,0x0d,0x03,0x09,0x38,0x29};
  int richting2[8]={0x29,0x38,0x09,0x03,0x0d,0x1c,0x2d,0x27};
  ioperm(0x378,3,1);
  ioperm(0x37a,3,1);
  wachten=100;


for (i=0; i<=7; i=i+1)
        {
        outb(richting2[i], 0x378);
        outb(1, 0x37a);
        usleep(wachten);
        outb(0, 0x37a);
        usleep(wachten);
        outb(1, 0x37a);
        usleep(wachten);
        }

 return(0);
}
#!/usr/bin/perl
# Perl CGI script 

# Uses 204 no content trick to stay on same page
use LWP::Simple;
my $img = get ('http://10.1.0.1/cgi-bin/left.cgi');
print "Status: 204 No content\n\n";

Streaming video was done using progressive JPG push.
Later i used the capturing command in the loop below.

#!/bin/sh

# push jpg, and update after 1sec
# output mime header

echo Content-type: multipart/x-mixed-replace;boundary=--WebcamRules\n
echo
echo --WebcamRules

# create stream

while true; do
   echo Content-type: image/jpeg
   echo
   cat /var/lib/httpd/htdocs/webcam.jpg
   echo
   echo --WebcamRules

   sleep 1
done

Steppermotor card was using a parallel port.

Aluminum machined part by Joost

Pdp-11 and playing with printers

I got a free mainframe, when i was about 17.
It was a huge Pdp-11/34 which a had to get from Enschede to Holten using a trailer.

PDP-11/34
  • It was a 19inch rack (loads of metal)
    • 2x 8inch floppy drives
    • 2x 20MB harddisk drives (with cardridge) each 34KG!
  • multiple (3?) Decwriter III printers
  • loads of VT100 terminals
  • 2.5 meter of manuals
  • cables
  • disks (8 inch) and harddisk cartridges

I converted the power to a generic 230V connector. When booting the machine all the lights in the house dimmed.

I didn’t know anything about mainframes, but i got things working.
Sometimes i would play with it, but after a while it didn’t run anymore.

I’ve kept some of the parts of the machine.
Terminals we used for a long time to connect to a linux server.
( The VT100 where later switched for more modern Wyse terminals )

One of the two drives (34kg) (not my picture)

Some parts i’ve kept

VT100 serial terminal (gave this one to a colleage) Postit says: Could you install Windows on this for me??

Serial printer

Last Decwriter i’ve got, also gone now.

These printer we used for generic printing, and just for fun.
They made a lot of noise, and even they are serial printers they are fast!

So i resourced ms-dos into assembly and printed that, that was a sh*tload of paper.
We even made a racing game. (Can’t find the source, but i’ve recreated a lookalike in linux-bash)

Object of the game was to keep your car O character on the road.
The printer printed the lines, and you could use the keyboard to move your car, which also got printed.

Below the build-in-5-minutes bash lookalike. ( z left, x straight and c right)
Original had more intricate road, and probably the road was drawn using two lines, to speedup printing (Decwriter III could print at 180 characters per second bidirectional!)

Looked more like this i think
#!/bin/bash
i=0
j=0
car=8
while true ; do
no=$(awk "BEGIN{print sin($i*atan2(0,-1)/180)*40+40}" | cut -f1 -d.)
way=$(awk "BEGIN{print sin($j*atan2(0,-1)/180)*10+13}" | cut -f1 -d.)
#echo $way
if [ $car -lt 0 ] ; then echo "boom" ; exit ; fi
if [ $car -gt $way ] ; then echo "boom" ; exit ; fi
carr=$car
rest=$((140-$no-$way))
i=$(($i + 1))
j=$(($j + 5))
while [ $no -gt 0 ] ; do
echo -n " "
no=$(($no - 1))
done
echo -n "#"
while [ $way -gt 0 ] ; do
echo -n " "
if [ $carr -eq 0 ] ; then
echo -n "O"
fi
way=$(($way - 1))
carr=$(($carr - 1))
done
echo -n "#"
while [ $rest -gt 0 ] ; do
echo -n " "
rest=$(($rest - 1))
done
echo ""
read -r -t 0.1 -n 1 -s key
if [ "$key" == "z" ] ; then
car=$((car - 1 ))
fi
if [ "$key" == "x" ] ; then
car=$((car - 1 ))
fi
if [ "$key" == "c" ] ; then
car=$((car + 1 ))
fi
done