Page 1 of 4

Script to fix dumb Zen MX playlist format

Posted: Sat Nov 14, 2009 12:11 pm
by stoffel
Some script coding in JScript.

Have fun ;-)

Code: Select all

// Fix stupid ZEN MX Bug: Playlists must define their tracks in 8.3 DOS style
// Convert every playlist <name> found in /playlist to <name>_mx. Old lists are not changed
// (c) Stefan Skopnik (sskopnik(at)web(dot)de)

/*
Insert in C:\Programme\MediaMonkey\Scripts\scripts.ini
[FixZenMXPlaylist]
FileName=FixZenMXPlaylist.js
ProcName=FixZenMXPlaylist
Order=1
DisplayName=Fix dumb ZEN MX playlist
;DisplayName=Korrektur von ZEN MX Playlisten
Description=Fix dumb ZEN MX playlist
;Description=Korrektur von ZEN MX Playlisten
Language=JScript
ScriptType=0
*/

var	MyLang = 'de',     // Define your language: 'en' = English, 'de' = German
	OutDrive = "?",    // Define your Zen MX Drive or leave "?" to find device
	
	OutDir = "\\Playlist",
	Scriptname = "FixZenMXPlaylist.js",
	objFso = new ActiveXObject("Scripting.FileSystemObject"),
	objDic = new ActiveXObject("Scripting.Dictionary"),
	fc,
	fin,
	fout,
	orgfile,
	newfile,
	newfilearr = new Array();
	re = /\.m3u$/,
	re2 = /_mx\.m3u$/,
	re3 = /^#/,
	newsuff = "_mx",
	nrfiles = 0,
	C_ForReading = 1,
	Lang_rc = {
		'de' : {
			msg1 : "Folgende %1 neue Playlisten wurden im Verzeichnis %3 erstellt:\n\n",
			msg2 : "Folgende %1 neue Playliste wurde im Verzeichnis %3 erstellt:\n\n",
			msg4 : "Kein Zen MX Spieler gefunden!",
			msg5 : "Zen MX Spieler in Laufwerk %1 gefunden!\nPlaylisten konvertieren?"
		},
		'en' : {
			msg1 : "%1 new playlists where created in directory %3:\n\n",
			msg2 : "%1 new playlist was created in directory %3:\n\n",
			msg4 : "No Zen MX Player found!",
			msg5 : "Found Zen MX Player in drive %1!\nConvert Playlists?"
		}
	},
	Lang = Lang_rc[MyLang];

// some  utillity functions
	
function sprintf() {
	var savearg = arguments;

	return savearg[0].replace(new RegExp("%(\\d+)","g"),
			    function ($0, $1, $2) { return savearg[$1]; }
		   );
}

function getDriveLetter(i) {
  var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
      s;
  s = str.charAt(i);
  return(s + ":");
}

function JS2VBArray(objJSArray) {
	objDic.RemoveAll();
    for (var i = 0; i < objJSArray.length; i++ ) {
        objDic.add(i,objJSArray[i]);
    }
    return objDic.Items();
}

function getShortPath(filespec, nodrive) {
var f = objFso.GetFile(filespec),
	ret = f.ShortPath;
	
	if (nodrive) ret = ret.substr(2);
	return(ret);
}

function convColltoArr(col) {
var ret = new Array();

	for (var e = new Enumerator(col), i = 0; !e.atEnd(); e.moveNext(), i++) {
		ret[i] = e.item();
	}
	return ret;
}

function getPath(fn) {
var stop = fn.lastIndexOf("\\");

	if (stop==-1) return "";
	return fn.slice(0,stop);
}

function getFilename(fn) {
var start = fn.lastIndexOf("\\");

	return fn.slice(++start);
}

function getFilenamePrefix(fn) {
var ret = getFilename(fn),
	stop = ret.lastIndexOf(".");
	
	if (stop==-1) return ret;
	return ret.slice(0,stop);
}

function getFilenameSuffix(fn) {
var ret = getFilename(fn),
	start = ret.lastIndexOf(".");
	
	if (start==-1) return "";
	return ret.slice(++start);
}

function genNewPlaylistname(filespec) {
	return getPath(filespec) + "\\" + getFilenamePrefix(filespec) + newsuff + "." + getFilenameSuffix(filespec);
}

function messageBox(s,t,b) {
	return SDB.MessageBox(s, t, JS2VBArray(b));
}

// ---

function FixZenMXPlaylist() {
var	ret,
	devlist,
	i;

	// find the Drive letter of Zen MX
	if (OutDrive == "?") {
		devlist = SDB.Device.ActiveDeviceList("USBSTOR\\Disk&Ven_Creative&Prod_ZEN_MX"); // You have to look into the registry!
		for (i = 0; i < devlist.Count;i++) {
			if (devlist.FriendlyName(i) == "Creative ZEN MX USB Device") {
				// messageBox(i + ": (" + devlist.DeviceID(i) + ") " + devlist.FriendlyName(i) + " " + devlist.DeviceInst(i) + " " + devlist.DriveLetterIndex(i), mtInformation, new Array(mbOk) );
				OutDrive = getDriveLetter(devlist.DriveLetterIndex(i));
			}			
		}
	}	
	if (OutDrive == "?") {
		messageBox(Lang.msg4, mtInformation, new Array(mbOk));
		return(-1);
	} else {
		ret = messageBox(sprintf(Lang.msg5, OutDrive), mtConfirmation, new Array(mbOk, mbCancel));
		if (ret == mrCancel) return (-2);
	}	
	
	objDir = objFso.GetFolder(OutDrive + OutDir);

	for (fc = new Enumerator(objDir.files); !fc.atEnd(); fc.moveNext()) {
		ele = fc.item();
		if (re.test(ele.Name) && !re2.test(ele.Name)) {
			nrfiles++;
			// WScript.Echo("File: " + ele.Path);

			orgfile = ele.Path;
			newfile = genNewPlaylistname(orgfile);
			newfilearr.push(getFilename(newfile));
			
			fin = objFso.OpenTextFile(orgfile, C_ForReading, false);
			fout = objFso.CreateTextFile(newfile, true);

			while (!fin.AtEndOfLine) {
				l = fin.ReadLine();
				if (!re3.test(l)) {
					sn = getShortPath(OutDrive + l, true);
					l = sn;
				}
				fout.WriteLine(l);

			}
			fin.Close();
			fout.Close();
		}
	}
	messageBox(sprintf(Lang[(nrfiles>1) ? 'msg1' : 'msg2'], nrfiles, OutDrive + OutDir) + newfilearr.join(", "), 
		mtInformation, new Array(mbOk)
	);
}

Re: Script to fix dumb Zen MX playlist format

Posted: Fri Jan 01, 2010 10:12 am
by stoffel
A new version for a new decade. Please delete <name>_mx.m3u files created with the former version and regenerate, because of the new naming schema.

01.01.2010 Fixes for W7, don't generate if newpl exists and is newer than orgpl, changed NewPlName

Installation:
1.) Copy this file to C:\<Program>\MediaMonkey\Scripts

2.) Append to file C:\<Program>\MediaMonkey\Scripts\scripts.ini:
[FixZenMXPlaylist]
FileName=FixZenMXPlaylist.js
ProcName=FixZenMXPlaylist
Order=1
DisplayName=Fix dumb ZEN MX playlist
;DisplayName=Korrektur von ZEN MX Playlisten
Description=Fix dumb ZEN MX playlist
;Description=Korrektur von ZEN MX Playlisten
Language=JScript
ScriptType=0

3.) Plugin Zen MX and create your PLs in MediaMonkey

4.) Send PL to 'My ZEN'

5.) Run this Script from Extras / Scripts / Fix dumb ZEN MX playlist

6.) Unplug ZEN MX

7.) Enjoy your MM PL on ZEN MX


Code: Select all

// Fix stupid ZEN MX Bug: Playlists must define their tracks in 8.3 DOS style
// Convert every playlist <name> found in /playlist to <name>_mx. Original ists are not changed
//
// (c) Stefan Skopnik (sskopnik(at)web(dot)de)
//
// 01.01.2010 Fixes for W7, don't generate if newpl exists and is newer than orgpl, changed NewPlName

/*
Installation:
1.) Copy this file to C:\<Program>\MediaMonkey\Scripts

2.) Append to file C:\<Program>\MediaMonkey\Scripts\scripts.ini:
[FixZenMXPlaylist]
FileName=FixZenMXPlaylist.js
ProcName=FixZenMXPlaylist
Order=1
DisplayName=Fix dumb ZEN MX playlist
;DisplayName=Korrektur von ZEN MX Playlisten
Description=Fix dumb ZEN MX playlist
;Description=Korrektur von ZEN MX Playlisten
Language=JScript
ScriptType=0

3.) Plugin Zen MX and create PLs in MediaMonkey

4.) Send PL to 'My ZEN'

5.) Run this Script from Extras / Scripts / Fix dumb ZEN MX playlist

6.) Unplug ZEN MX

7.) Enjoy your MM PL on ZEN MX
*/

var	MyLang = 'en',     		// Define your language: 'en' = English, 'de' = German

	OutDrive = "?",    		// Define your Zen MX Drive ('X:') or leave "?" to find device
	OutDir = "\\Playlist",  // Define location of PL on device
	Scriptname = "FixZenMXPlaylist.js",
	NewPlName = "mx_%1.%2", // Mask for new Playlist filenames, %1 is replaced with old filenameprefix, %2 is replaced with old filenamesuffix
							// Don't forget to modify re2 accordingly
	
	re = /\.m3u$/,			// RE for Filenames to be converted
	re2 = /mx_.*\.m3u$/,		// RE for Filenames NOT to be converted
	re3 = /^#/,
	objFso = new ActiveXObject("Scripting.FileSystemObject"),
	objDic = new ActiveXObject("Scripting.Dictionary"),
	C_ForReading = 1,
	Lang_rc = {
		'de' : {
			msg1 : "Folgende %1 neue Playlisten wurden im Verzeichnis %2 erstellt:\n\n",
			msg2 : "Folgende neue Playliste wurde im Verzeichnis %2 erstellt:\n\n",
			msg4 : "Kein Zen MX Spieler gefunden!",
			msg5 : "Zen MX Spieler in Laufwerk %1 gefunden.\nPlaylisten konvertieren?"
		},
		'en' : {
			msg1 : "%1 new playlists where created in directory %2:\n\n",
			msg2 : "%1 new playlist was created in directory %2:\n\n",
			msg4 : "No Zen MX Player found!",
			msg5 : "Found Zen MX Player in drive %1.\nConvert Playlists?"
		}
	},
	Lang = Lang_rc[MyLang];

// some utillity functions
	
function sprintf() {
var savearg = arguments;

	return savearg[0].replace(new RegExp("%(\\d+)","g"),
			    function ($0, $1, $2) { return savearg[$1]; }
		   );
}

function getDriveLetter(i) {
var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
	s;
	s = str.charAt(i);
	return(s + ":");
}

function JS2VBArray(objJSArray) {
	objDic.RemoveAll();
    for (var i = 0; i < objJSArray.length; i++ ) {
        objDic.add(i,objJSArray[i]);
    }
    return objDic.Items();
}

function getShortPath(filespec, nodrive) {
var f = objFso.GetFile(filespec),
	ret = f.ShortPath;
	
	if (nodrive) ret = ret.substr(2);
	return(ret);
}

function convColltoArr(col) {
var ret = new Array();

	for (var e = new Enumerator(col), i = 0; !e.atEnd(); e.moveNext(), i++) {
		ret[i] = e.item();
	}
	return ret;
}

function getPath(fn) {
var stop = fn.lastIndexOf("\\");

	if (stop==-1) return "";
	return fn.slice(0,stop);
}

function getFilename(fn) {
var start = fn.lastIndexOf("\\");

	return fn.slice(++start);
}

function getFilenamePrefix(fn) {
var ret = getFilename(fn),
	stop = ret.lastIndexOf(".");
	
	if (stop==-1) return ret;
	return ret.slice(0,stop);
}

function getFilenameSuffix(fn) {
var ret = getFilename(fn),
	start = ret.lastIndexOf(".");
	
	if (start==-1) return "";
	return ret.slice(++start);
}

function messageBox(s,t,barr) {
	return SDB.MessageBox(s, t, JS2VBArray(barr));
}

// ---

function FixZenMXPlaylist() {
var	fc,
	fin,
	fout,
	orgfile,
	newfile,
	newfilearr = new Array(),
	nrfiles = 0,
	ret,
	devlist,
	i,
	f_org,
	f_new;
	
	// Find the Drive letter of Zen MX
	// Well, I have no real idea what ActiveDeviceList is supposed to return. XP and W7 return complety different FriendlyNames. 
	// In W7 the second Drive is never returned.
	// So this is a rather dumb method: Just take the last entry by default, if you find the correct friendly name (XP) use it! 
	// This was tested with XP / W7 successfully
	if (OutDrive == "?") {
		devlist = SDB.Device.ActiveDeviceList("USBSTOR\\Disk&Ven_Creative&Prod_ZEN_MX"); // You have to look into the registry!
		for (i = 0; i < devlist.Count;i++) {
			//messageBox(i + ": (" + devlist.DeviceID(i) + ") " + devlist.FriendlyName(i) + " " + 
			//	devlist.DeviceInst(i) + " " + getDriveLetter(devlist.DriveLetterIndex(i)), mtInformation, new Array(mbOk) );
			OutDrive = getDriveLetter(devlist.DriveLetterIndex(i));
			if (devlist.FriendlyName(i) == "Creative ZEN MX USB Device") break;
		}
	}	
	if (OutDrive == "?") {
		messageBox(Lang.msg4, mtInformation, new Array(mbOk.toString())); // single num arg to array constructor sets array size!
		return(-1);
	} else {
		ret = messageBox(sprintf(Lang.msg5, OutDrive), mtConfirmation, new Array(mbOk, mbCancel));
		if (ret == mrCancel) return (-2);
	}	
	
	objDir = objFso.GetFolder(OutDrive + OutDir);

	for (fc = new Enumerator(objDir.files); !fc.atEnd(); fc.moveNext()) {
		ele = fc.item();
		if (re.test(ele.Name) && !re2.test(ele.Name)) {
			// WScript.Echo("File: " + ele.Path);

			orgfile = ele.Path;
			newfile = getPath(orgfile) + "\\" + sprintf (NewPlName, getFilenamePrefix(orgfile), getFilenameSuffix(orgfile));
			
			// Don't generate if newfile already exists and is newer than oldfile
			if (objFso.FileExists(newfile)) {
				f_org = objFso.GetFile(orgfile);
				f_new = objFso.GetFile(newfile);
				if (f_new.DateLastModified > f_org.DateLastModified) continue;
			}
			nrfiles++;
			newfilearr.push(getFilename(newfile));
			
			fin = objFso.OpenTextFile(orgfile, C_ForReading, false);
			fout = objFso.CreateTextFile(newfile, true);

			while (!fin.AtEndOfLine) {
				l = fin.ReadLine();
				if (!re3.test(l)) {
					sn = getShortPath(OutDrive + l, true);
					l = sn;
				}
				fout.WriteLine(l);

			}
			fin.Close();
			fout.Close();
		}
	}
	messageBox(sprintf(Lang[(nrfiles!=1) ? 'msg1' : 'msg2'], nrfiles, OutDrive + OutDir) + newfilearr.join(", "), 
		mtInformation, new Array(mbOk.toString())
	);
	return (0);
}

Re: Script to fix dumb Zen MX playlist format

Posted: Thu Jan 07, 2010 3:48 pm
by LL
Hei!

First of all, great work on the script! Thanks for that.

However, it doesn't work for me :(. When I tried the newest script, I got an error about an incorrect path at line 178, but there is no path at that line.

Tried it with the earlier script on this page, but then it tells me my player is not connected.

I'm quite technical, but not even close to you lot here... i know some basic (html/php) coding, but no javascript. Can someone help me please?

Knocking on creative's door is of no use unfortunately.

Cheers!

Re: Script to fix dumb Zen MX playlist format

Posted: Mon Jan 11, 2010 7:47 am
by stoffel
LL wrote:Hei!

First of all, great work on the script! Thanks for that.

However, it doesn't work for me :(. When I tried the newest script, I got an error about an incorrect path at line 178, but there is no path at that line.

Tried it with the earlier script on this page, but then it tells me my player is not connected.

I'm quite technical, but not even close to you lot here... i know some basic (html/php) coding, but no javascript. Can someone help me please?

Knocking on creative's door is of no use unfortunately.

Cheers!
Sorry to hear that the script doesn't work for you.

The older version did work under Windows XP only, so don't bother with it.

Does the actual Version tell you "Found Zen MX Player in drive X: ."? Is the drive letter correct?
Ok, then have a look at the ZEN Player Drive X:. Is there a Directory called "Playlist" ? If not, create it, then try again

Well, I thought this Directory is present on every ZEN MX device. Maybe that's not true.

Please tell me if you where successful

Bye

Re: Script to fix dumb Zen MX playlist format

Posted: Tue Jan 12, 2010 11:49 am
by JBille
Hi Stoffel and all.

I made this work on my Creative Mozaic Zen EZ300 with only a few minor changes in the code (defined the OutDrive to be I: and OutDir to \Playlist).
This would not have been possible if it weren't for your in code explanations since my only coding experience comes from writing in LaTeX 8)

Well done and many thanks. It has made playlist creation much easyer

Re: Script to fix dumb Zen MX playlist format

Posted: Tue Jan 12, 2010 5:49 pm
by Guest
JBille wrote:Hi Stoffel and all.

I made this work on my Creative Mozaic Zen EZ300 with only a few minor changes in the code (defined the OutDrive to be I: and OutDir to \Playlist).
This would not have been possible if it weren't for your in code explanations since my only coding experience comes from writing in LaTeX 8)

Well done and many thanks. It has made playlist creation much easyer
To my experience "coding" in LaTeX is a much more sophisticated task, than doing some JScripting :wink:
Didn't know that other Creative models suffer from same desease :o

Re: Script to fix dumb Zen MX playlist format

Posted: Wed Jan 13, 2010 2:33 am
by LL
Hei Stoffel!

Thanks for your response. Do I understand correctly that I have to use the newer script? Because that went fine untill I tried running it (I then got error about incorrect path at line 178).

Well, I'll try again when I'm home and will put the correct drive. There is a directory called playlist, but will double check that too.

If it doesn't work, then I'll put a printscreen here, again, I love you all for helping me!

Cheers!

P.S. Just got a response regarding this from Zen:
"Please be informed that you can not transfer playlists create by other
third-party software to the ZEN MX player.

You had to create the playlist using Creative Centrale and then transfer
it to your player."

How stupid is this?

Re: Script to fix dumb Zen MX playlist format

Posted: Thu Jan 14, 2010 5:54 pm
by stoffel
New version 1.02 with some better sanity checking and without runtime errors ;-)

Installation:
1.) Copy this file to C:\<Program>\MediaMonkey\Scripts\FixZenMXPlaylist.js

2.) Append to file C:\<Program>\MediaMonkey\Scripts\scripts.ini:
[FixZenMXPlaylist]
FileName=FixZenMXPlaylist.js
ProcName=FixZenMXPlaylist
Order=1
DisplayName=Fix dumb ZEN MX playlist
;DisplayName=Korrektur von ZEN MX Playlisten
Description=Fix dumb ZEN MX playlist
;Description=Korrektur von ZEN MX Playlisten
Language=JScript
ScriptType=0

3.) Plugin Zen MX and create PLs in MediaMonkey

4.) Send PL to 'My ZEN'

5.) Run this Script from Extras / Scripts / Fix dumb ZEN MX playlist

6.) Unplug ZEN MX

7.) Enjoy your MM PL on ZEN MX. You find them under '@ <ORGNAME>.m3u

Code: Select all

// Fix stupid ZEN MX Bug: Playlists must define their tracknames in 8.3 DOS style
// Convert every playlist '<name>.m3u' found in /playlist to '@ <name>.m3u'. Original files are not changed
//
// (c) Stefan Skopnik (sskopnik(at)web(dot)de)
//
// 01.01.2010 fixes for W7, don't generate if newpl exists and is newer than orgpl, changed NewPlName
// 14.01.2010 scan for drive modified, test for dir exist, more detailed messages, change naming schema again to: '@ <name>.m3u'

/*
Installation:
1.) Copy this file to C:\<Program>\MediaMonkey\Scripts\FixZenMXPlaylist.js

2.) Append to file C:\<Program>\MediaMonkey\Scripts\scripts.ini:
[FixZenMXPlaylist]
FileName=FixZenMXPlaylist.js
ProcName=FixZenMXPlaylist
Order=1
DisplayName=Fix dumb ZEN MX playlist
;DisplayName=Korrektur von ZEN MX Playlisten
Description=Fix dumb ZEN MX playlist
;Description=Korrektur von ZEN MX Playlisten
Language=JScript
ScriptType=0

3.) Plugin Zen MX and create PLs in MediaMonkey

4.) Send PL to 'My ZEN'

5.) Run this Script from Extras / Scripts / Fix dumb ZEN MX playlist

6.) Unplug ZEN MX

7.) Enjoy your MM PL on ZEN MX. You find them under '@ <ORGNAME>.m3u
*/

var	MyLang = 'en',     					// Define your language: 'en' = English, 'de' = German

	OutDrive = "?",    					// Define your Zen MX Drive ('X:') or leave "?" to let script find device
	OutDir = "\\Playlist",  			// Define location of PL on device
	Scriptname = "FixZenMXPlaylist.js",
	Version = "1.02"
	NewPlName = "@ %1.%2", 				// Mask for new Playlist filenames, %1 is replaced with old filenameprefix, %2 is replaced with old filenamesuffix
										// Don't forget to modify re_exclfn accordingly
	
	re_exclfn 	= /@.*\.m3u$/,			// RE for Filenames to be EXCLUDED from conversion (must match NewPlName)
	
	re_inclfn 	= /\.m3u$/,				// RE for Filenames to be INCLUDED into conversion
	re_ignoreln = /^#/,					// RE for lines to be ignored during conversion
	
	objFso = new ActiveXObject("Scripting.FileSystemObject"),
	objDic = new ActiveXObject("Scripting.Dictionary"),
	C_ForReading = 1,
	Lang_rc = {
		'de' : {
			msg0 : "Keine Playliste im Verzeichnis '%2' erstellt.",
			msg1 : "Folgende %1 neue Playlisten wurden im Verzeichnis '%2' erstellt:\n\n",
			msg2 : "Folgende neue Playliste wurde im Verzeichnis '%2' erstellt:\n\n",
			msg4 : "Kein Zen MX Spieler gefunden!",
			msg5 : "Zen MX Spieler in Laufwerk '%1' gefunden.\nPlaylisten konvertieren?",
			msg6 : "Unterverzeichnis '%1' auf Laufwerk '%2' nicht gefunden!",
			msg7 : "Zen MX Spieler gefunden, aber Unterverzeichnis '%1' nicht gefunden!"
		},
		'en' : {
			msg0 : "No playlist created in directory '%2'.",
			msg1 : "%1 new playlists where created in directory '%2':\n\n",
			msg2 : "%1 new playlist was created in directory '%2':\n\n",
			msg4 : "No Zen MX Player found!",
			msg5 : "Found Zen MX Player in drive '%1'.\nConvert Playlists?",
			msg6 : "Subdirectory '%1' missing on drive '%2'!",
			msg7 : "Zen MX Player found, but subdirectory '%1' missing!"
		}
	},
	Lang = Lang_rc[MyLang];

// some utillity functions
	
function sprintf() {
var savearg = arguments;

	return savearg[0].replace(new RegExp("%(\\d+)","g"),
			    function ($0, $1, $2) { return savearg[$1]; }
		   );
}

function getDriveLetter(i) {
var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
	s;
	s = str.charAt(i);
	return(s + ":");
}

function JS2VBArray(objJSArray) {
	objDic.RemoveAll();
    for (var i = 0; i < objJSArray.length; i++ ) {
        objDic.add(i,objJSArray[i]);
    }
    return objDic.Items();
}

function getShortPath(filespec, nodrive) {
var f = objFso.GetFile(filespec),
	ret = f.ShortPath;
	
	if (nodrive) ret = ret.substr(2);
	return(ret);
}

function convColltoArr(col) {
var ret = new Array();

	for (var e = new Enumerator(col), i = 0; !e.atEnd(); e.moveNext(), i++) {
		ret[i] = e.item();
	}
	return ret;
}

function getPath(fn) {
var stop = fn.lastIndexOf("\\");

	if (stop==-1) return "";
	return fn.slice(0,stop);
}

function getFilename(fn) {
var start = fn.lastIndexOf("\\");

	return fn.slice(++start);
}

function getFilenamePrefix(fn) {
var ret = getFilename(fn),
	stop = ret.lastIndexOf(".");
	
	if (stop==-1) return ret;
	return ret.slice(0,stop);
}

function getFilenameSuffix(fn) {
var ret = getFilename(fn),
	start = ret.lastIndexOf(".");
	
	if (start==-1) return "";
	return ret.slice(++start);
}

function messageBox(s,t,barr) {
	return SDB.MessageBox(s, t, JS2VBArray(barr));
}

// ---

function FixZenMXPlaylist() {
var	fc,
	fin,
	fout,
	orgfile,
	newfile,
	newfilearr = new Array(),
	nrfiles = 0,
	ret,
	devlist,
	i,
	f_org,
	f_new,
	actmsg;
	
	/*
	 * Find the Drive letter of Zen MX
	 * Well, I have no real idea what ActiveDeviceList is supposed to return. XP and W7 return complety different FriendlyNames. 
	 * In W7 the second Drive is never returned.
	 * So this is a rather dumb method:
	 * 
	 * Scan all Drives with correct vendor&Product Name.
	 * 		If you find drive with existing subdir <OutDir>  use it!
	 * 		else give up!
	 * 		
	 * This was tested with XP / W7 successfully
	 */
	if (OutDrive == "?") {
		devlist = SDB.Device.ActiveDeviceList("USBSTOR\\Disk&Ven_Creative&Prod_ZEN_MX"); // You have to look into the registry!
		for (i = 0; i < devlist.Count;i++) {
			OutDrive = "!";
			//messageBox(i + ": (" + devlist.DeviceID(i) + ") " + devlist.FriendlyName(i) + " " + 
			//	devlist.DeviceInst(i) + " " + getDriveLetter(devlist.DriveLetterIndex(i)), mtInformation, new Array(mbOk) );
			TestOutDrive = getDriveLetter(devlist.DriveLetterIndex(i));
			// if (devlist.FriendlyName(i) == "Creative ZEN MX USB Device") break;
			if (objFso.FolderExists(TestOutDrive + OutDir)) {
				OutDrive = TestOutDrive;
				break;
			}
		}
	}	
	switch (OutDrive) {
		case "?":	messageBox(Lang.msg4, mtError, new Array(mbOk.toString())); // single num arg to array constructor sets array size!
					return(-1);
		case "!":	messageBox(sprintf(Lang.msg7, OutDir), mtError, new Array(mbOk.toString()));
					return(-1);
		default:	ret = messageBox(sprintf(Lang.msg5, OutDrive), mtConfirmation, new Array(mbOk, mbCancel));
					if (ret == mrCancel) return (-2);
	}	
	
	// Ok, we want this folder! Else exit
	if (!objFso.FolderExists(OutDrive + OutDir)) {
		messageBox(sprintf(Lang.msg6, OutDir, OutDrive), mtError, new Array(mbOk.toString())); // single num arg to array constructor sets array size!
		return(-1);
	}	

	objDir = objFso.GetFolder(OutDrive + OutDir);

	for (fc = new Enumerator(objDir.files); !fc.atEnd(); fc.moveNext()) {
		ele = fc.item();
		if (re_inclfn.test(ele.Name) && !re_exclfn.test(ele.Name)) {
			// WScript.Echo("File: " + ele.Path);

			orgfile = ele.Path;
			newfile = getPath(orgfile) + "\\" + sprintf (NewPlName, getFilenamePrefix(orgfile), getFilenameSuffix(orgfile));
			
			// Don't generate if newfile already exists and is newer than oldfile
			if (objFso.FileExists(newfile)) {
				f_org = objFso.GetFile(orgfile);
				f_new = objFso.GetFile(newfile);
				if (f_new.DateLastModified > f_org.DateLastModified) continue;
			}
			nrfiles++;
			newfilearr.push(getFilename(newfile));
			
			fin = objFso.OpenTextFile(orgfile, C_ForReading, false);
			fout = objFso.CreateTextFile(newfile, true);

			while (!fin.AtEndOfLine) {
				l = fin.ReadLine();
				if (!re_ignoreln.test(l)) {
					sn = getShortPath(OutDrive + l, true);
					l = sn;
				}
				fout.WriteLine(l);

			}
			fin.Close();
			fout.Close();
		}
	}
	switch (nrfiles) {
		case 0:		actmsg = 'msg0'; break
		case 1: 	actmsg = 'msg2'; break
		default:	actmsg = 'msg1'; 
	}	
	messageBox(sprintf(Lang[actmsg], nrfiles, OutDrive + OutDir) + newfilearr.join(", "), 
		mtInformation, new Array(mbOk.toString())
	);
	return (0);
}

Re: Script to fix dumb Zen MX playlist format

Posted: Sun Jan 17, 2010 3:51 pm
by LL
I love you all...

Dear dear Stoffel, the latest script you uploaded works perfectly and I finally have a working playlist! Can't wait to sync the rest :).

Thank you Stoffel and all others here, you guys are amazing. Keep up the great work!

If you live in Northern Europe then I should get you a pint, wine, coke, coffee or tea :D.

Again, thanks a million! Not only to Stoffel for the great script, but to all of you spending your time on fixing bugs of other companies. I'm impressed!

Re: Script to fix dumb Zen MX playlist format

Posted: Wed Mar 17, 2010 5:31 am
by samsimilian
Amazing! Thank you so much! the playlist problem was a big drawback fo the zen mx!

Re: Script to fix dumb Zen MX playlist format

Posted: Sun Mar 28, 2010 8:36 am
by Geronimo72
Hei!
Thx for great tip - it works!
Had a bit of trouble in the beginning. After some hazle I found the there was one song on one playlist that caused an error for me. The song was Free Bird by Lynyrd Skynyrd. The ablum title is "(Pronounced 'Lĕh-'nérd 'Skin-'nérd)". Since I have music organized in album-folders, I guess the this folder/album name is hard to read for the program... (?).

Re: Script to fix dumb Zen MX playlist format

Posted: Thu Apr 08, 2010 3:56 am
by stoffel
Geronimo72 wrote:Hei!
Thx for great tip - it works!
Had a bit of trouble in the beginning. After some hazle I found the there was one song on one playlist that caused an error for me. The song was Free Bird by Lynyrd Skynyrd. The ablum title is "(Pronounced 'Lĕh-'nérd 'Skin-'nérd)". Since I have music organized in album-folders, I guess the this folder/album name is hard to read for the program... (?).
I don't see why the Artists name should be a problem for the Conversion program. Maybe you could post part of the original PL here for testing. When sending PL to device MM copies all songs in to a predefined folder structure <Artist>/<Album>/<Title>. The PL is modified accordingly. Maybe there is a problem with the MP3-Tags of that song.

Re: Script to fix dumb Zen MX playlist format

Posted: Thu Apr 08, 2010 4:05 am
by stoffel
stoffel wrote:
Geronimo72 wrote:Hei!
Thx for great tip - it works!
Had a bit of trouble in the beginning. After some hazle I found the there was one song on one playlist that caused an error for me. The song was Free Bird by Lynyrd Skynyrd. The ablum title is "(Pronounced 'Lĕh-'nérd 'Skin-'nérd)". Since I have music organized in album-folders, I guess the this folder/album name is hard to read for the program... (?).
I don't see why the Artists name should be a problem for the Conversion program. Maybe you could post part of the original PL here for testing. When sending PL to device MM copies all songs in to a predefined folder structure <Artist>/<Album>/<Title>. The PL is modified accordingly. Maybe there is a problem with the MP3-Tags of that song.
Sorry, I did't get it at first ;-)
Of course there could be a problem with Album name "Pronounced 'Lĕh-'nérd 'Skin-'nérd" definitely!
Will test that...

Re: Script to fix dumb Zen MX playlist format

Posted: Thu Jun 03, 2010 5:28 am
by Alain Van Ruys.
I want to mention that this scipt work nicely! Thank a lot to the writer!
It gives me an error on a certain line, and the question i to know if this is the order of the playlist or in the script?
A great thank to Stoffel anyway.

Re: Script to fix dumb Zen MX playlist format

Posted: Fri Jun 11, 2010 7:23 am
by stoffel
Alain Van Ruys. wrote:I want to mention that this scipt work nicely! Thank a lot to the writer!
It gives me an error on a certain line, and the question i to know if this is the order of the playlist or in the script?
A great thank to Stoffel anyway.
Need some more information! What error message, what line, what OS, what playlist?