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

Get the path of a track / Create a folder

Tags: None
(comma "," separated)
SAKDOSS
Registered Member
Posts
11
Karma
0
Hello everybody,

I am just trying to create a simple amarok script. But I don't know (and I don't succeed in finding) how to :
- get the path of the current track
- create a folder (if possible)

For the first point, I know I can get the current track by using :
Amarok.Engine.currentTrack()

I saw on Amarok development page that we can get the current track artist like that :
Amarok.Engine.currentTrack().artist

But I don't know which argument could give me the fullpath.

For the second point, I just don't know where to find the function to create a folder (I am quite a beginer in QT).

Thanks in advance for your help !
User avatar
Sentynel
KDE Developer
Posts
285
Karma
1
OS
I'm not familiar with the QtScript bindings, but a quick look at the code says the file path should be the 'url' property.

Creating a folder would be QDir().mkdir(path) or .mkpath(path).


SAKDOSS
Registered Member
Posts
11
Karma
0
Ok thanks for your answer.

When you say "a quick look to the code" which code do you mean ? I don't know where to search.
SAKDOSS
Registered Member
Posts
11
Karma
0
Do I have to import something to use QDir() ?

When I try to run the script it crashes and give the output :
"QDir() : did you forget to construct with new"

Currently I have the following imports :
Importer.loadQtBinding("qt.core");
Importer.loadQtBinding("qt.gui");
Importer.loadQtBinding("qt.network");
Importer.loadQtBinding("qt.core.QDir");

And I try to run the code :
if(QDir().exists(new_path))
Amarok.alert("exists: " + new_path);
else
Amarok.alert("doesn't exist: " + new_path);

Thanks for your help !
User avatar
Sentynel
KDE Developer
Posts
285
Karma
1
OS
As the error suggests, you're missing the new keyword, which is used for object creation in JavaScript (technically, ECMAScript).
Code: Select all
if (new QDir().exists(new_path))
Amarok.alert("exists");


I strongly suggest reading some basic JavaScript tutorials.


SAKDOSS
Registered Member
Posts
11
Karma
0
Thanks, it works perfectly !

Just one comment, "Amarok.Engine.currentTrack().url" was returning me the path of the track with "%20" instead of spaces.
I found the following command which suits me more :
Code: Select all
Amarok.Playlist.filenames()[Amarok.Playlist.activeIndex()];


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], Sogou [Bot]