Commits

Josep Batalle committed 8a772a7

initial commit

Comments (0)

Files changed (14)

+[Dolphin]
+PreviewsShown=true
+Timestamp=2013,1,27,0,27,57
+Version=3
+VisibleRoles=Icons_text
+var Config = Array();
+var helpWindow = new helpWindow();
+     
+Amarok.Window.addToolsMenu("Googlemusic", "Configure Google Music...", Amarok.Info.scriptPath() + "/images/logo.png");
+Amarok.Window.ToolsMenu.Googlemusic['triggered()'].connect(configureDialog); 
+     
+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.web = function () {
+	  browser = new QProcess();
+	  browser.start("xdg-open", ["http://kde-apps.org/content/show.php?content=155090"]);
+     };
+     
+     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 - SocialRok");
+     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.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 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 += "<b>Skype Tab</b><br />";     
+     helpText += "If you have a Skype account, you can authorize SocialRok to change the mood text on every track change. To do this, you must have Skype installed and running. When Skype will ask you to allow SocialRok to change mood text check \"Remember this selection\" and then click YES! To work, curl and python-dbus must be installed in your system.<br /><br />";     
+     helpText += "<b>Flickr Tab</b><br />";
+     helpText += "If you have a Flickr account, you can authorize SocialRok to upload the Cover Arts on your space so you can post the Covers on Facebook as a link instead of as a normal picture, if you're interested to this option, go to Grant Access page for Facebook and after Login you can Grant Access for Flickr. This option can also be activated after you have already Granted Access to Facebook.<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();
+}
+#!/bin/bash
+action=$1
+clientLoginUrl="https://www.google.com/accounts/ClientLogin"
+service="sj"
+
+auth() {
+email=$1
+password=$2
+    authResponse=$(curl "$clientLoginUrl" --data-urlencode Email="$email" --data-urlencode Passwd="$password" -d accountType=GOOGLE -d service="$service")
+    authToken="${authResponse##*=}"
+    SID="${authResponse:4:288}"
+    LID="${authResponse:298:288}"    
+}
+
+getCookie() {
+email=$1
+password=$2
+  curl -b cookie.txt -c cookie.txt "https://accounts.google.com/ServiceLogin?service=sj" > file.html
+  DSH=$(sed -n -e 's/.*id="dsh" value="\(.*\)".*/\1/p' file.html)
+  GALX=$(sed -n -e 's/         value="\(.*\)".*/\1/p' file.html)
+  curl -b cookie.txt -c cookie.txt -d "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" -X POST https://accounts.google.com/ServiceLoginAuth
+  rm file.html
+}
+listSongs(){
+ curl --header "Authorization: GoogleLogin auth=${authToken}"      https://www.googleapis.com/sj/v1beta1/tracks > listSongs.json
+}
+
+getUrlSong(){
+  curl -verbose -b cookie.txt -c cookie.txt "https://music.google.com/music/play?u=0&songid=$1&pt=e" > url.json
+}
+extractUrl(){
+  url=$(cat url.json | sed -e 's/{"url":"/''/g')
+  url="${url%?}"
+  url="${url%?}"
+  echo $url > url
+# url=${url//\\\003d/=}
+ url=$(sed 's/\\u003d/=/g' url)
+ echo $url > url
+ url=$(sed 's/\\u0026/\&/g' url)
+#  url=${url//\\\0026/&}
+  echo $url > url
+  echo $url
+}
+getList="getList"
+getUrlSong="getUrlSong"
+#echo $1>file1.txt
+#echo $action>file12.txt
+#echo $2>file2.txt
+#echo $3>file3.txt
+if [ "$action" == "$getList" ]; then
+email=$2
+password=$3
+#echo $1>file232.txt
+auth $email $password
+listSongs 
+getCookie $email $password
+#echo "ok"
+elif [ "$action" == "$getUrlSong" ]; then
+songId=$2
+getUrlSong $songId
+extractUrl
+fi
Added
New image

images/.directory

+[Dolphin]
+Timestamp=2013,1,22,18,31,22
+Version=3

images/google_music_logo.png

Added
New image

images/help.png

Added
New image

images/logo.png

Added
New image

images/logo_big.png

Added
New image
+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 checkPython = textStream.readAll();
+     if (checkPython) return true; else false;
+}
+
+function executeScript(){
+  Config["gpUserID"] = Amarok.Script.readConfig("gpUserID", "");
+  Config["gpPass"] = Amarok.Script.readConfig("gpPass", "");
+  var dirScript = "../.kde4/share/apps/amarok/scripts/google_music/";//~/Documents by default
+  var nameScript = "google_music.sh";
+    var args = new Array();
+  args[0]= nameScript;
+  args[1]= "getList";
+  args[2]= Config["gpUserID"];
+  args[3]= Config["gpPass"];
+
+  var p = new QProcess();
+  p.setWorkingDirectory(dirScript);
+  p.start("sh", args, QIODevice.ReadOnly);
+  p.waitForFinished();
+  var Response = p.readAllStandardOutput();
+  var textStream = new QTextStream(Response, QIODevice.ReadOnly);
+  var tinyURL = textStream.readAll();
+
+//Amarok.alert(tinyURL)
+//Amarok.alert(Response)
+//Amarok.alert(textStream) 
+}
+
+function getUrl(id){
+//  id="4abbd809-0d8e-3852-9301-a61a7f2fce3b";
+var dirScript = "../.kde4/share/apps/amarok/scripts/google_music/";//~/Documents by default
+  var nameScript = "google_music.sh";//getUrl
+var args = new Array();
+args[0]= nameScript;
+args[1]= "getUrlSong";
+args[2]= id;
+Amarok.alert(id);
+  var p = new QProcess();
+  p.setWorkingDirectory(dirScript);
+  p.start("sh", args, QIODevice.ReadOnly);
+  p.waitForFinished();
+  var Response = p.readAllStandardOutput();
+  var textStream = new QTextStream(Response, QIODevice.ReadOnly);
+  var tinyURL = textStream.readAll();
+  Amarok.alert(tinyURL);
+  return tinyURL;
+}
+
+
+function ImportJsonFile(json_file) {
+  eval("var JSON_obj = " + ReadTextFile(json_file));
+  return JSON_obj;
+}
+
+function ScriptBaseDir() {
+  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;
+}
+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;
+}
+
+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=[];
+  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;
+  }
+}