The officially official Devuan Forum!

You are not logged in.

#1 2021-04-30 11:20:10

rolfie
Member
Registered: 2017-11-25
Posts: 1,171  

Copy files from a playlist to a USB device

Got an Audacious playlist MyMusic.m3u that lists about 500 wav files on my file server line by line. Is there an easy way to copy these wav's to a USB device?

Thanks, rolfie

Last edited by rolfie (2021-04-30 12:32:59)

Offline

#2 2021-04-30 11:31:56

dice
Member
Registered: 2020-11-22
Posts: 559  
Website

Re: Copy files from a playlist to a USB device

You should be able to glob/wildcard the .wav extension.

cp server/playlist/*.wav /media/usb_device

?

Last edited by dice (2021-04-30 11:32:50)

Offline

#3 2021-04-30 12:38:48

rolfie
Member
Registered: 2017-11-25
Posts: 1,171  

Re: Copy files from a playlist to a USB device

Thanks for your suggestion, but the MyMusic.m3u file isn't accepted as input for the copy operation. Here are 3 lines as they appear in the file:

/srv/Audio/CDs/Adele - Adele21/Adele - Rolling in the deep.wav
/srv/Audio/CDs/Adele - Adele21/Adele - Set fire to the rain.wav
/srv/Audio/CDs/Adele - Adele21/Adele - Someone like you.wav
....

Or is is the only way to write a script that uses the file as input line by line?

rolfie

Last edited by rolfie (2021-04-30 12:39:21)

Offline

#4 2021-04-30 12:41:32

ralph.ronnquist
Administrator
From: Battery Point, Tasmania, AUS
Registered: 2016-11-30
Posts: 1,251  

Re: Copy files from a playlist to a USB device

EDIT: I forgot the m3u ...

find /srv/Audio/CDs -name \*.wav -o -name \*.m3u -print0 | xargs -0 cp -t /media/usb_device

or perhaps

find /srv/Audio/CDs -type f -print0 | xargs -0 cp -t /media/usb_device

Offline

#5 2021-04-30 12:46:31

dice
Member
Registered: 2020-11-22
Posts: 559  
Website

Re: Copy files from a playlist to a USB device

so what is the base directory, is it /srv/Audio/ for all 500 .wavs files and directories? Looks like you need to recurse into the many artists and album directories. Maybe tree the /srv/Audio/ directory to see what you have there?

tree /srv/Audio/

Last edited by dice (2021-04-30 12:55:51)

Offline

#6 2021-04-30 12:55:22

dice
Member
Registered: 2020-11-22
Posts: 559  
Website

Re: Copy files from a playlist to a USB device

ralph.ronnquist wrote:

EDIT: I forgot the m3u ...

find /srv/Audio/CDs -name \*.wav -o -name \*.m3u -print0 | xargs -0 cp -t /media/usb_device

or perhaps

find /srv/Audio/CDs -type f -print0 | xargs -0 cp -t /media/usb_device

That second command does the job nicely.

Offline

#7 2021-04-30 12:59:06

rolfie
Member
Registered: 2017-11-25
Posts: 1,171  

Re: Copy files from a playlist to a USB device

The playlist is a selection of *.wav files, grown over the years from a Winamp playlist under Windows. On the server I have stored all the ripped CDs I own, one directory per CD. And yes, the paths and file names contain whitespaces and special characters all over. I don't want to copy every single file but just the ones listed in the playlist. And about 500 files manually ......

rolfie

Offline

#8 2021-04-30 13:08:35

dice
Member
Registered: 2020-11-22
Posts: 559  
Website

Re: Copy files from a playlist to a USB device

In that case id just clone the directories /srv/Audio/CDs using rsync ?

and then copy over the .m3u file to the usb, wouldnt that work?

Offline

#9 2021-04-30 13:45:17

dice
Member
Registered: 2020-11-22
Posts: 559  
Website

Re: Copy files from a playlist to a USB device

To clarify a bit more having sort of understood what you want, rsync is your tool here.

Have a look at this.

https://unix.stackexchange.com/question … d-playlist

Offline

#10 2021-04-30 16:54:12

rolfie
Member
Registered: 2017-11-25
Posts: 1,171  

Re: Copy files from a playlist to a USB device

My intention is just to copy the files listed in the playlist, and not all the CDs from the server. Simple reason being space available.

Thanks for the link to Stackexchange. At first sight rsync looks promising, at least it might allow for using the specs in the m3u file. I have started to fiddle with the example given there and tried to adapt it to my needs. But its not exactly going as I would expect.

As a start I have reduced the list of files to be copied to 3 to be able to test the options. And I have prepared an empty space on a drive on my workstation. I have left out the sed stuff, since the 3 test files just contain a lot of spaces. Thought that should work. Something still isn't right.

~/Musik$ rsync -a --include-from=/home/rolf/Musik/Test.m3u --include='*/' --exclude='*' /srv/Audio/ /mnt/Daten/rolf/Audio --progress --prune-empty-dirs
building file list ... 
403 files to consider
./
~/Musik$ rsync -a --files-from=/home/rolf/Musik/Test.m3u --include='*/' --exclude='*' /srv/Audio/ /mnt/Daten/rolf/Audio --progress --prune-empty-dirs
building file list ... 
rsync: link_stat "/srv/Audio/srv/Audio/CDs/Adele - Adele21/Adele - Rolling in the deep.wav" failed: No such file or directory (2)
rsync: link_stat "/srv/Audio/srv/Audio/CDs/Adele - Adele21/Adele - Set fire to the rain.wav" failed: No such file or directory (2)
rsync: link_stat "/srv/Audio/srv/Audio/CDs/Adele - Adele21/Adele - Someone like you.wav" failed: No such file or directory (2)
0 files to consider
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1207) [sender=3.1.3]
~/Musik$ rsync -a --files-from=/home/rolf/Musik/Test.m3u --include='*/' --exclude='*' / /mnt/Daten/rolf/Audio --progress --prune-empty-dirs
building file list ... 0 files to consider
~/Musik$ rsync -a --files-from=/home/rolf/Musik/Test.m3u --include='*/' --exclude='*' // /mnt/Daten/rolf/Audio --progress --prune-empty-dirs
building file list ... 0 files to consider

Any idea what not right?

rolfie

Offline

#11 2021-04-30 17:11:44

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: Copy files from a playlist to a USB device

Try

while IFS= read -r line ; do cp -- "$line" /media/usb_device ; done < /home/rolf/Musik/Test.m3u

Reference: https://mywiki.wooledge.org/BashFAQ/001

EDIT: added -- to the cp command to accommodate filenames that start with -.

Last edited by Head_on_a_Stick (2021-05-01 07:05:24)


Brianna Ghey — Rest In Power

Offline

#12 2021-04-30 19:31:38

rolfie
Member
Registered: 2017-11-25
Posts: 1,171  

Re: Copy files from a playlist to a USB device

@HOAS: thanks for that simple bash line, it did the job. 470 files and 19G of data have been copied.

That link yyou posted looks interesting, more examples than the Advanced Scripting Guide I tried to work with. Is bookmarked.

Everybody have a nice weekend.

rolfie

Last edited by rolfie (2021-04-30 19:34:11)

Offline

#13 2021-05-01 11:56:39

dice
Member
Registered: 2020-11-22
Posts: 559  
Website

Re: Copy files from a playlist to a USB device

head on a stick nailed it.

I did a test with rsync and this is how i went about it, although i would probably stick with the bash command from head on a stick.

first created a dummy directory for testing.

~$ tree audio/
audio/
└── cds
    ├── 1
    │   └── 1.mp3
    ├── 2
    │   └── 2.mp3
    ├── 3
    │   └── 3.mp3
    └── 4

5 directories, 3 files

then created my playlist.m3u

find /home/dice/audio/cds/ -type f -iname "*.mp3" > playlist.m3u

the contents of playlist.m3u

/home/dice/audio/cds/2/2.mp3
/home/dice/audio/cds/3/3.mp3
/home/dice/audio/cds/1/1.mp3

then added a random directory number 5 not on the playlist.

~$ tree audio/
audio/
└── cds
    ├── 1
    │   └── 1.mp3
    ├── 2
    │   └── 2.mp3
    ├── 3
    │   └── 3.mp3
    ├── 4
    └── 5
        └── 5.mp3

6 directories, 4 files

created test directory for the rsync.

/home/dice/test-usb-dir

now the rsync command.

rsync -a --include-from=/home/dice/playlist.m3u --delete --delete-excluded --prune-empty-dirs /home/dice/audio test-usb-dir/

edit: this command is better

rsync -av --relative $(cat ~/playlist.m3u) test-usb-dir/

result

~$ tree test-usb-dir/
test-usb-dir/
└── home
    └── dice
        └── audio
            └── cds
                ├── 1
                │   └── 1.mp3
                ├── 2
                │   └── 2.mp3
                └── 3
                    └── 3.mp3

7 directories, 3 files

this seems to work for me and I will test this with some actual audio files in music directory soon.

Last edited by dice (2021-05-01 13:05:56)

Offline

Board footer