Rhythmbox XML Parsing to Copy Playlists to Phone or USB Stick

I was recently faced with the issue of physically moving all the songs I’d given five stars in Rhythmbox to a phone.

As it happens that stuff is stored in an XML file (at least the version I’m using in Ubuntu 16.04).

This is my PHP solution:

function xmlToArr($xml){
        $simple_xml_obj = @simplexml_load_string($xml, "SimpleXMLElement", LIBXML_NOCDATA);
        // Not valid XML
            return [];
        $json = json_encode($simple_xml_obj);
        return json_decode($json, true);
$arr = xmlToArr(file_get_contents('~/.local/share/rhythmbox/playlists.xml'));
foreach($arr['playlist'][6]['location'] as $file){
	$fname = urldecode(array_pop(explode('/', $file)));
	$file = urldecode(str_replace(['file://', '!'], ['', '\!'], $file));
	$target = "/feting/for_phone/$fname";
	echo $file."\n";
	copy($file, $target);

Related Posts

Tags: , ,