LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-22-2016, 08:30 AM   #1
yknivag
LQ Newbie
 
Registered: Jul 2016
Location: Wiltshire, UK
Distribution: Linux Mint 17.1, OSMC, OpenSUSE
Posts: 7

Rep: Reputation: Disabled
Combining a directory of mp3 files into one file in order.


I have a series of directories containing multiple mp3 files with filenames 001.mp3, 002.mp3, ..., 030.mp3.

What I want to do is to put them all together in order into a single mp3 file and add some meta data to that.

Here's what I have at the moment (removed some variable definitions, for clarity):

Code:
#!/bin/bash
for d in */; do
    cd $d
    find . -iname '*.mp3' -exec lame --decode '{}' - ';' | lame --tt "$title_prefix$name" --ty "${name:5}" --ta "$artist" --tl "$album" -b 64 - $final_path"${d%/}".mp3
    cd ..
done
Sometimes this works and I get a single file with all the "tracks" in the correct order.

However, more often than not I get a single file with all the "tracks" in reverse order, which really isn't good.

What I can't understand is why the order varies between different runs of the script as all the directories contain the same set of filenames. I've poured over the man page and can't find a sort option for find.

Is there any way I can put a sort in before find runs the exec? I can find plenty of examples here and elsewhere of doing this with -exec ls but not where one needs to execute something more complicated with exec.

Pushing the boundaries of my own bash abilities here but could I do something like this?
Code:
find . -iname '*.mp3' | sort -n | xargs <something_here>
If so how would I re-arrange the lame command to take an input?
 
Old 07-23-2016, 03:11 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594
Quote:
Originally Posted by yknivag View Post
could I do something like this?
Code:
find . -iname '*.mp3' | sort -n | lame
Absolutely! (Note absence of 'xargs'.)
Fun part is you can test the change yourself:

Code:
#!/bin/bash
set -vx
for d in */; do
    cd $d
    find . -type f -iname '*.mp3' | sort -n | while read MP3; do echo "lame --decode "${MP3}" | lame --tt "$title_prefix$name" --ty "${name:5}" --ta "$artist" --tl "$album" -b 64 - $final_path"${d%/}".mp3"
    cd ..
done
(Two methods shown in bold: using "set" and "echo".)
 
1 members found this post helpful.
Old 08-19-2016, 08:28 AM   #3
yknivag
LQ Newbie
 
Registered: Jul 2016
Location: Wiltshire, UK
Distribution: Linux Mint 17.1, OSMC, OpenSUSE
Posts: 7

Original Poster
Rep: Reputation: Disabled
The final solution turned out to be rather neat in the end:

Code:
find . -iname '*.mp3' -print0 | sort -zn | xargs -0 -I '{}' lame --decode '{}' - | lame --tt "$title_prefix$name" --ty "${name:5}" --ta "$artist" --tl "$album" -b 64 - $final_path"${d%/}".mp3

Last edited by yknivag; 08-19-2016 at 08:29 AM. Reason: Added code tags
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
combining files into one archive file Peggy L Linux - Newbie 5 08-24-2014 10:38 AM
How do I combining OGV files into one big file MikeyCarter Linux - Software 1 01-02-2011 02:30 PM
Reading all files in a directory in an alphabetical order weeshalll Programming 7 11-25-2009 10:28 PM
K3B automatically sorts MP3 files in order sephiro499 Linux - Software 0 12-03-2004 02:02 PM
File Order iwhen Burning MP3's W4LK Linux - General 1 06-29-2004 02:49 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration