Commits

Josep Batalle committed 0edd7b7

Reduce size file of songs

  • Participants
  • Parent commits dca51d7
  • Branches develop

Comments (0)

Files changed (2)

  *
  * Version: 1.2
  */
-
 function detectCurl() {
     var p = new QProcess();
     p.start("which", ["curl"], QIODevice.ReadOnly);
     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();
     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();
+
+    serviceDataJson = ImportJsonFile(ListFiles(ScriptBaseDir(), "ListSongs.json")[0]);
+    */
+    eval("var JSON_obj = " + tinyURL);
+    serviceDataJson = JSON_obj;
+    if (serviceDataJson != null) {
+        var items = serviceDataJson.data.items;
+        var newJsonFile = {
+            "data": [{}]
+        };
+
+        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 delayedArgs = null;
 var update = true;
+var currentFilter = "";
+
 
 var myRadioService = new RadioService("Google Music SERVICE", "", "Listen your uploaded Music!", "", "You need a Google Music Account");
 var categoryName = "Google Music";
 }
 
 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() {
 }
 
 function onPopulating(level, callbackData, filter) {
+	
+ 		filter        = filter.replace( "%20", " " );
+  filter        = filter.trim();
+  currentFilter = filter.toLowerCase();
+  Amarok.debug(filter);
+  
 	if(!detectCurl){
 		Amarok.alert("Curl is not installed in the system!");
 		return;
             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];
+var station = stationsList[sta_index];
+            	var nameStation = station.stationName;
+									var stationDesc = station.stationHtmlDescription;
+            	if(currentFilter != null){
+            	if(nameStation.indexOf( currentFilter ) != -1 ||stationDesc.indexOf( currentFilter ) != -1 ){
+            		
+            		
+                
                 item = Amarok.StreamItem;
                 item.level = 0;
                 item.callbackData = "";
 a station does not any image associated
 That's why this attribute is left blank */
                 script.insertItem(item);
+                }
+                }
             }
         }
     }