Commits

Josep Batalle committed 33a4dd7

ListSong functions and get Auth using only javascript! Implemented

Comments (0)

Files changed (2)

     update = false;
     newItems();
     if(state == '')
-      var state = curl("option1);
+      var state = curl("option1");
     if(state != '')
       Amarok.alert("Your music list is updated... Restart Amarok please.");
 }
     else false;
 }
 
-function curl(type){
+function curlAuth(type){
+  type="default";
    if(type == "default")
       var dirScript = ".kde4/share/apps/amarok/scripts/google_music/"; //~/Documents by default
     else
     var args = new Array();
     var clientLoginUrl="https://www.google.com/accounts/ClientLogin";
   var service="sj";
-  var email = Config["gpUserID"];
-  var password = Config["gpPass"];
-    args[0] = clientLoginUrl+' --data-urlencode Email="'+email+'" --data-urlencode Passwd="'+password+'" -d accountType=GOOGLE -d service=sj';
-        
+  var email = Config["gpUserID"];//jbatalle3@gmail.com
+  var password = Config["gpPass"];//prrlzmnu
+  
+//   args[0] = clientLoginUrl+" --data-urlencode Email="+email+" --data-urlencode Passwd="+password+" -d accountType=GOOGLE -d service=sj";
+    args[0] = clientLoginUrl;
+    args[1] = "--data-urlencode";
+    args[2] = "Email="+email;
+    args[3] = "--data-urlencode";
+    args[4] = "Passwd="+password;
+    args[5] = "-d";
+    args[6] = "accountType=GOOGLE";
+    args[7] = "-d";
+    args[8] = "service=sj";
     var p = new QProcess();
     p.setWorkingDirectory(dirScript);
     p.start("curl", args, QIODevice.ReadOnly);
     p.waitForFinished()
     var Response = p.readAllStandardOutput();
     var textStream = new QTextStream(Response, QIODevice.ReadOnly);
-    var checkPython = textStream.readAll();
-    if (checkPython) return true;
-    else false;
+    var tinyURL = textStream.readAll();
+    var authResponse = tinyURL;
+    Amarok.debug(tinyURL);
+    var auth = tinyURL;
+var re = new RegExp("SID=(.+)", "g");
+var myArray = auth.match(re);
+var SID = myArray[0].split("SID=");
+var LSID = myArray[1].split("SID=");
+Amarok.debug(SID[1]);
+Amarok.debug(LSID[1]);
+
+m = auth.match(/SID=([\s\S]*?)LSID=([\s\S]*?)Auth=([\s\S]*)/)
+var SID = m[1];
+var LSID = m[2];
+var Auth = m[3];
+
+}
+
+function listSongs(){
+	curl --header "Authorization: GoogleLogin auth=${authToken}" https://www.googleapis.com/sj/v1beta1/tracks > ListSongs.json
+	type="default";
+   if(type == "default")
+      var dirScript = ".kde4/share/apps/amarok/scripts/google_music/"; //~/Documents by default
+    else
+      var dirScript = "../.kde4/share/apps/amarok/scripts/google_music/"; //~/Documents by default other systems
+    var nameScript = "google_music.sh";
+  var args = new Array();
+  
+    args[0] = "--header";
+    args[1] = "Authorization: GoogleLogin auth="+AuthToken;
+    args[2] = "https://www.googleapis.com/sj/v1beta1/tracks";
+args[3] = ">";
+    args[4] = "ListSongs.json";
+
+    var p = new QProcess();
+    p.setWorkingDirectory(dirScript);
+    p.start("curl", args, QIODevice.ReadOnly);
+    p.waitForFinished()
+    var Response = p.readAllStandardOutput();
+    var textStream = new QTextStream(Response, QIODevice.ReadOnly);
+    var tinyURL = textStream.readAll();
+    var listSongs = tinyURL;
+    Amarok.debug(tinyURL);
+    
+    var file = new QFile(".kde4/share/apps/amarok/scripts/google_music/ListSongs.json");
+file.open(QIODevice.WriteOnly);
+     file.write(Response);
+     file.close();
 }
 
 function executeScript(type) {