Commits

Josep Batalle committed 2b3aadf

Version 1.3. Added search bar, solved problems with tokens and list of songs

  • Participants
  • Parent commits 12d1cce

Comments (0)

Files changed (5)

  *		This Script allows you to listen the music allocated in google
  *		music account using Amarok
  *
- * Copyright (C) 
+ * Copyright (C)
  *
  *  (C)  2013 Josep Batalle Oronich <jbatalle3@gmail.com>
  *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
- * Version: 1.2
+ * Version: 1.2.1
  */
-
 var Config = Array();
 var helpWindow = new helpWindow();
 
 Amarok.Window.ToolsMenu.updateList['triggered()'].connect(updateListJson);
 
 function updateListJson() {
-    var authToken = curlAuth();
-    listSongs(authToken);
-    getCookie();
-    update = false;
-    newItems();
-    if(authToken == ''){
-      Amarok.alert("Problem with Authentication");
-    }
-    if(authToken != '')
-      Amarok.alert("Your music list is updated... Restart Amarok please.");
+	var authToken = curlAuth();
+	listSongs(authToken);
+	getCookie();
+	update = false;
+	newItems();
+	if (authToken == '') {
+		Amarok.alert("Problem with Authentication");
+	}
+	if (authToken != '')
+		Amarok.alert("Your music list is updated... Restart Amarok please.");
 }
 
 function configurationEditor() {
-    this.window = new QMainWindow(this);
-    this.dialog = new QWidget(this);
-
-    this.show = function () {
-        this.window.show();
-    };
-
-    this.accept = function () {
-        this.saveConfiguration();
-        helpWindow.close();
-        this.window.close();
-    };
-
-    this.close = function () {
-        helpWindow.close();
-        this.window.close();
-    };
-
-    this.gp = function () {
-        browser = new QProcess();
-        browser.start("xdg-open", ["https://music.google.com"]);
-    };
-
-    this.pb = function () {};
-
-    this.help = function () {
-        helpWindow.events();
-    };
-
-this.repo = function (){
-	browser = new QProcess();
-	browser.start("xdg-open", ["https://bitbucket.org/jbatalle/google-music-for-amarok"]);
+	this.window = new QMainWindow(this);
+	this.dialog = new QWidget(this);
+
+	this.show = function () {
+		this.window.show();
+	};
+
+	this.accept = function () {
+		this.saveConfiguration();
+		helpWindow.close();
+		this.window.close();
+	};
+
+	this.close = function () {
+		helpWindow.close();
+		this.window.close();
+	};
+
+	this.gp = function () {
+		browser = new QProcess();
+		browser.start("xdg-open", ["https://music.google.com"]);
+	};
+
+	this.pb = function () {};
+
+	this.help = function () {
+		helpWindow.events();
+	};
+
+	this.repo = function () {
+		browser = new QProcess();
+		browser.start("xdg-open", ["https://bitbucket.org/jbatalle/google-music-for-amarok"]);
 	};
-    this.web = function () {
-        browser = new QProcess();
-        browser.start("xdg-open", ["http://kde-apps.org/content/show.php?content=156637"]);
-    };
-
-    this.readConfiguration = function () {
-        try {
-            Config["gpUserID"] = Amarok.Script.readConfig("gpUserID", "");
-            Config["gpPass"] = Amarok.Script.readConfig("gpPass", "");
-        } catch (err) {
-            Amarok.debug(err);
-        }
-        return true;
-    };
-
-    this.saveConfiguration = function () {
-        try {
-            Config["gpUserID"] = this.gpUserInput.text;
-            Config["gpPass"] = this.gpPassInput.text;
-
-            Amarok.Script.writeConfig("gpUserID", Config["gpUserID"]);
-            Amarok.Script.writeConfig("gpPass", Config["gpPass"]);
-
-        } catch (err) {
-            Amarok.debug(err);
-        }
-        return true;
-    };
-
-    this.readConfiguration();
-
-    this.Title = new QHBoxLayout();
-    this.Label = new QLabel("<b>Configure - Google Music</b>");
-    this.Title.addWidget(this.Label, 0, Qt.AlignLeft);
-
-    this.Logo = new QHBoxLayout();
-    this.logo = new QPixmap(Amarok.Info.scriptPath() + "/images/logo.png");
-    this.logoLabel = new QLabel();
-    this.logoLabel.setPixmap(this.logo);
-    this.Logo.addWidget(this.logoLabel, 0, Qt.AlignRight);
-
-
-    // Google
-    this.gpUserBox = new QHBoxLayout();
-    this.gpUserLabel = new QLabel("User:");
-    this.gpUserInput = new QLineEdit(Config["gpUserID"]);
-    this.gpUserInput.setMinimumSize(210, 0);
-
-    this.gpUserInput.setDisabled(false);
-    this.gpUserBox.addWidget(this.gpUserLabel, 0, Qt.AlignLeft);
-    this.gpUserBox.addWidget(this.gpUserInput, 0, Qt.AlignRight);
-
-    this.gpPassBox = new QHBoxLayout();
-    this.gpPassLabel = new QLabel("Password:");
-    this.gpPassInput = new QLineEdit(Config["gpPass"], "password");
-    this.gpPassInput.setMinimumSize(210, 0);
-
-    this.gpPassInput.setDisabled(false);
-    this.gpPassInput.echoMode = QLineEdit.Password;
-    this.gpPassBox.addWidget(this.gpPassLabel, 0, Qt.AlignLeft);
-    this.gpPassBox.addWidget(this.gpPassInput, 0, Qt.AlignLeft);
-
-    // Main
-    this.mainHeader = new QHBoxLayout();
-    this.mainHeader.addLayout(this.Title, 0);
-    this.mainHeader.addLayout(this.Logo, 0);
-
-    this.HeadearTab = new QWidget();
-    this.HeadearTab.setLayout(this.mainHeader);
-
-    // Google
-    this.gpBox = new QGridLayout();
-    this.gpBox.addLayout(this.gpUserBox, 1, 0);
-    this.gpBox.addLayout(this.gpPassBox, 2, 0);
-
-    this.gpTab = new QGroupBox("Google Music Options");
-    this.gpTab.setLayout(this.gpBox);
-
-    this.buttonBox = new QDialogButtonBox();
-    this.buttonBox.addButton(QDialogButtonBox.Help);
-    this.buttonBox.addButton(QDialogButtonBox.Ok);
-    this.buttonBox.addButton(QDialogButtonBox.Cancel);
-    this.buttonBox.accepted.connect(this, this.accept);
-    this.buttonBox.rejected.connect(this, this.close);
-    this.buttonBox.helpRequested.connect(this, this.help);
-
-    this.mainTabs = new QTabWidget();
-    this.mainTabs.addTab(this.gpTab, new QIcon(Amarok.Info.scriptPath() + "/images/google_music_logo.png"), "Google");
-
-    this.vblSet = new QVBoxLayout(this.dialog);
-    this.vblSet.addWidget(this.HeadearTab, 0, 0);
-    this.vblSet.addWidget(this.mainTabs, 0, 0);
-    this.vblSet.addWidget(this.buttonBox, 0, 0);
-
-    var QRect = new QDesktopWidget;
-    var Size = QRect.screenGeometry()
-    var W = (Size.width() - 350) / 2;
-    var H = (Size.height() - 400) / 2;
-
-    this.dialog.setLayout(this.vblSet);
-    this.dialog.sizeHint = new QSize(350, 400);
-    this.dialog.size = new QSize(350, 400);
-    this.window.move(W, H);
-    this.window.setWindowTitle("Configure - Google Music");
-    this.window.windowIcon = new QIcon(Amarok.Info.scriptPath() + "/images/logo.png");
-    this.window.setCentralWidget(this.dialog);
-
-    this.toolsMenu = this.window.menuBar().addMenu("Tools");
-    this.toolsGpApp = this.toolsMenu.addAction(new QIcon(Amarok.Info.scriptPath() + "/images/google.png"), "Go to Google Music");
-    this.toolsGpApp.triggered.connect(this, this.gp);
-
-    this.helpMenu = this.window.menuBar().addMenu("Help");
-    this.helpHlp = this.helpMenu.addAction(new QIcon(Amarok.Info.scriptPath() + "/images/help.png"), "Help");
-    this.helpHlp.triggered.connect(this, this.help);
-    this.helpRepo = this.helpMenu.addAction(new QIcon(Amarok.Info.scriptPath() + "/images/logo.png"), "Repository");
-    this.helpRepo.triggered.connect(this, this.repo);
-    this.helpWeb = this.helpMenu.addAction(new QIcon(Amarok.Info.scriptPath() + "/images/logo.png"), "WebSite");
-    this.helpWeb.triggered.connect(this, this.web);
-
-    return true;
+	this.web = function () {
+		browser = new QProcess();
+		browser.start("xdg-open", ["http://kde-apps.org/content/show.php?content=156637"]);
+	};
+
+	this.readConfiguration = function () {
+		try {
+			Config["gpUserID"] = Amarok.Script.readConfig("gpUserID", "");
+			Config["gpPass"] = Amarok.Script.readConfig("gpPass", "");
+		} catch (err) {
+			Amarok.debug(err);
+		}
+		return true;
+	};
+
+	this.saveConfiguration = function () {
+		try {
+			Config["gpUserID"] = this.gpUserInput.text;
+			Config["gpPass"] = this.gpPassInput.text;
+
+			Amarok.Script.writeConfig("gpUserID", Config["gpUserID"]);
+			Amarok.Script.writeConfig("gpPass", Config["gpPass"]);
+
+		} catch (err) {
+			Amarok.debug(err);
+		}
+		return true;
+	};
+
+	this.readConfiguration();
+
+	this.Title = new QHBoxLayout();
+	this.Label = new QLabel("<b>Configure - Google Music</b>");
+	this.Title.addWidget(this.Label, 0, Qt.AlignLeft);
+
+	this.Logo = new QHBoxLayout();
+	this.logo = new QPixmap(Amarok.Info.scriptPath() + "/images/logo.png");
+	this.logoLabel = new QLabel();
+	this.logoLabel.setPixmap(this.logo);
+	this.Logo.addWidget(this.logoLabel, 0, Qt.AlignRight);
+
+
+	// Google
+	this.gpUserBox = new QHBoxLayout();
+	this.gpUserLabel = new QLabel("User:");
+	this.gpUserInput = new QLineEdit(Config["gpUserID"]);
+	this.gpUserInput.setMinimumSize(210, 0);
+
+	this.gpUserInput.setDisabled(false);
+	this.gpUserBox.addWidget(this.gpUserLabel, 0, Qt.AlignLeft);
+	this.gpUserBox.addWidget(this.gpUserInput, 0, Qt.AlignRight);
+
+	this.gpPassBox = new QHBoxLayout();
+	this.gpPassLabel = new QLabel("Password:");
+	this.gpPassInput = new QLineEdit(Config["gpPass"], "password");
+	this.gpPassInput.setMinimumSize(210, 0);
+
+	this.gpPassInput.setDisabled(false);
+	this.gpPassInput.echoMode = QLineEdit.Password;
+	this.gpPassBox.addWidget(this.gpPassLabel, 0, Qt.AlignLeft);
+	this.gpPassBox.addWidget(this.gpPassInput, 0, Qt.AlignLeft);
+
+	// Main
+	this.mainHeader = new QHBoxLayout();
+	this.mainHeader.addLayout(this.Title, 0);
+	this.mainHeader.addLayout(this.Logo, 0);
+
+	this.HeadearTab = new QWidget();
+	this.HeadearTab.setLayout(this.mainHeader);
+
+	// Google
+	this.gpBox = new QGridLayout();
+	this.gpBox.addLayout(this.gpUserBox, 1, 0);
+	this.gpBox.addLayout(this.gpPassBox, 2, 0);
+
+	this.gpTab = new QGroupBox("Google Music Options");
+	this.gpTab.setLayout(this.gpBox);
+
+	this.buttonBox = new QDialogButtonBox();
+	this.buttonBox.addButton(QDialogButtonBox.Help);
+	this.buttonBox.addButton(QDialogButtonBox.Ok);
+	this.buttonBox.addButton(QDialogButtonBox.Cancel);
+	this.buttonBox.accepted.connect(this, this.accept);
+	this.buttonBox.rejected.connect(this, this.close);
+	this.buttonBox.helpRequested.connect(this, this.help);
+
+	this.mainTabs = new QTabWidget();
+	this.mainTabs.addTab(this.gpTab, new QIcon(Amarok.Info.scriptPath() + "/images/google_music_logo.png"), "Google");
+
+	this.vblSet = new QVBoxLayout(this.dialog);
+	this.vblSet.addWidget(this.HeadearTab, 0, 0);
+	this.vblSet.addWidget(this.mainTabs, 0, 0);
+	this.vblSet.addWidget(this.buttonBox, 0, 0);
+
+	var QRect = new QDesktopWidget;
+	var Size = QRect.screenGeometry()
+	var W = (Size.width() - 350) / 2;
+	var H = (Size.height() - 400) / 2;
+
+	this.dialog.setLayout(this.vblSet);
+	this.dialog.sizeHint = new QSize(350, 400);
+	this.dialog.size = new QSize(350, 400);
+	this.window.move(W, H);
+	this.window.setWindowTitle("Configure - Google Music");
+	this.window.windowIcon = new QIcon(Amarok.Info.scriptPath() + "/images/logo.png");
+	this.window.setCentralWidget(this.dialog);
+
+	this.toolsMenu = this.window.menuBar().addMenu("Tools");
+	this.toolsGpApp = this.toolsMenu.addAction(new QIcon(Amarok.Info.scriptPath() + "/images/google.png"), "Go to Google Music");
+	this.toolsGpApp.triggered.connect(this, this.gp);
+
+	this.helpMenu = this.window.menuBar().addMenu("Help");
+	this.helpHlp = this.helpMenu.addAction(new QIcon(Amarok.Info.scriptPath() + "/images/help.png"), "Help");
+	this.helpHlp.triggered.connect(this, this.help);
+	this.helpRepo = this.helpMenu.addAction(new QIcon(Amarok.Info.scriptPath() + "/images/logo.png"), "Repository");
+	this.helpRepo.triggered.connect(this, this.repo);
+	this.helpWeb = this.helpMenu.addAction(new QIcon(Amarok.Info.scriptPath() + "/images/logo.png"), "WebSite");
+	this.helpWeb.triggered.connect(this, this.web);
+
+	return true;
 }
 
 function helpWindow() {
-    this.helpWindow = new QWidget(this);
-
-    this.events = function () {
-        if (this.helpWindow.visible == false) this.helpWindow.show();
-        else this.helpWindow.close();
-    };
-    this.close = function () {
-        this.helpWindow.close();
-    };
-
-    helpText = "<h3>How to configure Google Music for Amarok</h3>";
-    helpText += "This app allows you to listen the music that you have uploaded in Google Music!<br /><br />";
-    helpText += "In order to listen your music you need an account on Google Music.<br>";
-    helpText += "To grant access to the Google Music click on <b>Tools</b> menu and put your username and password of Google. ";
-    helpText += "<i>This actions require a restart of Amarok, or alternatively reload the Script.</i><br /><br />";
-    helpText += "<b>Username:</b> Your username/email used in Google.<br />";
-    helpText += "<b>Password:</b> Your password.<br />";
-    helpText += "<br/><b>Google Music</b><br />";
-    helpText += "The extracted url only can player one time. After listen a song, if you want to listen again the same song, you need to load another time the song.<br /><br />";
-    helpText += "<b>Next versions</b><br />";
-    helpText += "In the following versions I try to improve these. If you want to collaborate with this script, you are free to do it. And also you can contact with me if you have a question.<br /><br />";
-
-
-    var QRect = new QDesktopWidget;
-    var Size = QRect.screenGeometry()
-    var W = (Size.width() - 530) / 2;
-    var H = (Size.height() - 350) / 2;
-
-    this.helpText = new QTextEdit(helpText, this);
-    this.helpText.readOnly = true;
-    this.layout = new QVBoxLayout(this.helpWindow);
-    this.layout.addWidget(this.helpText, 0, 0);
-
-    this.helpWindow.setLayout(this.layout);
-    this.helpWindow.sizeHint = new QSize(530, 350);
-    this.helpWindow.size = new QSize(530, 350);
-    this.helpWindow.move(W, H);
-    this.helpWindow.setWindowTitle("How to configure Google Music");
-    this.helpWindow.windowIcon = new QIcon(Amarok.Info.scriptPath() + "/images/help.png");
-
-    return true;
+	this.helpWindow = new QWidget(this);
+
+	this.events = function () {
+		if (this.helpWindow.visible == false) this.helpWindow.show();
+		else this.helpWindow.close();
+	};
+	this.close = function () {
+		this.helpWindow.close();
+	};
+
+	helpText = "<h3>How to configure Google Music for Amarok</h3>";
+	helpText += "This app allows you to listen the music that you have uploaded in Google Music!<br /><br />";
+	helpText += "In order to listen your music you need an account on Google Music.<br>";
+	helpText += "To grant access to the Google Music click on <b>Tools</b> menu and put your username and password of Google. ";
+	helpText += "<i>This actions require a restart of Amarok, or alternatively reload the Script.</i><br /><br />";
+	helpText += "<b>Username:</b> Your username/email used in Google.<br />";
+	helpText += "<b>Password:</b> Your password.<br />";
+	helpText += "<br/><b>Google Music</b><br />";
+	helpText += "The extracted url only can player one time. After listen a song, if you want to listen again the same song, you need to load another time the song.<br /><br />";
+	helpText += "<b>Next versions</b><br />";
+	helpText += "In the following versions I try to improve these. If you want to collaborate with this script, you are free to do it. And also you can contact with me if you have a question.<br /><br />";
+
+
+	var QRect = new QDesktopWidget;
+	var Size = QRect.screenGeometry()
+	var W = (Size.width() - 530) / 2;
+	var H = (Size.height() - 350) / 2;
+
+	this.helpText = new QTextEdit(helpText, this);
+	this.helpText.readOnly = true;
+	this.layout = new QVBoxLayout(this.helpWindow);
+	this.layout.addWidget(this.helpText, 0, 0);
+
+	this.helpWindow.setLayout(this.layout);
+	this.helpWindow.sizeHint = new QSize(530, 350);
+	this.helpWindow.size = new QSize(530, 350);
+	this.helpWindow.move(W, H);
+	this.helpWindow.setWindowTitle("How to configure Google Music");
+	this.helpWindow.windowIcon = new QIcon(Amarok.Info.scriptPath() + "/images/help.png");
+
+	return true;
 }
 
 function configureDialog() {
-    var configEdit = new configurationEditor();
-    configEdit.show();
-}
+	var configEdit = new configurationEditor();
+	configEdit.show();
+}

docs/CHANGELOG.txt

+v1.3:
+- Added bar for search
+- Problem with breakline in authToken
+- Download all songs
 v1.2:
 - Bash script functions passed to javascript.
 v1.0:
  *  This Script allows you to listen the music allocated in google
  *  music account using Amarok
  *
- * Copyright (C) 
+ * Copyright (C)
  *
  *  (C)  2013 Josep Batalle Oronich <jbatalle3@gmail.com>
  *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
- * Version: 1.2
+ * Version: 1.3.0
  */
 var Config = Array();
 
 function detectCurl() {
-    var p = new QProcess();
-    p.start("which", ["curl"], QIODevice.ReadOnly);
-    p.waitForFinished()
-    var Response = p.readAllStandardOutput();
-    var textStream = new QTextStream(Response, QIODevice.ReadOnly);
-    var checkCurl = textStream.readAll();
-    if (checkCurl) return true;
-    else false;
+	var p = new QProcess();
+	p.start("which", ["curl"], QIODevice.ReadOnly);
+	p.waitForFinished()
+	var Response = p.readAllStandardOutput();
+	var textStream = new QTextStream(Response, QIODevice.ReadOnly);
+	var checkCurl = textStream.readAll();
+	if (checkCurl) return true;
+	else false;
 }
 
 function doCurl(args) {
-    var p = new QProcess();
-    p.setWorkingDirectory(Amarok.Info.scriptPath());
-    p.start("curl", args, QIODevice.ReadOnly);
-    p.waitForFinished()
-    var Response = p.readAllStandardOutput();
-    var textStream = new QTextStream(Response, QIODevice.ReadOnly);
-    return textStream.readAll();
+	var p = new QProcess();
+	p.setWorkingDirectory(Amarok.Info.scriptPath());
+	p.start("curl", args, QIODevice.ReadOnly);
+	p.waitForFinished()
+	var Response = p.readAllStandardOutput();
+	var textStream = new QTextStream(Response, QIODevice.ReadOnly);
+	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();
+	var p = new QProcess();
+	p.setWorkingDirectory(Amarok.Info.scriptPath());
+	p.start("curl", args, QIODevice.ReadOnly);
+	p.waitForFinished()
+	return p.readAllStandardOutput();
 }
+
 function readConfiguration() {
-        try {
-            Config["gpUserID"] = Amarok.Script.readConfig("gpUserID", "");
-            Config["gpPass"] = Amarok.Script.readConfig("gpPass", "");
-        } catch (err) {
-            Amarok.debug(err);
-        }
-        return true;
-    };
+	try {
+		Config["gpUserID"] = Amarok.Script.readConfig("gpUserID", "");
+		Config["gpPass"] = Amarok.Script.readConfig("gpPass", "");
+	} catch (err) {
+		Amarok.debug(err);
+	}
+	return true;
+};
+
 function curlAuth() {
-    var args = new Array();
-    var clientLoginUrl = "https://www.google.com/accounts/ClientLogin";
-readConfiguration();
-    var email = Config["gpUserID"];
-    var password = Config["gpPass"];
+	var args = new Array();
+	var clientLoginUrl = "https://www.google.com/accounts/ClientLogin";
+	readConfiguration();
+	var email = Config["gpUserID"];
+	var password = Config["gpPass"];
+
+	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);
 
-    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";
+	m = authResponse.match(/SID=([\s\S]*?)LSID=([\s\S]*?)Auth=([\s\S]*)/)
 
-    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;
+	var SID = m[1];
+	var LSID = m[2];
+	var Auth = m[3];
+	Auth = Auth.replace(/\s+/g, ' '); //possible breakline removed
+	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 args = new Array();
+	args[0] = "--header";
+	args[1] = "Authorization: GoogleLogin auth=" + AuthToken;
+	args[2] = "--header";
+	args[3] = "Content-Type: application/json"; //Accept
+	args[4] = "-X";
+	args[5] = "POST";
+	args[6] = "--data";
+	args[7] = "{\'max-results\': \'20000\'}";
+	args[8] = "https://www.googleapis.com/sj/v1beta1/trackfeed";
 
-    var Response = getStreamByCurl(args);
-    var textStream = new QTextStream(Response, QIODevice.ReadOnly);
-    var tinyURL = textStream.readAll();
-    var listSongs = tinyURL;
-    
-			eval("var JSON_obj = " + tinyURL);
-    serviceDataJson = JSON_obj;
-    if (serviceDataJson != null) {
-        var items = serviceDataJson.data.items;
-        var newJsonFile = {
-            "data": [{}]
-        };
+	var Response = getStreamByCurl(args);
+	var textStream = new QTextStream(Response, QIODevice.ReadOnly);
+	var listSongs = textStream.readAll();
+	//Amarok.debug(listSongs);
 
-        for (var i in items) {
-            newJsonFile.data.push({
-                "title": items[i].title, "id": items[i].id, "artist": items[i].artist
-                });
-        }
-    }
+	eval("var JSON_obj = " + listSongs);
+	//var serviceDataJson = JSON.parse(listSongs);
+	var serviceDataJson = JSON_obj;
+	if (serviceDataJson != null) {
+		var items = serviceDataJson.data.items;
+		var nextToken = serviceDataJson.nextPageToken;
+		var newJsonFile = {
+			"nextPageToken": serviceDataJson.nextPageToken, //can be useful
+			"data": [{}]
+		};
 
-    var jsonString = JSON.stringify(newJsonFile);
- 
-    var jsonArray = new QByteArray();
-    jsonArray.append(jsonString);
-    var file = new QFile(Amarok.Info.scriptPath() + "/ListSongs.json");
-    file.open(QIODevice.WriteOnly);
-    file.write(jsonArray);
-    file.close();
+		for (var i in items) {
+			newJsonFile.data.push({
+				"title": items[i].title,
+				"id": items[i].id,
+				"artist": items[i].artist
+			});
+		}
+	}
+
+	var jsonString = JSON.stringify(newJsonFile);
+
+	var jsonArray = new QByteArray();
+	jsonArray.append(jsonString);
+	var file = new QFile(Amarok.Info.scriptPath() + "/ListSongs.json");
+	file.open(QIODevice.WriteOnly);
+	file.write(jsonArray);
+	file.close();
 }
 
 function getCookie(type) {
-    var email = Config["gpUserID"];
-    var password = Config["gpPass"];
+	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 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 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("Debug getCookie" + 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 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);
+	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";//music.google.com
-    args[7] = "POST";
-    args[8] = "https://accounts.google.com/ServiceLoginAuth";
+	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"; //music.google.com
+	args[7] = "POST";
+	args[8] = "https://accounts.google.com/ServiceLoginAuth";
 
-    var authResponse = doCurl(args);
-    var auth = authResponse;
+	var authResponse = doCurl(args);
+	var auth = authResponse;
 }
 
 function getSong(songId) {
-    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 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);
-    Amarok.debug(authResponse);
-    if(authResponse.match("^<HTM"))//In the first execution doesn't work! We need more cookies: sjsaid value
-					authResponse = doCurl(args);//And after this don't get the name of the song, only a number
-    var song = (new Function("return " + authResponse))();
-    Amarok.debug(song.url);
-    return song.url;
+	var authResponse = doCurl(args);
+	//	Amarok.debug(authResponse);
+	if (authResponse.match("^<HTM")) //In the first execution doesn't work! We need more cookies: sjsaid value
+		authResponse = doCurl(args); //And after this don't get the name of the song, only a number
+	var song = (new Function("return " + authResponse))();
+	Amarok.debug("GMusic Debug url" + 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;
+	}
 }
 
 function ScriptBaseDir() {
-    var ScriptFullPath = Amarok.Info.scriptPath();
-    return ScriptFullPath;
+	var ScriptFullPath = Amarok.Info.scriptPath();
+	return ScriptFullPath;
 }
 
 function ListFiles(fullPath, patternFilter) {
-    Importer.loadQtBinding("qt.core");
-    var arr_filesFullPath = []
-    var qd_base = new QDir(fullPath);
-    qd_base.setFilter(QDir.Files);
-    var arr_files = qd_base.entryList([patternFilter]);
-    for (index in arr_files) {
-        arr_filesFullPath[index] = qd_base.absoluteFilePath(arr_files[index])
-    }
-    //arr_filesFullPath is now filled
-    return arr_filesFullPath;
+	Importer.loadQtBinding("qt.core");
+	var arr_filesFullPath = []
+	var qd_base = new QDir(fullPath);
+	qd_base.setFilter(QDir.Files);
+	var arr_files = qd_base.entryList([patternFilter]);
+	for (index in arr_files) {
+		arr_filesFullPath[index] = qd_base.absoluteFilePath(arr_files[index])
+	}
+	//arr_filesFullPath is now filled
+	return arr_filesFullPath;
 }
 
 function ReadTextFile(file) {
-    Importer.loadQtBinding("qt.core");
-    var tmpFile = new QFile(file);
-    tmpFile.open(QIODevice.ReadOnly);
-    var tmpTxtStr = new QTextStream(tmpFile);
-    var text_from_file = tmpTxtStr.readAll();
-    tmpFile.close();
-    return text_from_file;
+	Importer.loadQtBinding("qt.core");
+	var tmpFile = new QFile(file);
+	tmpFile.open(QIODevice.ReadOnly);
+	var tmpTxtStr = new QTextStream(tmpFile);
+	var text_from_file = tmpTxtStr.readAll();
+	tmpFile.close();
+	return text_from_file;
 }
 
 function RadioService(serviceName, serviceSlogan, serviceHtmlDescription, serviceImageFullPath, serviceNoConfigMessage) {
-    this.serviceName = serviceName; //ex: "Radios Portuguesas"
-    this.serviceSlogan = serviceSlogan; //ex: "Escuta em directo as inumeras radios regionais portuguesas"
-    this.serviceHtmlDescription = serviceHtmlDescription; //ex: '<iframe src="http://amarokradiosscript.blogspot.com/"></iframe>';
-    this.serviceImageFullPath = serviceImageFullPath //ex: "/xxx/.../xxx/RadioService.image.png"
-    this.serviceNoConfigMessage = serviceNoConfigMessage; //ex: "Este script nao necessita de configura�ao"
-    this.categoriesList = [];
+	this.serviceName = serviceName; //ex: "Radios Portuguesas"
+	this.serviceSlogan = serviceSlogan; //ex: "Escuta em directo as inumeras radios regionais portuguesas"
+	this.serviceHtmlDescription = serviceHtmlDescription; //ex: '<iframe src="http://amarokradiosscript.blogspot.com/"></iframe>';
+	this.serviceImageFullPath = serviceImageFullPath //ex: "/xxx/.../xxx/RadioService.image.png"
+	this.serviceNoConfigMessage = serviceNoConfigMessage; //ex: "Este script nao necessita de configura�ao"
+	this.categoriesList = [];
 
-    function Category(categoryName, categoryImageFullPath, categoryHtmlDescription) {
-        this.categoryName = categoryName; //ex: "A�ores"
-        this.categoryImageFullPath = categoryImageFullPath; //ex: "/xxx/.../xxx/Category.A�ores/Category.A�ores.image.png"
-        this.categoryHtmlDescription = categoryHtmlDescription; //ex: '<iframe src="http://amarokradiosscript.blogspot.com/"></iframe>'
-        this.stationsList = [];
+	function Category(categoryName, categoryImageFullPath, categoryHtmlDescription) {
+		this.categoryName = categoryName; //ex: "A�ores"
+		this.categoryImageFullPath = categoryImageFullPath; //ex: "/xxx/.../xxx/Category.A�ores/Category.A�ores.image.png"
+		this.categoryHtmlDescription = categoryHtmlDescription; //ex: '<iframe src="http://amarokradiosscript.blogspot.com/"></iframe>'
+		this.stationsList = [];
 
-        function Stream(stationName, stationUrl, stationHtmlDescription) {
-            this.stationName = stationName; //ex: "R�dio Pico"
-            this.stationUrl = stationUrl; //ex: "mms://stream.radio.com.pt/ROLI-ENC-420"
-            this.stationHtmlDescription = stationHtmlDescription; //ex: "R�dio Pico, Freq: 100.2, Distrito: A�ores, Concelho: Madalena"
-        }
-        this.addStream = function addStream(stationName, stationUrl, stationHtmlDescription) {
-            this.stationsList.push(new Stream(stationName, stationUrl, stationHtmlDescription));
-            return this;
-        }
-    }
-    this.addCategory = function addCategory(categoryName, categoryImageFullPath, categoryHtmlDescription) {
-        var newCategory = new Category(categoryName, categoryImageFullPath, categoryHtmlDescription);
-        this.categoriesList.push(newCategory);
-        return newCategory;
-    }
-}
+		function Stream(stationName, stationUrl, stationHtmlDescription) {
+			this.stationName = stationName; //ex: "R�dio Pico"
+			this.stationUrl = stationUrl; //ex: "mms://stream.radio.com.pt/ROLI-ENC-420"
+			this.stationHtmlDescription = stationHtmlDescription; //ex: "R�dio Pico, Freq: 100.2, Distrito: A�ores, Concelho: Madalena"
+		}
+		this.addStream = function addStream(stationName, stationUrl, stationHtmlDescription) {
+			this.stationsList.push(new Stream(stationName, stationUrl, stationHtmlDescription));
+			return this;
+		}
+	}
+	this.addCategory = function addCategory(categoryName, categoryImageFullPath, categoryHtmlDescription) {
+		var newCategory = new Category(categoryName, categoryImageFullPath, categoryHtmlDescription);
+		this.categoriesList.push(newCategory);
+		return newCategory;
+	}
+}
 /*
- *		This Script allows you to listen the music allocated in google
- *		music account using Amarok
+ *  This Script allows you to listen the music allocated in google
+ *  music account using Amarok
  *
- * Copyright (C) 
+ * Copyright (C)
  *
  *  (C)  2013 Josep Batalle Oronich <jbatalle3@gmail.com>
  *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
- * Version: 1.2
+ * Version: 1.3.0
  */
-
 Importer.loadQtBinding("qt.core");
 Importer.loadQtBinding("qt.gui");
 Importer.include("config.js");
 var serviceDataJson;
 
 function newItems() {
-    serviceDataJson = ImportJsonFile(ListFiles(ScriptBaseDir(), "ListSongs.json")[0]);
-    if(serviceDataJson != null){
-    	var categoryObj = myRadioService.addCategory(categoryName, categoryImageFullPath, categoryHtmlDescr);
-    	//  Amarok.alert("New items "+serviceDataJson.kind);
-    	var items = serviceDataJson.data;
-	
-   	 for (var i in items) {
-        	categoryObj.addStream(items[i].title, items[i].id, items[i].artist);
-    	}
-    }
-    update = false;
-    onPopulating(delayedArgs[0], delayedArgs[1], delayedArgs[2]);
+	serviceDataJson = ImportJsonFile(ListFiles(ScriptBaseDir(), "ListSongs.json")[0]);
+	if (serviceDataJson != null) {
+		var categoryObj = myRadioService.addCategory(categoryName, categoryImageFullPath, categoryHtmlDescr);
+		//  Amarok.alert("New items "+serviceDataJson.kind);
+		var items = serviceDataJson.data;
+
+		for (var i in items) {
+			categoryObj.addStream(items[i].title, items[i].id, items[i].artist);
+		}
+	}
+	update = false;
+	onPopulating(delayedArgs[0], delayedArgs[1], delayedArgs[2]);
 }
 
 function GoogleMusicforAmarok() {
-    ScriptableServiceScript.call(this, "Google Music for Amarok", 2, "Songs allocated in Google music", "GoogleMusic2", false);
+	ScriptableServiceScript.call(this, "Google Music for Amarok", 2, "Songs allocated in Google music", "GoogleMusic2", true);
 }
 
 function onConfigure() {
-    Amarok.alert("Este script no requiere configuracion.");
+	Amarok.alert("Este script no requiere configuracion.");
 }
 
 function onPopulating(level, callbackData, filter) {
-	if(!detectCurl){
+	filter = filter.replace("%20", " ");
+	filter = filter.trim();
+	currentFilter = filter.toLowerCase();
+	if (!detectCurl) {
 		Amarok.alert("Curl is not installed in the system!");
 		return;
-		}
-    if (update == true) {
-        delayedArgs = [level, callbackData, filter];
-        newItems();
-        Amarok.Window.Statusbar.shortMessage("Google Music collection is loading...");
-        return;
-    }
-    update = true;
-    Amarok.debug("Populating... " + level);
+	}
+	if (update == true) {
+		delayedArgs = [level, callbackData, filter];
+		newItems();
+		Amarok.Window.Statusbar.shortMessage("Google Music collection is loading...");
+		return;
+	}
+	update = false;
+	Amarok.debug("Populating... " + level);
 
-    if (level == 1) {
-        for (var cat_index = 0; cat_index < myRadioService.categoriesList.length; cat_index++) {
-            var category = myRadioService.categoriesList[cat_index];
-            item = Amarok.StreamItem;
-            item.level = 1;
-            item.callbackData = cat_index;
-            /* Coding caution:
-item.callbackData will be stringified
-So it must not be an object nor a function!!! */
-            item.itemName = category.categoryName;
-            item.playableUrl = "";
-            /* It is a category, so it will not play any URL by itself
-Stations have a playable url, but not categories */
-            item.infoHtml = category.categoryHtmlDescription;
-            item.coverUrl = category.categoryImageFullPath;
-            script.insertItem(item);
-        }
-    } else if (level == 0) {
-        for (var cat_index = 0; cat_index < myRadioService.categoriesList.length; cat_index++) {
-            var category = myRadioService.categoriesList[cat_index];
-            var stationsList = category.stationsList;
-            for (var sta_index = 0; sta_index < stationsList.length; sta_index++) {
-                var station = stationsList[sta_index];
-                item = Amarok.StreamItem;
-                item.level = 0;
-                item.callbackData = "";
-                item.itemName = station.stationName;
-                item.playableUrl = station.stationUrl;
-                item.album = category.categoryName;
-                item.infoHtml = station.stationHtmlDescription;
-                item.artist = station.stationName;
-                item.coverUrl = "";
-                /* A category has an image associated, but
-a station does not any image associated
-That's why this attribute is left blank */
-                script.insertItem(item);
-            }
-        }
-    }
-    script.donePopulating();
+	if (level == 1) {
+		for (var cat_index = 0; cat_index < myRadioService.categoriesList.length; cat_index++) {
+			var category = myRadioService.categoriesList[cat_index];
+			item = Amarok.StreamItem;
+			item.level = 1;
+			item.callbackData = cat_index;
+			/* Coding caution:
+			item.callbackData will be stringified
+			So it must not be an object nor a function!!! */
+			item.itemName = category.categoryName;
+			item.playableUrl = "";
+			/* It is a category, so it will not play any URL by itself
+			Stations have a playable url, but not categories */
+			item.infoHtml = category.categoryHtmlDescription;
+			item.coverUrl = category.categoryImageFullPath;
+			script.insertItem(item);
+		}
+	} else if (level == 0) {
+		Amarok.debug(currentFilter);
+		if (currentFilter == null || new String(currentFilter) == "") {
+			for (var cat_index = 0; cat_index < myRadioService.categoriesList.length; cat_index++) {
+				var category = myRadioService.categoriesList[cat_index];
+				var stationsList = category.stationsList;
+				for (var sta_index = 1; sta_index < stationsList.length; sta_index++) {
+					var station = stationsList[sta_index];
+					item = Amarok.StreamItem;
+					item.level = 0;
+					item.callbackData = "";
+					item.itemName = station.stationName;
+					item.playableUrl = station.stationUrl;
+					item.album = category.categoryName;
+					item.infoHtml = station.stationHtmlDescription;
+					item.artist = station.stationName;
+					item.coverUrl = "";
+					script.insertItem(item);
+				}
+			}
+		} else {
+			for (var cat_index = 0; cat_index < myRadioService.categoriesList.length; cat_index++) {
+				var category = myRadioService.categoriesList[cat_index];
+				var stationsList = category.stationsList;
+				for (var sta_index = 1; sta_index < stationsList.length; sta_index++) {
+					var station = stationsList[sta_index];
+					var nameStation = station.stationName;
+					var stationDesc = station.stationHtmlDescription;
+					if (nameStation.toLowerCase().indexOf(filter) == -1 
+						|| nameStation.toLowerCase().indexOf(currentFilter) == -1 
+						|| stationDesc.indexOf(currentFilter) != -1) continue;
+					item = Amarok.StreamItem;
+					item.level = 0;
+					item.callbackData = "";
+					item.itemName = station.stationName;
+					item.playableUrl = station.stationUrl;
+					item.album = category.categoryName;
+					item.infoHtml = station.stationHtmlDescription;
+					item.artist = station.stationName;
+					item.coverUrl = "";
+					/* A category has an image associated, but
+					a station does not any image associated
+					That's why this attribute is left blank */
+					script.insertItem(item);
+				}
+			}
+		}
+	}
+	script.donePopulating();
 }
 
 
 function getNewURL(frow, row) {
-    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 = getSong(Amarok.Playlist.trackAt(row).path);
+	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 = getSong(Amarok.Playlist.trackAt(row).path);
 
-        uri = uri.replace(/[\n\r]/g, ''); //delete carrier return
-        Amarok.debug(uri);
-        Amarok.Playlist.addMedia(new QUrl(uri));
-        Amarok.Playlist.removeByIndex(row);
-    }
+		uri = uri.replace(/[\n\r]/g, ''); //delete carrier return
+		Amarok.debug(uri);
+		Amarok.Playlist.addMedia(new QUrl(uri));
+		Amarok.Playlist.removeByIndex(row);
+	}
 }
 Amarok.Playlist.trackInserted.connect(getNewURL);
 
 function onCustomize() {
-    var currentDir = Amarok.Info.scriptPath() + "/";
-    var iconPixmap = new QPixmap(currentDir + "icon.png");
-    script.setIcon(iconPixmap);
+	var currentDir = Amarok.Info.scriptPath() + "/";
+	var iconPixmap = new QPixmap(currentDir + "icon.png");
+	script.setIcon(iconPixmap);
 }
 
 Amarok.configured.connect(onConfigure);
 script = new GoogleMusicforAmarok();
 script.populate.connect(onPopulating);
-script.customize.connect(onCustomize);
+script.customize.connect(onCustomize);
 Comment=Google music for Amarok allows you to listen the music allocated in your Google Music account.
 
 X-KDE-PluginInfo-Author=Josep Batalle
-X-KDE-PluginInfo-Email=jbatalle@gmail.com
+X-KDE-PluginInfo-Email=jbatalle3@gmail.com
 X-KDE-PluginInfo-Name=Google Music for Amarok
-X-KDE-PluginInfo-Version=1.2
+X-KDE-PluginInfo-Version=1.3
 X-KDE-PluginInfo-Category=Scriptable Service
 X-KDE-PluginInfo-Depends=Amarok2
 X-KDE-PluginInfo-License=LGPL
-X-KDE-PluginInfo-EnabledByDefault=true
+X-KDE-PluginInfo-EnabledByDefault=true