Page 1 of 2

php: mp3 stats

Posted: Tue Oct 14, 2003 3:55 am
by Den
I was kinda bored last weekend, and made this. This will display ur current song. You can use it for ur signature or whatever. Only for Winamp. The script will make an image, called music.png.

You need the latest php version.

mp3.php

Code: Select all

<?php 
/* 

  Winamp Real-time Song Updater 

  Usefull when you want a dynamic signature for a forum / website 
  17. dec. Added stripslashes and fixed some small bugs (den) 
  29. oct. Added documentation (haui) 
  17. oct. Added icon (den) 
  15. oct. Added md5 protection (haui) 
  10. oct. released this whole thing (den) 

  This script is for WinAmp only, use this plugin http://den.m00ki.de/winamp/install.exe to call this script remotely. 
  When called correclty (see doc) this script creates a file (defaults to music.png) in which it shows the currently played song. 

  Of course you can change this script for other needs, if you know what you are doing. 

  Getting started in seven steps: 
  1. It's rather easy to use this script. All you need is a php-capable webserver with GD-lib (it's default in php) installed. 
  2. Edit mp3.php and change your personal key '$mySecret' below to ANY RANDOM string... 
     -> For example '$mySecret = "idontcare75829jdd";' 
  3. Upload the mp3.php (this file) and the 'winampicon.png' to your webserver. 
-> You can find the icon here: http://den.m00ki.de/winamp/winampicon.png 
  4. Run mp3.php in your webbrowser and you will see something _like_: 
     Use: 'http://yourhost.com/mp3.php?secret=724269l56033b8e23b179b4c29cf8248&song=' to be the master of this script 

     The long secret-string is important in the next step. 
  5. Install the WinAmp-Plugin (http://den.m00ki.de/winamp/install.exe) and tell the plugin to execute this URL everytime, when the song changes: 
     -> http://yourhost.com/mp3.php?secret=724269l56033b8e23b179b4c29cf8248&song= 

        (Note: the LONG secret-string must be taken from the display in the 4th step!) 

  6. Now EDIT the mp3.php again and __kill__ this line OUT: 
     'echo "<br/>Use: 'http://". $HTTP_HOST . $PHP_SELF ."?secret=". $internalSecret ."&song=MySong' to be the master of this script";' 

     -> it's the third last line in this file. 

  7. Upload the mp3.php again, without the line of the sixth step. 
  This is it... your winamp now calls the URL everytime when the song changes and uses a secret only you know. 
  Thus, nobody else can change the music.png and its text. 
*/ 
    
  $mySecret = "idontcare75829jdd"; // change for your own password pls. 
  $song = $_GET["song"]; 
  $secret = $_GET["secret"];
  $internalSecret = md5($mySecret . "staticsecret"); // For a bit more security 

  $finalsong = stripslashes($song); 
  $font = "2"; // Font you want to use 
  $outputfile = "music.png"; // Filename for the image 
  $bgcolor = "#FFFFFF"; // Background Color 
  $textcolor = "#000000"; // Font Color 
  $signature = " | quadaver ownz me"; // Extra text you want to add 
  $blank = "   "; // Blank spaces for icon 
  $final = $blank. $finalsong. $signature; // Putting everything together 

  function CreatePNG($font, $outputfile, $bgcolor, $textcolor, $signature, $final) { 
    // Creating the image 
    $im = ImageCreate(ImageFontWidth($font)*strlen($final), ImageFontHeight($font)); 
    $bgcolor2 = ImageColorAllocate($im, "0x" . substr($bgcolor, 1, 2), "0x" . substr($bgcolor, 3, 4), "0x" . substr($bgcolor, 5, 6)); 
    $textcolor2 = ImageColorAllocate($im, "0x" . substr($textcolor, 1, 2), "0x" . substr($textcolor, 3, 4), "0x" . substr($textcolor, 5, 6)); 
    ImageColorTransparent($im, $bgcolor2); // Comment out for no transparency 
    ImageString($im, $font, 0, 0, $final, $textcolor2); 
    ImagePNG($im, $outputfile); 
    ImageDestroy($im); 
    
    $oldimage = imagecreatefrompng($outputfile); // Saving it as outputfile 
    $icon  = imagecreatefrompng("winampicon.png"); // Icon 

    imagecopy($oldimage, $icon, 0, 0, 0, 0, 13, 13); // Icon settings 
    imagepng($oldimage, $outputfile); 
    imagedestroy($icon); 
  }  
  if ($secret == $internalSecret) { 
      if(isset($song)) {      
        CreatePNG($font, $outputfile, $bgcolor, $textcolor, $signature, $final); 
      } else { 
          echo "No new image created. perhaps you wanna see the current one: <br/>\n". 
          "<img src=\"$outputfile\" alt=\"old one\" />"; 
      } 
  } else { 
      echo "No valid key"; 
      echo "<br/>Use: 'http://". $HTTP_HOST . $PHP_SELF ."?secret=". $internalSecret ."&song=' to be the master of this script";
    } 
?> 


Posted: Tue Oct 14, 2003 12:53 pm
by Haudrauf
hehe update soon :) Den learns md5 right now :)

Posted: Tue Oct 14, 2003 4:36 pm
by Awes8ME
hmm nice codeing m8 u gotta be bored too make that kind off an codein :)

Posted: Wed Oct 15, 2003 7:54 am
by tuv
Let's see if this is working...

Posted: Wed Oct 29, 2003 9:50 am
by Haudrauf
Hu?

Where is my credit because of inserting the md5-secret things?



/Hau

Posted: Wed Oct 29, 2003 9:55 am
by Haudrauf
This looks like an old backup has reverted this thread to an old version of the above .php too... :(



there even is one line missing...

Posted: Wed Oct 29, 2003 10:32 am
by ToMMics
thx to haui its now workin for me. thx :)

Posted: Wed Oct 29, 2003 10:44 am
by Haudrauf
updated (2003-10-29)

Posted: Wed Oct 29, 2003 2:28 pm
by Den
Sorry :) i uploaded an old version. :hop:

Posted: Thu Oct 30, 2003 7:24 am
by ToMMics
can i change the font (not the font size) somehow ?

Posted: Thu Oct 30, 2003 7:42 am
by Den
yes u can



$font = "<fontname>"



1 ... 5 are just the fonts that come with php GB lib

Posted: Thu Oct 30, 2003 7:50 am
by ToMMics
just changed it to 1. it decreased the size.

Posted: Wed Dec 17, 2003 10:03 am
by Den
Changed some things :) scripts works properly now

Posted: Wed Mar 10, 2004 3:29 am
by Hazard
hah. neat. i must try it when i get home.

Posted: Sun Jan 02, 2005 2:22 pm
by Clown
I got a different script working to createpng like Den's.
It's working, but in a different way.