php: mp3 stats

Forum for anything hard- or software related.

Moderator: Moderators

Den
something dur dur
Posts: 2616
Joined: Fri Jul 25, 2003 8:56 am
Location: nl
Contact:

php: mp3 stats

Post 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";
    } 
?> 

Last edited by Den on Tue Aug 24, 2004 2:14 pm, edited 38 times in total.
There's a chopper coming in 3 days and there's a katana on top of the cafe and that's all you need to know
Image
Haudrauf
tripped on its own grenade
Posts: 331
Joined: Tue Aug 26, 2003 11:20 am
Location: de
Contact:

Post by Haudrauf »

hehe update soon :) Den learns md5 right now :)
ImageOwner of http://aq2maps.quadaver.org
Not part of #aq2admins for a reason.
Awes8ME

Post by Awes8ME »

hmm nice codeing m8 u gotta be bored too make that kind off an codein :)
tuv
is connecting
Posts: 19
Joined: Wed Aug 27, 2003 1:49 pm
Location: nl

Post by tuv »

Let's see if this is working...
Haudrauf
tripped on its own grenade
Posts: 331
Joined: Tue Aug 26, 2003 11:20 am
Location: de
Contact:

Post by Haudrauf »

Hu?

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



/Hau
ImageOwner of http://aq2maps.quadaver.org
Not part of #aq2admins for a reason.
Haudrauf
tripped on its own grenade
Posts: 331
Joined: Tue Aug 26, 2003 11:20 am
Location: de
Contact:

Post 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...
ImageOwner of http://aq2maps.quadaver.org
Not part of #aq2admins for a reason.
ToMMics
found a way out
Posts: 200
Joined: Tue Jul 29, 2003 7:52 am
Location: de
Contact:

Post by ToMMics »

thx to haui its now workin for me. thx :)
Image
Haudrauf
tripped on its own grenade
Posts: 331
Joined: Tue Aug 26, 2003 11:20 am
Location: de
Contact:

Post by Haudrauf »

updated (2003-10-29)
ImageOwner of http://aq2maps.quadaver.org
Not part of #aq2admins for a reason.
Den
something dur dur
Posts: 2616
Joined: Fri Jul 25, 2003 8:56 am
Location: nl
Contact:

Post by Den »

Sorry :) i uploaded an old version. :hop:
There's a chopper coming in 3 days and there's a katana on top of the cafe and that's all you need to know
Image
ToMMics
found a way out
Posts: 200
Joined: Tue Jul 29, 2003 7:52 am
Location: de
Contact:

Post by ToMMics »

can i change the font (not the font size) somehow ?
Image
Den
something dur dur
Posts: 2616
Joined: Fri Jul 25, 2003 8:56 am
Location: nl
Contact:

Post by Den »

yes u can



$font = "<fontname>"



1 ... 5 are just the fonts that come with php GB lib
There's a chopper coming in 3 days and there's a katana on top of the cafe and that's all you need to know
Image
ToMMics
found a way out
Posts: 200
Joined: Tue Jul 29, 2003 7:52 am
Location: de
Contact:

Post by ToMMics »

just changed it to 1. it decreased the size.
Image
Den
something dur dur
Posts: 2616
Joined: Fri Jul 25, 2003 8:56 am
Location: nl
Contact:

Post by Den »

Changed some things :) scripts works properly now
There's a chopper coming in 3 days and there's a katana on top of the cafe and that's all you need to know
Image
Hazard
plummets to its death
Posts: 54
Joined: Mon Sep 15, 2003 6:40 pm
Location: fi
Contact:

Post by Hazard »

hah. neat. i must try it when i get home.
Image
Clown
unpossible??!?!!
Posts: 1750
Joined: Sun Jul 27, 2003 7:38 am
Location: en

Post by Clown »

I got a different script working to createpng like Den's.
It's working, but in a different way.
I don't give a shit.
Post Reply