View Single Post
  #156  
Old 04-15-2009, 05:18 PM
streamsteam
 
Posts: n/a
Default

Re: freeme2 - free software to remove DRM protection from Windows Media WMA,WMV,ASF f


Despite the great tutorials I prefer a script to automate the DRM removal. Check out the attached script and see if it works for you. The script must be renamed to "pilatesdrm.js".
Code:
// Put this script somewhere on your system together with FreeMe2.exe and
// dmrdbg.exe. Run drmdbg to generate the keys and then run the script.
// The script will not enter sub-directories.

function ReadIni()
{
  var ForReading = 1;
  var line;
  var fso = WScript.CreateObject("Scripting.FileSystemObject");
  var dso = WScript.CreateObject("Scripting.Dictionary");
  var ts = fso.OpenTextFile("drmdbg.ini", ForReading);
  var key, w, subkey, val;
  while (!ts.AtEndOfStream) {
    line = ts.ReadLine();
    if (line.substr(0, 1) == "[" && line.substr(line.length - 1, 1) == "]") {
      key = line.substr(1, line.length - 2);
      dso.add(key, WScript.CreateObject("Scripting.Dictionary"));
    }
    else {
      w = line.split("=");
      if (w.length == 2) {
	subkey = w[0];
	val = w[1];
	if (subkey == "path") {
	  // val = val.replace(/\\/g, '\\\\');
	  // val = val.replace(/ /g, '\\ ');
	  // WScript.Echo(key + "," + subkey +  "," + val);
	}
	dso.item(key).item(subkey) = val;
	// WScript.Echo(key + "," + subkey +  "," + val);
      }
    }
  }
  return dso;
}


function ReadKeys(ini)
{
  var ForReading = 1;
  var line;
  var fso = WScript.CreateObject("Scripting.FileSystemObject");
  var dso = WScript.CreateObject("Scripting.Dictionary");
  var kpath = ini.item("drm2dir").item("path");
  var ts;
  var sid, kid;
  if (ini.item("MakeDRM2Dir").item("0_or_1") == 1)
    ts = fso.OpenTextFile(kpath + "DRM2\\DRM2.KEY", ForReading);
  else
    ts = fso.OpenTextFile(kpath + "DRM2.KEY", ForReading);
  while (!ts.AtEndOfStream) {
    line = ts.ReadLine();
    if (line.substr(0, 5) == "<KID>") {
      kid = line.substr(5).substr(0, line.length - 11);
    }
    if (line.substr(0, 5) == "<SID>") {
      sid = line.substr(5).substr(0, line.length - 11);
      dso.add(kid, sid);
      // WScript.Echo(kid + "," + sid);
    }
  }
  ts.Close();
  return dso;
}


function ReadFiles(ini, dso)
{
  var line, lines, fname;
  var sso = WScript.CreateObject("WScript.Shell");
  var fso = WScript.CreateObject("Scripting.FileSystemObject");
  var ds = fso.GetFolder(ini.item("wmvdir").item("path"));
  var fc = new Enumerator(ds.files);
  var spath = WScript.ScriptFullName;
  spath = spath.substr(0, spath.length - WScript.ScriptName.length);
  var cmd = spath + "FreeMe2.exe -s ";
  var se;
  var sid, kid;
  lines = new Array();
  while (!fc.atEnd()) {
    fname = "" + fc.item();
    if (fname.substr(fname.length - 4, 4).toLowerCase() == ".wma") {
      lines.push("File: " + fname);
      // Get KID
      se = sso.Exec(cmd + '"' + fname + '"');
      se.StdIn.WriteLine("");
      se.StdIn.WriteLine("");
      line = se.StdErr.ReadLine();
      while (se.Status == 0)
	WScript.Sleep(10);
      if (line.substr(0, 9) == "Found KID") {
	kid = line.substr(11, 24);
	if (dso.Exists(kid)) {
	  sid = dso.item(kid);
	  se = sso.Exec(cmd + '"' + fname + '"');
	  se.StdIn.WriteLine(sid);
	  line = "";
	  while (!se.StdErr.AtEndOfStream)
	    line = se.StdErr.ReadLine();
	  while (se.Status == 0)
	    WScript.Sleep(10);
	  line = line.split("\r");
	  lines.push(line[line.length - 2]);
	}
	else {
	  lines.push("KID " + kid + " not found");
	}
      }
      else {
	lines.push(line);
      }
    }
    fc.moveNext();
  }
  WScript.Echo(lines.join("\n"));
}


var ini;
var keys;
ini = ReadIni();
keys = ReadKeys(ini);
ReadFiles(ini, keys);
Attached Files
File Type: txt pilatesdrm.js.txt (3.4 KB, 0 views)
Reply With Quote