Adding an AND operator into an FFmpeg command for both an MP3 and OGG lookup functionality

77 Views Asked by At

Using Linux Mint I've been using the following code successfully to generate an m3u playlist file of all musical tracks in a given folder. That's fine for instances where the whole contents are Ogg's; and I change the listed extension within the code to mp3 in the instance I'm working from a folder full of mp3's:

`playlist='play.m3u' ; if [ -f $playlist ]; then rm $playlist ; fi ; for f in *.ogg; do echo "$f" >> "$playlist"; done`

It would be very beneficial if I could add an AND operator in the above so that the generated text file will list both MP3 files and Oggs together in the same list/generated file. Can anyone tell me how to do this please?

I attempted to include:

...for f in *.ogg AND '.mp3';

and

...`for f in *.ogg & '.mp3';

and

...`for f in *.ogg && '.mp3';

None of which worked.

1

There are 1 best solutions below

0
Jon On

I owe another user the answer to this problem but it is now solved.

In order to include multiple file extensions when generating a m3u music playlist, you simply add brackets and a comma to separate the different extensions you may encounter within a particular folder.

Below is an example where you wish to generate an m3u playlist within a folder that includes a mix of Mp3's, Ogg's and WAV's:

playlist='play.m3u' ; if [ -f $playlist ]; then rm $playlist ; fi ; for f in *.{mp3,ogg,wav}; do echo "$f" >> "$playlist"; done

The order in which you place the file extensions within the command determines the order in which those files will appear in the generated m3u file; so in the example above, Mp3 files will be listed first followed by Ogg's and then finally Wav's. Each extension will also be sorted alphanumerically.

'play.m3u' can obviously be substituted for whatever title you'd like to give the m3u file.