This forum has been archived. All content is frozen. Please use KDE Discuss instead.

script download in amarok2

Tags: None
(comma "," separated)
kk7
Registered Member
Posts
6
Karma
0

script download in amarok2

Mon Sep 29, 2008 2:47 pm
I'm currently writing a script, for dynamic playlist generation. Therefore I need to look up every song in a online database. Currently I saw this downloader in other scripts:
Code: Select all
new Downloader( qurl, signal_handler );

...well, I prefer the code to stop until a response arrives like:
Code: Select all
html_response = download( qurl );

how may I realize this? I didn't figure it out how to handle it with the trolltech network module...
User avatar
markey
KDE Developer
Posts
2286
Karma
3
OS

Re: script download in amarok2

Thu Oct 02, 2008 3:13 pm
There is no need to use the Downloader in a synchronous way. Just give it the method that it should call after finishing, and do nothing.


Here you can see an example of how it works:

http://kollide.net:8060/browse/~raw,r=1 ... rc/main.js


--
Mark Kretschmann - Amarok Developer
kk7
Registered Member
Posts
6
Karma
0

Re: script download in amarok2

Thu Oct 02, 2008 5:24 pm
thx for your answer... let me reformulate my problem  :wink: If I would do something like this:
Code: Select all
var query = db.exec( SQL_GET_ARTIST_TITLE );

while( query.next() ){
   var track_id = query.value(0)
   var artist = query.value(1);
   var title = query.value(2);
   
   var path = "http://localhost/getCoordinates.php?" + "artist=" + artist + "&title=" + title;
   qurl = new QUrl( path );
   new Downloader( qurl , download_finished );
}

function download_finished( data ){
   print( "I'm a very sad function because I don't know to witch track_id this data belongs since the ordering may change caused by some connection problems" );
}


...or is there a way to add an additional argument to 'download_finished'? I made a very ugly hack with a stack but it somehow works this way now...
clone00
Registered Member
Posts
1
Karma
0

Re: script download in amarok2

Sun Dec 14, 2008 8:19 pm
I /just/ started doing amarok plugin programming, so bear with me.  Here is how it would work in javascript though:


var query = db.exec( SQL_GET_ARTIST_TITLE );

var row_dex = 0;
while( query.next() ){
  var track_id = query.value(0)
  var artist = query.value(1);
  var title = query.value(2);
 
  var path = "http://localhost/getCoordinates.php?" + "artist=" + artist + "&title=" + title;
  qurl = new QUrl( path );
  new Downloader( qurl , function(data) {
            if ( whatever your condition that needs to access row_dex is )
                      print( "I'm a happy anonymous function that since JS is totally crazy, can inherit variables from where it is instantiained.  No joke: "+row_dex );

} );
    row_dex++;
}


Bookmarks



Who is online

Registered users: bancha, Bing [Bot], daret, Evergrowing, Google [Bot], lockheed, sandyvee, Sogou [Bot]