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

m3u Playlists

Tags: None
(comma "," separated)
User avatar
Max
Registered Member
Posts
28
Karma
0
OS

m3u Playlists

Wed Jan 27, 2010 5:15 pm
I started this in order to make a playlist that is readable from my portable device (a Sansa Clip). The Clip uses m3u playlists, and there isn't a way to copy the Amarok playlist to a portable device.
So I started this script with the idea being that you'd plug in your device, create a playlist the same way you'd regularly do (from the songs in the portable device), and then run this script to create an m3u playlist on the device.
On the way I ran into some difficulties:
1) I have never written a script like this before, and certainly never used Qt. I have no idea how to begin making a GUI for this, put it in the menu or whatever.
2) My device is an MTP device. And in order for Amarok to read media files from such a device it copies them to the tmp folder. An m3u playlist needs the absolute file path in order to work. Therefore, this won't work for what I had in mind.
Regardless, I am posting my code here, perhaps somebody will be able to use it.

This is the snippet that saves the current playlist in Amarok as an m3u file in the parent directory of the music collection.
Code: Select all
var path=Amarok.Collection.collectionLocation();
file=new QFile(path+"/Playlist.m3u"); //Change this to the name of the file that you want.
file.open(new QIODevice.OpenMode(QIODevice.WriteOnly));
if (file.isOpen()){
   out = new QTextStream(file);
   out.writeString("#EXTM3U \n");
   var i=0;
   for (i=0; i<Amarok.Playlist.totalTrackCount(); i++){
      var seconds=Amarok.Playlist.trackAt(i).length;
      var sseconds=seconds.toString();
      out.writeString("#EXTINF\:"+sseconds.slice(0,sseconds.length/1000)
            +","+Amarok.Playlist.trackAt(i).title+"\n");
      out.writeString(Amarok.Playlist.trackAt(i).path+"\n");
   }
}
file.close()

You can run this from the scripting console. Replace the name of the file with the name you want.

Anybody who could help or contribute to this is welcome, and you're welcome to use this bit of code. But unless something changes in the way Amarok reads MTP devices I don't see any practical use for it.


Cogito ergo surf
I think therefore I network.

Registered Linux user #481826 Get counted!
Image
User avatar
Stecchino
KDE Developer
Posts
88
Karma
0

Re: m3u Playlists

Wed Jan 27, 2010 8:13 pm
We are actually working on a way to copy, and even sync device playlists to and from amarok that should be included in the next version.

I'm not trying to discourage you from developing this script further but it might be wasted effort.
User avatar
Max
Registered Member
Posts
28
Karma
0
OS

Re: m3u Playlists

Wed Jan 27, 2010 9:01 pm
I was discouraged from developing this further when I realized that it won't serve the purpose I intended for it.
I decided to post it here and make it public in the hopes that maybe somebody would find it useful, but I don't intend to take it any further.


Cogito ergo surf
I think therefore I network.

Registered Linux user #481826 Get counted!
Image


Bookmarks



Who is online

Registered users: Bing [Bot], gfielding, Google [Bot], markhm, Sogou [Bot], Yahoo [Bot]