how to filter the music? - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: how to filter the music? (/showthread.php?tid=68704)
how to filter the music? by roflmao456 on 11-21-2006 at 03:13 AM
how do i filter the Messenger.MyCurrentMedia thing? i need help
it always ends up like {0}\Music or something like that >_>..
RE: how to filter the music? by Matti on 11-21-2006 at 05:27 PM
You should use a regular expression for that.
Here's a small function which will return an array containing the information out of a media string.
code: function parseMedia(Media) {
var mediaExp = /^\\0([a-z]+)\\0([0-1])\\0(.*)\\0(.*)\\0(.*)\\0(.*)\\0(.*)\\0$/i;
if(typeof(Media) == "string" && mediaExp.test(Media)) {
var arr = new Array();
arr['type'] = RegExp.$1;
arr['enabled'] = RegExp.$2;
arr['format'] = RegExp.$3;
arr['title'] = RegExp.$4;
arr['artist'] = RegExp.$5;
arr['album'] = RegExp.$6;
arr['contentId'] = RegExp.$7;
return arr;
} else {
return false;
}
}
An example to use this:
code: var arrMedia = parseMedia(Messenger.MyCurrentMedia);
if(!arrMedia) {
//Here you can work with the arrMedia array
Debug.Trace("Now Playing: " + arrMedia['artist'] + " - " + arrMedia['title'];
} else {
//The media string was invalid
}
RE: RE: how to filter the music? by roflmao456 on 11-21-2006 at 09:15 PM
quote: Originally posted by Mattike
You should use a regular expression for that.
Here's a small function which will return an array containing the information out of a media string.
code: function parseMedia(Media) {
var mediaExp = /^\\0([a-z]+)\\0([0-1])\\0(.*)\\0(.*)\\0(.*)\\0(.*)\\0(.*)\\0$/i;
if(typeof(Media) == "string" && mediaExp.test(Media)) {
var arr = new Array();
arr['type'] = RegExp.$1;
arr['enabled'] = RegExp.$2;
arr['format'] = RegExp.$3;
arr['title'] = RegExp.$4;
arr['artist'] = RegExp.$5;
arr['album'] = RegExp.$6;
arr['contentId'] = RegExp.$7;
return arr;
} else {
return false;
}
}
An example to use this:
code: var arrMedia = parseMedia(Messenger.MyCurrentMedia);
if(!arrMedia) {
//Here you can work with the arrMedia array
Debug.Trace("Now Playing: " + arrMedia['artist'] + " - " + arrMedia['title'];
} else {
//The media string was invalid
}
when i use it in the OnEvent_MyMediaChange function it ends up as undefined... i just copied and pasted the code
RE: how to filter the music? by Spunky on 11-21-2006 at 09:39 PM
It is an error on your part as the function works fine...
code: var MediaInfo = new Array();
function OnEvent_MyMediaChange(NewMedia){
MediaInfo = parseMedia(NewMedia);
for(i in MediaInfo){
Debug.Trace(i+" - "+MediaInfo[i]);
}
}
function parseMedia(Media) {
var mediaExp = /^\\0([a-z]+)\\0([0-1])\\0(.*)\\0(.*)\\0(.*)\\0(.*)\\0(.*)\\0$/i;
if(typeof(Media) == "string" && mediaExp.test(Media)) {
var arr = new Array();
arr['Type'] = RegExp.$1;
arr['Enabled'] = RegExp.$2;
arr['Format'] = RegExp.$3;
arr['Title'] = RegExp.$4;
arr['Artist'] = RegExp.$5;
arr['Album'] = RegExp.$6;
arr['ContentId'] = RegExp.$7;
Debug.Trace(arr);
return arr;
} else {
return false;
}
}
That works perfectly
RE: RE: how to filter the music? by roflmao456 on 11-21-2006 at 09:46 PM
quote: Originally posted by SpunkyLoveMuff
It is an error on your part as the function works fine...
code: var MediaInfo = new Array();
function OnEvent_MyMediaChange(NewMedia){
MediaInfo = parseMedia(NewMedia);
for(i in MediaInfo){
Debug.Trace(i+" - "+MediaInfo[i]);
}
}
function parseMedia(Media) {
var mediaExp = /^\\0([a-z]+)\\0([0-1])\\0(.*)\\0(.*)\\0(.*)\\0(.*)\\0(.*)\\0$/i;
if(typeof(Media) == "string" && mediaExp.test(Media)) {
var arr = new Array();
arr['Type'] = RegExp.$1;
arr['Enabled'] = RegExp.$2;
arr['Format'] = RegExp.$3;
arr['Title'] = RegExp.$4;
arr['Artist'] = RegExp.$5;
arr['Album'] = RegExp.$6;
arr['ContentId'] = RegExp.$7;
Debug.Trace(arr);
return arr;
} else {
return false;
}
}
That works perfectly
wewt! thanks -.-
RE: how to filter the music? by Spunky on 11-22-2006 at 12:00 AM
Whats the point in quoting the message before you if you're not going to refer to it or make a further point? Just type a normal reply if a quote isn't needed
|