Download Latest Version cgi-juke_0.1.tar.xz (57.0 kB)
Email in envelope

Get an email when there's a new version of CGI Jukebox

Home
Name Modified Size InfoDownloads / Week
readme.md 2021-01-25 7.1 kB
cgi-juke_0.1.tar.xz 2021-01-25 57.0 kB
Totals: 2 Items   64.1 kB 0

These are 2 programs (directory scanner (jb) and CGI target (jbe)) that will let you make a CGI mp3 jukebox. You can have thousands of songs playable over a wifi LAN by clicking on them in a web browser, which may be in a phone, Kindle, iPad, etc. It's NOT intended for use on real internet since there were no security precautions taken. I'm behind a firewall using NAT with a dynamic IP, nothing gets in.

For setup you're going to need to have Apache2 installed with CGI working. There's a way to do the same thing with nginx and an add-on CGI package, which is OK but you're on your own. The same thing goes for sound. I'm using pure Alsa, developing on a laptop, intending to run on a Raspberry Pi with a USB sound card driving an external stereo. It will work using Lynx as a web browser.

If you're using Debian, maybe it's in Ubuntu too, there's a little helper so you can type a2enmod cgi, then apachectl restart. You'll probably need sudo. Your cgi-bin (where you put CGI programs) is actually in /usr/lib/cgi-bin. Try a CGI test program or two, I'll stick a couple in the tarball, before you try to get the jukebox working. jbe (Juke Box Engine) is the CGI program for the jukebox, I worked with the source and Makefile in the cgi-bin. Once it's working you don't need to do anything else to it.

The mp3 files don't need to be in your cgi-bin since jbe is calling mpg123, but they do need to be owned by the www-data account, at least that's what I did. So like "chown -R www-data mp3" if mp3 is where you put your files. The directory structure can be almost anything you want, jb will pick it up and make web pages. Within mp3 I had a directory level of artists, then one of albums, then songs. With exceptions like a level for live albums vs studio albums. That worked fine because when jb finds a subdirectory it puts it in a subdir list, mp3s have their own list. They get sorted then explore starts going into subdirectories by recursing (calling itself). When subdirs are done it starts listing and linking files. It shouldn't list directories that don't have mp3 files or subdirs in them but that's not perfect. The output of jb, besides a directory structure, is in jbmain.tab, which needs to go into your cgi-bin. It was written with a test set of 1199 dirs, 15104 files. jbmain.tab is a list of file names and fully qualified paths, in a specific order. The other output is a set of HTML files. They're what the web browser uses and link a file number to a path (on the screen). There needs to be a directory of html files, that can be separate from where the mp3s are. File names for the mp3 files are assumed to be song titles, they're what will end up in web pages anyway.

The 2 errors that had me stumped briefly were that if www-data doesn't own the mp3 files it can't play them. Also there's a timeout value in /etc/apache2/apache2.conf of 300 seconds. For playing albums that should be /more like 3600 seconds (1 hour).

OK, sudo apt-get install mpg123 apache2 build-essential for Debian and Ubuntu people. Put my tarball somewhere and unpack it. Configuration is by some defines in the source. In jbe.c is

define PLAYPROG "/usr/bin/mpg123" // Path to mpg123 on server

define MODULE "alsa" // or jack or pulse, etc. from above

define ALSADEV "plughw:1,0,0" // device name

so change those if you need to and type make to compile. Assuming you have CGI working copy jbe into your cgi-bin. You don't have to use alsa but the MODULE line is where you change it. I've only used alsa. I left PLAYPROG easily changeable because I thought I might set it to flac, except that's not a player.

In the scanning program jb:

define MP3HOME "/data/mp3"

define LOCWEB "/var/www/html/jb" // 2 ways to refer to the output dir

define WEB "http://pbp/jb"

define CGIPROG "http://pbp/cgi-bin/jbe"

define DIRFILES 1000 // max # of files or subdirs in a dir

define MAXCRUMBS 10 // max # of breadcrumbs

define LISTFILE "/usr/lib/cgi-bin/jbmain.tab" // input to the CGI

MP3HOME is where your MP3 collection is, you don't have to make a fresh collection. Nothing is written there. It does need to be readable by the CGI program which runs as the www-data user (with Apache). I just did a "chown -R www-data mp3" on mine. You need to do that whenever you add files to it. /data is a mountpoint I mount an SSD drive on, it's not standard.

LOCWEB is how programs refer to where the HTML pages are, like to read or write them. It's a path on the server machine only.

WEB is the URL you'd use from outside the server. pbp is the machine name here (hostname) so referring to jb on it gets the jukebox directory. Oh, index.html there needs to be a symlink to 000000.html which is the root of the automatically named directories/files. It's a flat filesystem there, 1 file per directory. The MP3 files don't need to be in a flat directory.

CGIPROG is the web path to whereever you put jbe, usually it's in your cgi-bin. The URL to play a file is this with a ? and a file number on the end. Your machine hostname or IP will become part of this. This is used in the web pages generated.

DIRFILES Is used to size both arrays of subdirs and files in a directory, There are checks that it hasn't exceeded these. You might have to increase and recompile. Worry about it then.

MAXCRUMBS The maximum number of breadcrumbs you can leave.

LISTFILE This is the file list that this program outputs and jbe reads. It's not easily changeable there so don't change it here unless you have to, then fudge it there. There is no actual index to this array of paths, the index is the lines' position in this file. It gets replaced each time you scan through your MP3 files.


Since jb explores dirs starting at MP3HOME you could put it in your path and run it from anywhere. jbe needs to go in your cgi-bin so Apache finds it.

You need to create your LOCWEB directory whereever you want it, it's where jb puts pages. Then in there do: ln -s 000000.html index.html This means the default web page in this directory (index.html) will be the first one jb spits out (000000.html).

Copy the favicon.ico into LOCWEB as well. It gives browser tabs a recognizable icon so when you have 20 of them open it's easier to spot the jukebox one. And jb200.png, it's a photo of an old jukebox remote, it's used on the main page.

Filenames are sorted and numbered, those numbers become line numbers in LISTFILE. Directories are also sorted and numbered, those numbers become web page filenames in LOCWEB. Directories with no MP3 files, or subdirectories with MP3 files are ignored and not listed. You can have images or videos amongst your MP3 files and they'll be ignored.

When I started this I mostly only had mp3 files that I'd made myself by ripping CDs to mp3. But if you go to https://tpbpirateproxy.org/en and search you can find a lot of music on bittorrents. Install a bittorrent client and it will start trickling in. I mostly avoided doing this with artists who are still alive and producing for legal reasons. And I'm not selling anything.

Source: readme.md, updated 2021-01-25