| 1 | package Apache2::EmbedMP3::Template; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use Template; | ||
| 7 | |||
| 8 | my $default_template=<<EOF; | ||
| 9 | <html> | ||
| 10 | <head> | ||
| 11 | </head> | ||
| 12 | <body> | ||
| 13 | <style media="screen" type="text/css"> | ||
| 14 | body { | ||
| 15 | background:#262523 none repeat scroll 0 0; | ||
| 16 | color:#DDDDCC; | ||
| 17 | font-family:"Trebuchet MS",Helvetica,Arial,sans-serif; | ||
| 18 | font-size:14px; | ||
| 19 | font-size-adjust:none; | ||
| 20 | font-stretch:normal; | ||
| 21 | font-style:normal; | ||
| 22 | font-variant:normal; | ||
| 23 | font-weight:normal; | ||
| 24 | line-height:1.5em; | ||
| 25 | } | ||
| 26 | /* Header */ | ||
| 27 | #header { | ||
| 28 | margin: 1em auto; | ||
| 29 | width: 40em; | ||
| 30 | } | ||
| 31 | |||
| 32 | #header a, #header a:visited, #header a:active { | ||
| 33 | color: #eef; | ||
| 34 | text-decoration: none; | ||
| 35 | } | ||
| 36 | |||
| 37 | #header a:hover { | ||
| 38 | color: #ccb; | ||
| 39 | } | ||
| 40 | #posts { | ||
| 41 | margin: 0 auto; | ||
| 42 | width: 42em; | ||
| 43 | } | ||
| 44 | |||
| 45 | .post { | ||
| 46 | background-color:#363B39; | ||
| 47 | border:1px solid #494949; | ||
| 48 | margin: 1.5em 0; | ||
| 49 | padding: 1em; | ||
| 50 | } | ||
| 51 | |||
| 52 | |||
| 53 | h1 { | ||
| 54 | font-size: 3em; | ||
| 55 | font-weight: bold; | ||
| 56 | line-height: 1em; | ||
| 57 | } | ||
| 58 | .video{ | ||
| 59 | text-align:center; | ||
| 60 | } | ||
| 61 | </style> | ||
| 62 | <div id="header"> | ||
| 63 | <h1>Apache2::EmbedMP3</h1> | ||
| 64 | <h2>[% artist %] - [% title %]</h2> | ||
| 65 | <h3>[% album %] ([% year %])</h3> | ||
| 66 | </div> | ||
| 67 | |||
| 68 | <div id="posts"> | ||
| 69 | <div class="post"> | ||
| 70 | <div class="video"> | ||
| 71 | [% player %] | ||
| 72 | </div> | ||
| 73 | </div> | ||
| 74 | |||
| 75 | <div class="post"> | ||
| 76 | <pre> | ||
| 77 | [% lyrics %] | ||
| 78 | </pre> | ||
| 79 | </div> | ||
| 80 | </div> | ||
| 81 | |||
| 82 | |||
| 83 | |||
| 84 | <p align="center">Apache2::EmbedMP3 - <a href="http://axiombox.com/apache2-embedmp3">http://axiombox.com/apache2-embedmp3</a></p> | ||
| 85 | |||
| 86 | </body></html> | ||
| 87 | EOF | ||
| 88 | |||
| 89 | my $player = <<EOF; | ||
| 90 | <script type="text/javascript" src="%%% js %%%"></script> | ||
| 91 | |||
| 92 | <object | ||
| 93 | type="application/x-shockwave-flash" | ||
| 94 | data="%%% wpaudioplayer %%%" | ||
| 95 | id="audioplayer1" | ||
| 96 | height="24" | ||
| 97 | width="290"> | ||
| 98 | |||
| 99 | <param | ||
| 100 | name="movie" | ||
| 101 | value="%%% wpaudioplayer %%%"> | ||
| 102 | |||
| 103 | <param | ||
| 104 | name="FlashVars" | ||
| 105 | value="playerID=1&soundFile=%%% url %%%"> | ||
| 106 | |||
| 107 | <param | ||
| 108 | name="quality" value="high"> | ||
| 109 | |||
| 110 | <param | ||
| 111 | name="menu" value="false"> | ||
| 112 | |||
| 113 | <param | ||
| 114 | name="wmode" value="transparent"> | ||
| 115 | |||
| 116 | </object> | ||
| 117 | |||
| 118 | EOF | ||
| 119 | |||
| 120 | sub new { | ||
| 121 | my $self = shift; | ||
| 122 | return bless {}; | ||
| 123 | } | ||
| 124 | |||
| 125 | sub process { | ||
| 126 | my($self, %opts) = @_; | ||
| 127 | my $opts = \%opts; | ||
| 128 | |||
| 129 | if($opts->{template} and -r $opts->{template}) { | ||
| 130 | open my $fh, "<", $opts->{template} or die $!; | ||
| 131 | $default_template = ""; | ||
| 132 | while(<$fh>) { | ||
| 133 | $default_template .= $_; | ||
| 134 | } | ||
| 135 | close $fh; | ||
| 136 | } | ||
| 137 | |||
| 138 | my $wpaudioplayer = "/wpaudioplayer.swf"; | ||
| 139 | $wpaudioplayer = $opts->{wpaudioplayer} if $opts->{wpaudioplayer}; | ||
| 140 | |||
| 141 | my $js = "/wpaudioplayer.js"; | ||
| 142 | $js = $opts->{js} if $opts->{js}; | ||
| 143 | |||
| 144 | my $url = $opts->{uri}."?".$opts->{md5}; | ||
| 145 | $player =~ s/%%% url %%%/$url/g; | ||
| 146 | $player =~ s/%%% js %%%/$js/g; | ||
| 147 | $player =~ s/%%% wpaudioplayer %%%/$wpaudioplayer/g; | ||
| 148 | |||
| 149 | my $tt = Template->new; | ||
| 150 | my $output; | ||
| 151 | |||
| 152 | $tt->process(\$default_template, { | ||
| 153 | player => $player, | ||
| 154 | artist => $opts->{artist}, | ||
| 155 | title => $opts->{title}, | ||
| 156 | year => $opts->{year}, | ||
| 157 | album => $opts->{album}, | ||
| 158 | lyrics => $opts->{lyrics}, | ||
| 159 | }, \$output); | ||
| 160 | |||
| 161 | return $output; | ||
| 162 | |||
| 163 | } | ||
| 164 | |||
| 165 | 1; | ||
| 166 | |||
| 167 | __DATA__ |