forked from bentglasstube/blosxom-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnowplaying-v0i1
More file actions
56 lines (38 loc) · 1.38 KB
/
nowplaying-v0i1
File metadata and controls
56 lines (38 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Blosxom Plugin: nowplaying
# Author(s): Terrence Yu
# Version: 0.1
# Used in conjuction with Brandon Fuller's Now Playing plugin
# for iTunes for Windows (http://brandon.fuller.name/archives/hacks/nowplaying/).
# This will populate $nowplaying::nowplaying with a list of the last songs played
# in iTunes as well as the artist's name.
package nowplaying;
# --- Configurable variables -----
# Filename including full path to file
my $filename = "/home/tyua/pub_html/blog/now_playing.xml";
# --------------------------------
use CGI qw/:standard/;
use FileHandle;
sub start {
$nowplaying .= "<dl class=\"nowplaying\">\n";
# Read the now_playing.xml file
open(NOWPLAYING, "$filename") || die "Can't open $filename: $!";
do {$nowplaying_data .= <NOWPLAYING>} until eof(NOWPLAYING);
close(NOWPLAYING);
chomp($nowplaying_data);
# Put each song's data into an array
my @songs = split /<\/song>/, $nowplaying_data;
# Get rid of last </now_playing> bit
pop(@songs);
foreach my $song_data (@songs) {
my $np_title, my $np_artist;
if ($song_data =~ /<title>([^<]+)<\/title>/) {
$np_title = "$1";
}
if ($song_data =~ /<artist>([^<]+)<\/artist>/) {
$np_artist = "$1";
}
$nowplaying .= " <dt>$np_title<\/dt>\n <dd>$np_artist<\/dd>\n";
}
$nowplaying .= " <\/dl>\n";
1;
}