Commits

Josep Batalle committed 8d39c3b Merge

Merged in develop (pull request #1)

Version 1.2

Comments (0)

Files changed (2)

     p.waitForFinished()
     var Response = p.readAllStandardOutput();
     var textStream = new QTextStream(Response, QIODevice.ReadOnly);
-    var checkPython = textStream.readAll();
-    if (checkPython) return true;
+    var checkCurl = textStream.readAll();
+    if (checkCurl) return true;
     else false;
 }
 
-function executeScript(type) {
-    Config["gpUserID"] = Amarok.Script.readConfig("gpUserID", "");
-    Config["gpPass"] = Amarok.Script.readConfig("gpPass", "");
-    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] = nameScript;
-    args[1] = "getList";
-    args[2] = Config["gpUserID"];
-    args[3] = Config["gpPass"];
+function doCurl(args) {
     var p = new QProcess();
-    p.setWorkingDirectory(dirScript);
-    p.start("sh", args, QIODevice.ReadOnly);
-    p.waitForFinished();
+    p.setWorkingDirectory(Amarok.Info.scriptPath());
+    p.start("curl", args, QIODevice.ReadOnly);
+    p.waitForFinished()
     var Response = p.readAllStandardOutput();
     var textStream = new QTextStream(Response, QIODevice.ReadOnly);
-    var tinyURL = textStream.readAll();
-    return tinyURL;
+    return textStream.readAll();
+}
+
+function getStreamByCurl(args) {
+    var p = new QProcess();
+    p.setWorkingDirectory(Amarok.Info.scriptPath());
+    p.start("curl", args, QIODevice.ReadOnly);
+    p.waitForFinished()
+    return p.readAllStandardOutput();
 }
 
-function getUrl(id) {
-    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"; //getUrl
+function curlAuth() {
     var args = new Array();
-    args[0] = nameScript;
-    args[1] = "getUrlSong";
-    args[2] = id;
+    var clientLoginUrl = "https://www.google.com/accounts/ClientLogin";
+    var email = Config["gpUserID"];
+    var password = Config["gpPass"];
 
-    var p = new QProcess();
-    p.setWorkingDirectory(dirScript);
-    p.start("sh", args, QIODevice.ReadOnly);
-    p.waitForFinished();
-    var Response = p.readAllStandardOutput();
+    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 authResponse = doCurl(args);
+    /*
+    var auth = authResponse;
+    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 = authResponse.match(/SID=([\s\S]*?)LSID=([\s\S]*?)Auth=([\s\S]*)/)
+    var SID = m[1];
+    var LSID = m[2];
+    var Auth = m[3];
+    return Auth;
+}
+
+function listSongs(AuthToken) {
+    var args = new Array();
+    Amarok.debug(AuthToken);
+    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 Response = getStreamByCurl(args);
     var textStream = new QTextStream(Response, QIODevice.ReadOnly);
     var tinyURL = textStream.readAll();
-    return tinyURL;
+    var listSongs = tinyURL;
+    //    Amarok.debug(tinyURL);
+    Amarok.debug(Amarok.Info.scriptPath());
+    var file = new QFile(Amarok.Info.scriptPath() + "/ListSongs.json");
+    file.open(QIODevice.WriteOnly);
+    file.write(Response);
+    file.close();
+}
+
+function getCookie(type) {
+    var email = Config["gpUserID"];
+    var password = Config["gpPass"];
+
+    var args = new Array();
+    args[0] = "-b";
+    args[1] = "cookie.txt";
+    args[2] = "-c";
+    args[3] = "cookie.txt";
+    args[4] = "https://accounts.google.com/ServiceLogin?service=sj";
+
+    var authResponse = doCurl(args);
+    var auth = authResponse;
+    var re = new RegExp('id="dsh" value="(.*)"', "g");
+    var myArray = auth.match(re);
+    var dsh = myArray[0].split('value="');
+    var dsh = dsh[1].split('"');
+    Amarok.debug(dsh[0]);
+
+    var re = new RegExp('  value="(.*)"', "g");
+    var myArray = auth.match(re);
+    var galx = myArray[0].split('value="');
+    var galx = galx[1].split('"');
+    Amarok.debug(galx[0]);
+
+    var DSH = dsh[0];
+    var GALX = galx[0];
+    getCookie2(DSH, GALX);
 }
 
+function getCookie2(DSH, GALX) {
+    var email = Config["gpUserID"];
+    var password = Config["gpPass"];
+    var args = new Array();
+    args[0] = "-b";
+    args[1] = "cookie.txt";
+    args[2] = "-c";
+    args[3] = "cookie.txt";
+    args[4] = "-d";
+    args[5] = "service=sj&dsh=" + DSH + "&GALX=" + GALX + "&pstMsg=1&dnConn=&checkConnection=youtube%3A138%3A1&checkedDomains=youtube&timeStmp=&secTok=&Email=" + email + "&PersistentCookie=no&Passwd=" + password + "&signIn=Sign+in";
+    args[6] = "-X";
+    args[7] = "POST";
+    args[8] = "https://accounts.google.com/ServiceLoginAuth";
+
+    var authResponse = doCurl(args);
+    var auth = authResponse;
+}
+
+function getSong(songId) {
+    var dirScript = ".kde4/share/apps/amarok/scripts/google_music/"; //~/Documents by default
+
+    var args = new Array();
+    args[0] = "-b";
+    args[1] = "cookie.txt";
+    args[2] = "-c";
+    args[3] = "cookie.txt";
+    args[4] = "https://music.google.com/music/play?u=0&songid=" + songId + "&pt=e";
+
+    var authResponse = doCurl(args, dirScript);
+    var song = (new Function("return " + authResponse))();
+    Amarok.debug(song.url);
+    return song.url;
+}
 
 function ImportJsonFile(json_file) {
-    if(json_file != null){
-    	eval("var JSON_obj = " + ReadTextFile(json_file));
-    	return JSON_obj;
-    }
-    else{
-    	return null;    	
+    if (json_file != null) {
+        eval("var JSON_obj = " + ReadTextFile(json_file));
+        return JSON_obj;
+    } else {
+        return null;
     }
 }
 
 var delayedArgs = null;
 var update = true;
 
-//var myRadioService = new RadioService("RADIO SERVICE", "aaa", "HTML DEscription", "aaaaaa", "Message");
 var myRadioService = new RadioService("Google Music SERVICE", "", "Listen your uploaded Music!", "", "You need a Google Music Account");
 var categoryName = "Google Music";
 var categoryImageFullPath = ScriptBaseDir() + "/Defaults/Category.default.image.png";
     onPopulating(delayedArgs[0], delayedArgs[1], delayedArgs[2]);
 }
 
-
 function GoogleMusicforAmarok() {
     ScriptableServiceScript.call(this, "Google Music for Amarok", 2, "Songs allocated in Google music", "GoogleMusic2", false);
 }
 }
 
 function onPopulating(level, callbackData, filter) {
+	if(!detectCurl){
+		Amarok.alert("Curl is not installed in the system!");
+		return;
+		}
     if (update == true) {
         delayedArgs = [level, callbackData, filter];
         newItems();
     var google_for_amarok = "Google Music";
     if (Amarok.Playlist.trackAt(row).album == google_for_amarok) {
         //  Amarok.alert(Amarok.Playlist.trackAt(row).album);
-        var uri = getUrl(Amarok.Playlist.trackAt(row).path);
+//        var uri = getUrl(Amarok.Playlist.trackAt(row).path);
+        var uri = getSong(Amarok.Playlist.trackAt(row).path);
+
         uri = uri.replace(/[\n\r]/g, ''); //delete carrier return
         Amarok.debug(uri);
         Amarok.Playlist.addMedia(new QUrl(uri));
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.