Copy favorite Amarok songs


Suppose we have some songs reside in /music and want transfer them to Kindle Duokan or any storage. We need an sql query to fetch their path:

./sql.sql

SELECT `U`.`rpath` from `statistics` as `S`, `urls` as `U` where `S`.`url` = `U`.`id` ORDER BY `S`.score DESC LIMIT 256

and a simple shell script for copying them:

./copy.sh

#!/bin/env sh
from="/music"
dest="/media/Kindle/music"

dir="`dirname "${1:1}"`";
if [ ! -d "$dest""$dir" ]; then
        mkdir -p "$dest""$dir"
fi

cp "$from${1:1}" "$dest${1:1}"

Fire!

$ chmod u+x copy.sh
$ mysql --silent -r -u amarok_user -p amarok > sql.sql \
| grep --color=never -i '.*\.mp3' \
| xargs -d'\n' -L 1 -I '{}' ./copy.sh '{}'