1#! /usr/bin/perl
2###########################################################################
3# This is an example script that sends external metadata to streamripper.
4# It implements an external program that:
5#   1) Fetches a web page
6#   2) Searches the web page for the artist and title information
7#   3) Sends the information to streamripper
8#
9# To invoke the script, do this:
10#    streamripper URL -E "perl fetch_external_metadata.pl META_URL"
11#
12# This assumes that META_URL is the URL with the artist/title information
13#
14# You will need perl and LWP::Simple installed to run this script.
15# On unix, you install LWP::Simple as root, like this:
16#    perl -MCPAN -e 'install LWP::Simple';
17# On windows, LWP::Simple is included in the ActiveState perl distribution.
18#
19# This script is in the public domain. You are free to use, modify and
20# redistribute without restrictions.
21###########################################################################
22
23use LWP::Simple;
24
25if ($#ARGV != 0) {
26    die "Usage: fetch_external_metadata.pl URL\n";
27}
28$url = $ARGV[0];
29
30while (1) {
31    my $content = get $url;
32
33    if ($content =~ m/title="(.*)" artist="(.*)"/) {
34	$title = "TITLE=$1\n";
35	$artist = "ARTIST=$2\n";
36	$end_of_record = ".\n";
37	$meta_data = $title . $artist . $end_of_record;
38	syswrite (STDOUT, $meta_data, length($meta_data));
39    }
40    sleep (10);
41}
42