Get Artist Info

Hi there,

I was unsure if this would go in a feature request or script, hence why i posted it here.

At the moment, thanks to help from Charlie’s script, we have a successful artist and title updater on the station’s website.

Now, is it possible to have some sort of info grabbing script or album art grabber from a site e.g. last.fm (is that possible, i’ve never really seen it properly??). If you’ve ever seen the SAM Broadcaster program which grabs artist album image from ‘Amazon.co.uk’ and applies it to the song- I’m looking something similar to that. Also, a good example is the Absolute Radio online player (http://player.absoluteradio.co.uk/core/player/).

Is there a site which info can be ‘grabbed’ from and also another issue would be a script!? (Not necessarily to do with mAirList, probably PHP based instead)

Thanks, Ryan.

I can’t give you a ready made solution, but some pointers:
on this page there is a link to an example call to the last.fm api
so you just have to adjust the get variables for artist and title (don’t forget to get yourself your own API key)
Last.fm then returns an xml document that your script has to grab the relevant info from.
here’s an easy way to do that, if you’re using php5

That is PERFECT.

I’ll give it a go, it can’t be that hard :smiley:

Thanks very much- it will prove very useful!

Ryan.

I’ve got quite far with this now and have managed to successfully grab details from last.fm from whatever is playing in mAirList.

I’ve now tried to retrieve the XML file details which are created from last.fm through mAirList for the type of way i am wanting to do things.

This is the script-

end else if (Item.GetDuration > MUSIC) then begin sl := TStringList.Create; sl.Add('<?php'); sl.Add('if (!$xmlObj=simplexml_load_file ( "http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=' + Item.GetArtist + '&api_key=097a7ab0f5b56a894eb7a25e1c51b0da" )){'); sl.Add('echo "Error reading XML file";'); sl.Add('}'); sl.Add('foreach($xmlObj as $artist){'); sl.Add('echo "Price : " . $artist->name . "<br />"; '); sl.Add('echo "Price : " . $artist->image . "<br />";'); sl.Add('echo "Price : " . $artist->bio->summary . "<br />";'); sl.Add('}'); sl.Add('?>'); sl.SaveToFile('C:\Users\Ryan\Documents\HOMEWORK\_RADIO\site\nowplaying\nowplaying.php'); sl.Free; SystemLog('Now Playing... ' + Item.GetArtist + ' - ' + Item.GetTitle);

Yet, when i open the nowplaying.php on the site, i get the following errors.

[code]Warning: simplexml_load_file() [function.simplexml-load-file]: http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Ben’s Brother&api_key=097a7ab0f5b56a894eb7a25e1c51b0da:1: parser error : Document is empty in /home/kingdavi/public_html/devwire/radio/nowplaying/nowplaying.php on line 2

Warning: simplexml_load_file() [function.simplexml-load-file]: in /home/kingdavi/public_html/devwire/radio/nowplaying/nowplaying.php on line 2

Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in /home/kingdavi/public_html/devwire/radio/nowplaying/nowplaying.php on line 2

Warning: simplexml_load_file() [function.simplexml-load-file]: http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Ben’s Brother&api_key=097a7ab0f5b56a894eb7a25e1c51b0da:1: parser error : Start tag expected, ‘<’ not found in /home/kingdavi/public_html/devwire/radio/nowplaying/nowplaying.php on line 2

Warning: simplexml_load_file() [function.simplexml-load-file]: in /home/kingdavi/public_html/devwire/radio/nowplaying/nowplaying.php on line 2

Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in /home/kingdavi/public_html/devwire/radio/nowplaying/nowplaying.php on line 2
Error reading XML file
Warning: Invalid argument supplied for foreach() in /home/kingdavi/public_html/devwire/radio/nowplaying/nowplaying.php on line 5[/code]

It worked normally when using it in a separate PHP file and not using it through mAirList’s mls file, but when implemented into mAirList, those errors appear, even though it is the same. The normal code would have been as follows-

[code]<?php
if (!$xmlObj=simplexml_load_file ( ‘artist info would go here, but unable to be put in unless through mairlist artist tags’ )){
echo ‘Error reading XML file’;
}
foreach($xmlObj as $artist){

echo 'Price : ’ . $artist->name . ‘
’;
echo 'Price : ’ . $artist->image . ‘
’;
echo 'Price : ’ . $artist->bio->summary . ‘
’;
}
?>[/code]

Thanks, Ryan.

EDIT- It seems the artist “Ben’s Brother” is causing the problem because of the apostrophe. Any other artist such as “Girls Aloud” works great. How would i get around the problem of artist titles with apostrophes in them?

Having made further advances (yet not solving the apostrophe issue with titles and artists from previous post), i have added a track/album retriever from last.fm.

On adding this extra section to the .mls script, mAirList is now receiving an error on startup- see attached image.

Here is the script-

[code]// Intelligent Now Playing Script v2
// by Charlie Davy
// last modified 16th January 2009

// This script examines each audio item played via a Player and performs a task based upon the track’s length.
// The 3 settings below work for most situations, however you can fine-tune them if you wish.

// The last.fm links work for most artist/groups - it adds a nice touch, I think.

// Update: The OnAir switch is considered within this script, if you are “Off Air”, this script does nothing.
// If you are “On Air”, the script runs as normal. Useful in a multi-studio environment where pre-recorded
// shows may interfer with your live “now playing” display!

// IMPORTANT!! You MUST rename this file to .mls when adding it to mAirListConfig

const
IDENT = 900000000; // 90 seconds
MUSIC = 900000000; // 90 seconds
PRE_REC = 4200000000; // 7 minutes

procedure OnPlayerStart(PlayerControl: IPlayerControl; Item: IPlaylistItem);
var sl: TStringList;

begin
if Engine.GetOnAir = False then begin
SystemLog(‘mAirList is in production mode, so no action taken…’);
sl := TStringList.Create;
sl.Add(‘LiveWire Radio’);
sl.SaveToFile(‘C:\Users\Ryan\Documents\HOMEWORK_RADIO\site\nowplaying\nowplaying.php’);
sl.Free;

// If the track is over 7 minutes, assume it’s a pre-recorded programme

end else if (Item.GetDuration > PRE_REC) then begin

sl := TStringList.Create;
sl.Add(‘More music soon’);
sl.SaveToFile(‘C:\Users\Ryan\Documents\nowplaying\nowplaying.php’);
sl.Free;
SystemLog(‘This item is a pre-record or longer than 7 minutes…’);

// If the track is more than 90 seconds, assume it’s a song

end else if (Item.GetDuration > MUSIC) then begin
sl := TStringList.Create;
sl.Add(’<?php’);
sl.Add(‘if (!$xmlObj=simplexml_load_file ( "http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=’ + Item.GetArtist + ‘&api_key=097a7ab0f5b56a894eb7a25e1c51b0da" )){’);
sl.Add(‘echo “Error reading XML file”;’);
sl.Add(’}’);
sl.Add(‘foreach($xmlObj as $artist){’);
sl.Add(‘echo "Price : " . $artist->name . “
”; ‘);
sl.Add(‘echo "Price : " . $artist->image . “
”;’);
sl.Add(‘echo "Price : " . $artist->bio->summary . “
”;’);
sl.Add(’}’);
sl.Add(’?>’);
sl.SaveToFile(‘C:\Users\Ryan\Documents\HOMEWORK_RADIO\site\nowplaying\artist.php’);
sl.Free;

sl := TStringList.Create;
sl.Add(’<?php’);
sl.Add(‘if (!$xmlObj=simplexml_load_file ( "http://ws.audioscrobbler.com/2.0/?method=track.getinfo&artist=’ + Item.GetArtist + ‘&track=’ + Item.GetTitle’&api_key=097a7ab0f5b56a894eb7a25e1c51b0da" )){’);
sl.Add(‘echo “Error reading XML file”;’);
sl.Add(’}’);
sl.Add(‘foreach($xmlObj as $track){’);
sl.Add(‘echo "Price : " . $track->album->title . “
”; ‘);
sl.Add(’}’);
sl.Add(’?>’);
sl.SaveToFile(‘C:\Users\Ryan\Documents\HOMEWORK_RADIO\site\nowplaying\track.php’);
sl.Free;

sl := TStringList.Create;
sl.Add(’’ + Item.GetArtist + ’ - ’ + Item.GetTitle + ‘’);
sl.SaveToFile(‘C:\Users\Ryan\Documents\HOMEWORK_RADIO\site\nowplaying\nowplaying.php’);
sl.Free;
SystemLog(‘Now Playing… ’ + Item.GetArtist + ’ - ’ + Item.GetTitle’);

// If the track is under 90 seconds, assume it’s an advert or jingle
// You may wish to comment this section out as sending this info for such a short time may seem pointless!

end else if (Item.GetDuration < IDENT) then begin

sl := TStringList.Create;
sl.Add(‘More music soon’);
sl.SaveToFile(‘C:\Users\Ryan\Documents\HOMEWORK_RADIO\site\nowplaying\nowplaying.php’);
sl.Free;
SystemLog(‘Playing Adverts or Jingles…’);

end;
end;
begin
end.[/code]

Thanks, Ryan.


comma error.jpg

For the apostrophe, try replacing the " ’ " character by “%27” (its hexadecimal code) before creating the url in your script.
You should see " … ?methode=artiste.getinfo&artist=Ben%27s%20Brother&tract=…"

Globally, you have to convert all symbol in its hexadecimal code because url doesn’t accept all symbols…

Here are the most commons for title and artist
: %27
: %20
: %2C
: %28
: %29
<minus / dash> : %2D
: %2E

and so on…

I hope it will help you.

Regards,


Théo

Would the mls script in mAirList need a replace function for the apostrophe though?

It’s conflicting because it thinks the function has ended when the apostrophe appears when mAirList inserts it and saves the file.

Thanks, Ryan.

EDIT-

When trying with a standard address of this- http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Ben’s%20Brother&api_key=097a7ab0f5b56a894eb7a25e1c51b0da

…instead of through the mAirList script, it works fine.

So i can only think that mAirList is identifying the apostrophe within “Ben’s Brother” as the end of the function, hence messing up the file.

Delphi (and therefore mAirList scripts) uses single quotes around strings (NOT double quotes), therefore in a mAirList script, if you want a ’ within a string, you have to type it twice in succession.

Hence, for example, you would type:

ArtistName := ‘Ben’‘s Brother’;

if you wanted to assign it to a string variable.

No idea about PHP or last.fm though; I’ve never needed to use either of them (nor wanted to).

BFN
CAD

Problem is that the Artist is generated ‘whenever’ as such when it is played and inserts the artist as and when as i’m sure you understand.

It’s when it adds it that it needs replacing, because it’s the script that’s the problem, not the PHP etc.

Is there a script that could replace any ’ within the initial opening and closing apostrophes?

Thanks Cad, Ryan.

Also by the way, just fiddling with the file and i want to simply write the Artist to nowplaying.php, yet i get errors when loading the script with this bit in it-

sl := TStringList.Create; sl.Add(' ' + Item.GetArtist + ' '); sl.SaveToFile('nowplaying.php'); sl.Free;

I’ve tried without some apostrophes, without the + signs etc. No luck.

Thanks, Ryan.

Ryan, sl.Add(Item.GetArtist); should work - you don’t need those symbols unless you’re adding your own text.

Ryan, to replace text within strings, you need to use one of these (I forget which one works in mAirList script!):

sAfter := StringReplace(sBefore, 'x', 'y');

or
sAfter := AnsiStringReplace(sBefore, ‘x’, ‘y’);

The examples change x to y. Note that the from and to strings don’t need to be the same length. Also note that sBefore and sAfter can be the same variable. :wink:

If Delphi (language of mAirList script) isn’t a language you’re familiar with, I thoroughly recommend this site: http://delphibasics.co.uk.

BFN
CAD

Charlie-

Here is the script, yet i still get the following error (see attached image)-

[code]// Intelligent Now Playing Script v2
// by Charlie Davy
// last modified 16th January 2009

// This script examines each audio item played via a Player and performs a task based upon the track’s length.
// The 3 settings below work for most situations, however you can fine-tune them if you wish.

// The last.fm links work for most artist/groups - it adds a nice touch, I think.

// Update: The OnAir switch is considered within this script, if you are “Off Air”, this script does nothing.
// If you are “On Air”, the script runs as normal. Useful in a multi-studio environment where pre-recorded
// shows may interfer with your live “now playing” display!

// IMPORTANT!! You MUST rename this file to .mls when adding it to mAirListConfig

const
IDENT = 900000000; // 90 seconds
MUSIC = 900000000; // 90 seconds
PRE_REC = 4200000000; // 7 minutes

procedure OnPlayerStart(PlayerControl: IPlayerControl; Item: IPlaylistItem);
var sl: TStringList;

begin
if Engine.GetOnAir = False then begin
SystemLog(‘mAirList is in production mode, so no action taken…’);
sl := TStringList.Create;
sl.Add(‘LiveWire Radio’);
sl.SaveToFile(‘C:\Users\Ryan\Documents_RADIO\site\nowplaying\nowplaying.php’);
sl.Free;

// If the track is over 7 minutes, assume it’s a pre-recorded programme

end else if (Item.GetDuration > PRE_REC) then begin

sl := TStringList.Create;
sl.Add(‘More music soon’);
sl.SaveToFile(‘C:\Users\Ryan\Documents\nowplaying\nowplaying.php’);
sl.Free;
SystemLog(‘This item is a pre-record or longer than 7 minutes…’);

// If the track is more than 90 seconds, assume it’s a song

end else if (Item.GetDuration > MUSIC) then begin

sl := TStringList.Create;
sl.Add(Item.GetArtist);
sl.SaveToFile(‘C:\Users\Ryan\Documents_RADIO\site\nowplaying\nowplaying.php’);
sl.Free;
SystemLog(‘Now Playing… ’ + Item.GetArtist + ’ - ’ + Item.GetTitle’);

// If the track is under 90 seconds, assume it’s an advert or jingle
// You may wish to comment this section out as sending this info for such a short time may seem pointless!

end else if (Item.GetDuration < IDENT) then begin

sl := TStringList.Create;
sl.Add(‘More music soon’);
sl.SaveToFile(‘C:\Users\Ryan\Documents_RADIO\site\nowplaying\nowplaying.php’);
sl.Free;
SystemLog(‘Playing Adverts or Jingles…’);

end;
end;
begin
end.[/code]

Cad-

Where would that code go within the script? I presume at the very end, that’s if Delphi works in a logical order like PHP does, by working down through the document- by that i mean it would first add the artists etc into the rlevant fields, and then at the end execute your code and replace any ’ with whatever?

Thanks, Ryan.


nowplaying error.jpg

Errr, well it isn’t happy with Line51:
SystemLog(‘Now Playing… ’ + Item.GetArtist + ’ - ’ + Item.GetTitle’);

Not tested, but it should be:
SystemLog('Now Playing… ’ + Item.GetArtist + ’ - ’ + Item.GetTitle);
without the last ’ at the end. Note that you open the quotes with the Now Playing bit, you close them off for the artist, then you open them for the hyphen, then you close them for the title. In your example, you then have a final ’ which isn’t required.

Brilliant!

Working now…thanks for the help!

Ryan.

de nada (let’s hope his Spanish is as good as his French!)

If you enable the StatusBar in Notepad, it makes hunting for script errors quite straightforward as you don’t have to keep counting line-numbers :wink:

I only did Spanish for 2 years haha. But i know that it means ‘no problem’ :wink:

And i use DreamWeaver so line counting is no problem!

Thanks, Ryan.

Ryan, you would do something like:

var
    sTitle, sArtist: string;
    sl: TStringList;

begin

    // .... the rest of your code before the GetTitle ...

    sTitle := Item.GetTitle;
    sArtist := Item.GetArtist;
    SystemLog(sArtist + ' - ' + sTitle);

    sTitle := AnsiStringReplace(sTitle, '''', '%27');
    sTitle := AnsiStringReplace(sTitle, ',', '%2C');
    // ... add similar replacements for other 'bad' characters in sTitle, AND the same idea for sArtist ...

    sl := TStringList.Create;
    sl.Add(sArtist + ' - ' + sTitle);
    sl.SaveToFile('nowplaying.php');
    sl.Free;

end.

In other words, you store the Artist and Title values in string variables, write to SystemLog so you can see what they are, replace anything necessary BEFORE writing your file, and finally write the file.

(Apologies if the above is not 100% accurate: I’m at work, plus Delphi isn’t my first language; I’m really a Visual BASIC person!)

BFN
CAD

Hi Cad,

Much appreciated for the script.

Right now I have the following script, yet an error popped up in mAirList, line 55 saying it wasn’t happy with AnsiStringReplace. So I removed the ‘Ansi’ and left it as StringReplace, yet it isn’t happy with that either (see attached image).

[code]// Intelligent Now Playing Script v2
// by Charlie Davy
// last modified 16th January 2009

// This script examines each audio item played via a Player and performs a task based upon the track’s length.
// The 3 settings below work for most situations, however you can fine-tune them if you wish.

// The last.fm links work for most artist/groups - it adds a nice touch, I think.

// Update: The OnAir switch is considered within this script, if you are “Off Air”, this script does nothing.
// If you are “On Air”, the script runs as normal. Useful in a multi-studio environment where pre-recorded
// shows may interfer with your live “now playing” display!

// IMPORTANT!! You MUST rename this file to .mls when adding it to mAirListConfig

const
IDENT = 900000000; // 90 seconds
MUSIC = 900000000; // 90 seconds
PRE_REC = 4200000000; // 7 minute

var
sTitle, sArtist: string;
sl: TStringList;

procedure OnPlayerStart(PlayerControl: IPlayerControl; Item: IPlaylistItem);
var sl: TStringList;

begin
if Engine.GetOnAir = False then begin
SystemLog(‘mAirList is in production mode, so no action taken…’);
sl := TStringList.Create;
sl.Add(‘LiveWire Radio’);
sl.SaveToFile(‘C:\Users\Ryan\Documents\HOMEWORK_RADIO\site\nowplaying\nowplaying.php’);
sl.Free;

// If the track is over 7 minutes, assume it’s a pre-recorded programme

end else if (Item.GetDuration > PRE_REC) then begin

sl := TStringList.Create;
sl.Add(‘More music soon’);
sl.SaveToFile(‘C:\Users\Ryan\Documents\nowplaying\nowplaying.php’);
sl.Free;
SystemLog(‘This item is a pre-record or longer than 7 minutes…’);

// If the track is more than 90 seconds, assume it’s a song

end else if (Item.GetDuration > MUSIC) then begin

sTitle := Item.GetTitle;
sArtist := Item.GetArtist;
SystemLog(sArtist + ’ - ’ + sTitle);

sTitle := StringReplace(sTitle, ‘’’’, ‘%27’);
sTitle := StringReplace(sTitle, ‘,’, ‘%2C’);
sArtist := StringReplace(sArtist, ‘’’’, ‘%27’);
sArtist := StringReplace(sArtist, ‘,’, ‘%2C’);

sl := TStringList.Create;
sl.Add(’<?php’);
sl.Add(‘if (!$xmlObj=simplexml_load_file ( "http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=’ + sArtist + ‘&api_key=097a7ab0f5b56a894eb7a25e1c51b0da" )){’);
sl.Add(‘echo “Error reading XML file”;’);
sl.Add(’}’);
sl.Add(‘foreach($xmlObj as $artist){’);
sl.Add(‘echo "Price : " . $artist->name . “
”; ‘);
sl.Add(‘echo "Price : " . $artist->image . “
”;’);
sl.Add(‘echo "Price : " . $artist->bio->summary . “
”;’);
sl.Add(’}’);
sl.Add(’?>’);
sl.SaveToFile(‘C:\Users\Ryan\Documents\HOMEWORK_RADIO\site\nowplaying\artist.php’);
sl.Free;

sl := TStringList.Create;
sl.Add(’<?php’);
sl.Add(‘if (!$xmlObj=simplexml_load_file ( "http://ws.audioscrobbler.com/2.0/?method=track.getinfo&artist=’ + SArtist + ‘&track=’ + STitle+ ‘&api_key=097a7ab0f5b56a894eb7a25e1c51b0da" )){’);
sl.Add(‘echo “Error reading XML file”;’);
sl.Add(’}’);
sl.Add(‘foreach($xmlObj as $track){’);
sl.Add(‘echo "Price : " . $track->name . “
”; ‘);
sl.Add(‘echo "Price : " . $track->wiki->content . “
”; ‘);
sl.Add(’}’);
sl.Add(’?>’);
sl.SaveToFile(‘C:\Users\Ryan\Documents\HOMEWORK_RADIO\site\nowplaying\track.php’);
sl.Free;

sl := TStringList.Create;
sl.Add(’’ + Item.GetArtist + ’ - ’ + Item.GetTitle + ‘’);
sl.SaveToFile(‘C:\Users\Ryan\Documents\HOMEWORK_RADIO\site\nowplaying\nowplaying.php’);
sl.Free;
SystemLog('Now Playing… ’ + Item.GetArtist + ’ - ’ + Item.GetTitle);

end;
end;
begin
end.[/code]

Thanks, Ryan.


stringreplace.jpg

Ryan: As I said, I can’t remember whether mAirList script supports either of the StringReplace functions in Delphi. I’ll try to check when I get home.

[You need to bear in mind that PascalScript (the basis of mAirList script) is a) largely undocumented; and b) requires the developer of the Delphi program using it (i.e. Doktor Torben) to explicitly implement/instantiate each and every Pascal/Delphi unit, function, etc. etc. to make it available through scripting in that program (mAirList in this case). So, although many ‘standard’ Delphi/Pascal functions DO exist in mAirList script, equally there are several which don’t, like many of the date/time formatting and conversion functions. Generally speaking, what I do is: find the function I need from DelphiBasics, try it out in a test mAirList script, and if it comes up ‘unknown identifier,’ I know I need to ‘code around’ that, because it’s not available in mAirList script.]

BFN
CAD