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

[script] converting amarok 1.4 playlist to 2.1 (svn)

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

i've written a small perl script that i used to convert my old amarok 1.4 playlist (from "current.xml") to a new amarok 2.1 svn installation with the new playlist format because the new amarok didn't seem to load my old playlist.

the script fetches the "amarok-sqltrackuid" from the mysql embedded database with the path/url info from the old current.xml playlist and then outputs the new xspf format (to STDOUT). hence it needs mysqld running, see http://amarok.kde.org/wiki/Development/MySQL_Embedded#Tips. it will also show the entries that couldn't be converted (to STDERR).

i've installed 2.1-svn from scratch with a new config and new collectionscan (same files) and didn't import anything from the old amarok. my script successfully converted my old playlist and only skipped 32 out of 277 entries which the new amarok didn't seem to add to the collection database (don't know why..).

usage example: convert.pl /path/to/old/amarok/current.xml > ~/.kde4/share/apps/amarok/current.xspf (backup old file!)

DISCLAIMER: it works for my setup and it is possible that it won't for yours. backup your amarok stuff before trying. feel free to reuse or change the code if it doesn't work you. i didn't test it with v2.0.2, it may work :)

[edited 20090416]

i've removed the code as it seems some users had problems with copy&paste from the forum. i've uploaded the script as convert.pl.txt, just rename the file to convert.pl and it should work then.

furthermore the script has to be run from commandline (konsole, ...), it is not a amarok script.

[/edited 20090416]

20090418: uploaded v0.4

Last edited by 0x00 on Sat Apr 18, 2009 2:46 pm, edited 1 time in total.
User avatar
markey
KDE Developer
Posts
2286
Karma
3
OS
Thanks for this contribution :)

It's probably going to make many users happy.


--
Mark Kretschmann - Amarok Developer
0x00
Registered Member
Posts
6
Karma
0
hi,

i've adjusted the script (v0.3) and now it should also be able to convert playlists with streams or other URLs instead of only handling local "file://" URIs. i didn't fully test it (only modified my old playlist) as i don't have a playlist from amarok 1.4 with streams/podcasts (only local mp3s).

0x00
User avatar
LD
Registered Member
Posts
25
Karma
0
I am having some problems getting it to work, I keep getting syntax errors.

Any suggestions?
0x00
Registered Member
Posts
6
Karma
0
LD wrote:Any suggestions?


i think it is [......] well.. i can't know what went wrong, i need more info, maybe you could post how you started the script, maybe it was a copy&paste error (check with perl -c yourfile.pl) , post what the output (error) is, or does the conversion work and amarok complains ...
you can also upload your xml-playlist somewhere so i can take a look whether it has some weird format, ..... :)

0x00

Last edited by 0x00 on Thu Apr 16, 2009 3:35 pm, edited 1 time in total.
User avatar
LD
Registered Member
Posts
25
Karma
0
I don't really know where I could upload it, but this is what I get when I run it.

Code: Select all
chris@balthazar ~ $ perl amarokplaylists.pl
"use" not allowed in expression at amarokplaylists.pl line 18, at end of line
syntax error at amarokplaylists.pl line 18, near "use strict"
BEGIN not safe after errors--compilation aborted at amarokplaylists.pl line 19.


I also tried in the scripting consol in amarok, but it ust said syntax error.

Here's what is in the file

Code: Select all
#!/usr/bin/perl
# 20090414 v0.3
# v0.1 - unreleased, first version
# v0.2 - first public release
# v0.3 - added code for URI handling other than file:// so it should be possible to
convert streams/podcasts too
# DISCLAIMER: this script is provided as "works for me", backup your amarok stuff
before trying it and keep in
#             mind that it even may not work for your setup

# tries to convert old amarok 1.4 "current.xml" playlist to new amarok 2.1 (svn) playlist format (current.xspf)
# needs mysqld running: http://amarok.kde.org/wiki/Development/MySQL_Embedded#Tips
# because "amarok-sqltrackuid" is being fetched from db
#
# usage: just pipe the output to a new file "current.xspf" and copy the new file/your new playlist to
# ~/.kde4/share/apps/amarok/

use strict;
use DBI;
use URI::Escape;

my $file = $ARGV[0] or die ("Specify path to your current.xml file: $0
/path/to/current.xml\n");

# database stuff
my $db="amarok";
my $host="localhost";
my $userid="root";
my $passwd="";
my $connectionInfo="dbi:mysql:$db;$host";
my $dbh = DBI->connect($connectionInfo,$userid,$passwd) or die "Is mysqld not
running?\n";

# read file, needs path to current.xml file
open (IN, "<$file") or die ("Can't open file..\n");

# print xml headers
print '<?xml version="1.0" encoding="UTF-8"?>
<playlist version="1" xmlns="http://xspf.org/ns/0/" >
  <trackList>
';

# process input file
while (<IN>) {
    chomp($_);
    # get items
    my ($uri, $path) = $_ =~ m/<item url="(.*?):\/\/(.*)" uniqueid/g;
    if ($path eq "") { next; }

    # get amarok db identifier
    my $identifier = "";
    if ($uri eq "file") {
        $identifier = getsql($path); # only fetch info from database when we have
local files
    } else {
        $identifier = "$uri://$path"; # set identifier to the same value as location
(like amarok 2 does for a http:// URI)
    }

    if ($identifier eq "") {
        print STDERR "Identifier not found in db, skipping entry: " .
uri_unescape($path) ."\n";
    } else {
        # print/fill xml structure
        print "    <track>\n";
        print "      <location>$uri://" . $path . "</location>\n";
        print "      <identifier>" . $identifier . "</identifier>\n";
        print "    </track>\n";
    }
}

# print rest of the xml stuff
print "  </trackList>\n";
print "</playlist>\n";
$dbh->disconnect;

# reads uniqueid from amarok database and returns first best match for given local
path
sub getsql {
    my $path = shift;
    $path = uri_unescape($path);

    my $sth = $dbh->prepare("SELECT uniqueid FROM urls WHERE rpath like ?") or die
"Couldn't prepare statement: " . $dbh->errstr;
    $sth->execute("%$path%") or die "Couldn't execute query" . $sth->errstr;

    my @result = $sth->fetchrow_array();
    $sth->finish();
    # only return first result
    return $result[0];
}
0x00
Registered Member
Posts
6
Karma
0
hi,

i've rewritten my script (v0.4), and it is also able to import .m3u playlists now. i've added the script to the first post.

the new script handles .m3u playlist files and inserts them into the mysqld of amarok.

it searches for the paths of the m3u tracks in the database, retrieves the collection path stored in the database and uses that path instead of the one in the .m3u playlist. this is because at least my old amarok m3u playlists often had relative paths which don't seem to be working 1:1 in new amarok anymore.

keep in mind that it if you add a m3u playlist and the track is NOT in the collection it will be added to the playlist database anyway BUT it may not be recognized by amarok if it has a relative path that is inside your home directory (such as ../../../../../mp3/somefile.mp3). in that case you'd have to change the relative paths to absolute ones. i didn't want to mess further with paths in that case.

0x00
User avatar
markey
KDE Developer
Posts
2286
Karma
3
OS
0x00 wrote:i've rewritten my script (v0.4), and it is also able to import .m3u playlists now. i've added the script to the first post.


How about putting it on kde-apps.org? This way you'd have proper hosting for free, and it would make it easier to find for others.


PS:
Please don't put it in the "Amarok Scripts" category though, which is reserved for scripts that run with Amarok's Script Manager system.


--
Mark Kretschmann - Amarok Developer
User avatar
LD
Registered Member
Posts
25
Karma
0
0x00 wrote:hi,

i've rewritten my script (v0.4), and it is also able to import .m3u playlists now. i've added the script to the first post.

the new script handles .m3u playlist files and inserts them into the mysqld of amarok.

it searches for the paths of the m3u tracks in the database, retrieves the collection path stored in the database and uses that path instead of the one in the .m3u playlist. this is because at least my old amarok m3u playlists often had relative paths which don't seem to be working 1:1 in new amarok anymore.

keep in mind that it if you add a m3u playlist and the track is NOT in the collection it will be added to the playlist database anyway BUT it may not be recognized by amarok if it has a relative path that is inside your home directory (such as ../../../../../mp3/somefile.mp3). in that case you'd have to change the relative paths to absolute ones. i didn't want to mess further with paths in that case.

0x00


finally got to a point where I could give it a shot. It keeps erroring out saying mysqld is not runing.
0x00
Registered Member
Posts
6
Karma
0
as new playlists are being stored in the embedded mysqld for amarok2, mysqld has to be running, see my first post how to do start it (link on the amarok wiki).
at my system it is enough to run as your user (you may have to adjust the permissions for the socket directory):
Code: Select all
cd ~/.kde4/share/apps/amarok/
/usr/sbin/mysqld --default-storage-engine=MyISAM --datadir=`pwd`/mysqle --socket=/var/run/mysqld/mysqld.sock --skip-grant-tables


0x00
User avatar
biffster
Registered Member
Posts
8
Karma
0
OS
I know I must be completely missing something, but I just can't figure this out. *WHERE* can I find the script? v 0.3 used to be in the first entry in this thread. That was removed when 0.4 was released. The post says that it was "uploaded," but not where it was uploaded *TO*. I really want to get my hands on a copy of v 0.4 of this script. Can anyone tell me where I can locate it? Or can someone send me a copy?

- Biffster
0x00
Registered Member
Posts
6
Karma
0
it seems the forum has moved (haven't been here for a while..). the old forum had a file upload feature and i've uploaded it there. since i can't find any way to upload files at the new forum (i tried sending you a pm with an attachment, but it always denied the file extension). hence i've pasted the contents of the perl script here: http://pastebin.com/f7526107d

i have no idea whether the script still works for the latest version and i also don't have time to take a look :)

0x00
User avatar
Mamarok
Manager
Posts
6071
Karma
16
OS
You should upload it to http://kde-apps.org/index.php?xcontentmode=57, that's where the Amarok 2.x scripts all are :)


Running Kubuntu 22.10 with Plasma 5.26.3, Frameworks 5.100.0, Qt 5.15.6, kernel 5.19.0-23 on Ryzen 5 4600H, AMD Renoir, X11
FWIW: it's always useful to state the exact Plasma version (+ distribution) when asking questions, makes it easier to help ...
User avatar
biffster
Registered Member
Posts
8
Karma
0
OS
0x00 wrote:i have no idea whether the script still works for the latest version and i also don't have time to take a look :)

0x00


Thank you so much!!!! :D
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
@0x00: File attachments are disabled here for security reasons.

Unfortunately we were unable to import the attachments, as they had been given odd names by the previous board making it impossible for us to script the importing of them.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]


Bookmarks



Who is online

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