Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] "How to"



On 2014-05-11 at 18:02:33 Bruno Raoult wrote:
> 3- How would you *copy* your mp3 (real files) playlists from an m3u
> file to another place, with no subtree in destination? Example:
> src/a/b/c/d.mp3 => dst/a-b-c-d.mp3. m3u is a common file format for
> music playing lists.

I'd do something like this, where "file.m3u" is your m3u file:

cat file.m3u | while read SRC ; do
    DST=$(echo "${SRC}" | sed -e 's/^src\///; s/\//-/g; s/^/dst\//')
    echo "Copying '${SRC}' to '${DST}'"
    cp -p "${SRC}" "${DST}"
done

If you want to get fancy you can get rid of the "useless use of cat", 
but i find that it makes the logic easier to understand. You could also 
optimize the sed more; i think 's/\//-/g; s/^src-/dst\//;' would also 
work as well and only require 2 substitutions. I put the echo in there 
so for testing you can just remove the cp and make sure it is 
calculating the source and destination paths correctly.

> 4- If you consider the final target being /a/b/c/d, how would you
> create the new m3u file from the original one? Example: you answered
> question 3, but the target is for another device/machine, therefore
> different path.

I'm not sure i understand the question, but if you want to mangle the 
paths of each line in the m3u, one solution might involve passing the 
file through sed with the appropriate substitution commands. And if sed 
isn't powerful enough, i usually mangle things with "perl -ne" and a 
suitable 1-line script.

__
Daniel A. Ramaley
Network Engineer 2

Dial Center 122, Drake University
2407 Carpenter Ave / Des Moines IA 50311 USA
Tel: +1 515 271-4540
Fax: +1 515 271-1938
E-mail: daniel.ramaley@example.com



Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links