<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:admin="http://webns.net/mvcb/"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<channel> 

	<title>Comments on: Joining MP3 Files Together Based on Date in Filename?</title>
	<link>http://ask.metafilter.com/117747/Joining-MP3-Files-Together-Based-on-Date-in-Filename/</link>
	<description>Comments on Ask MetaFilter post Joining MP3 Files Together Based on Date in Filename?</description>
	<pubDate>Wed, 25 Mar 2009 16:28:06 -0800</pubDate>
	<lastBuildDate>Wed, 25 Mar 2009 16:28:06 -0800</lastBuildDate>
	<language>en-us</language>
	<docs>http://blogs.law.harvard.edu/tech/rss</docs>
	<ttl>60</ttl>

	<item>
		<title>Question: Joining MP3 Files Together Based on Date in Filename?</title>
		<link>http://ask.metafilter.com/117747/Joining-MP3-Files-Together-Based-on-Date-in-Filename</link>	
		<description>I have a podcast that downloads as multiple segments over multiple days.  Its format arrives as YYYYMMDD_showcode_segment.mp3; so, for example, one download might result in files as 20090323_goofa_01.mp3 through 20090323_goofa_21.mp3, and also &lt;i&gt;within the same download&lt;/i&gt; 20090324_goofa_01.mp3 through 20090324_goofa_21.mp3.  What I&apos;m looking for is a Unix script (shell, perl, what have you) that would look at a directory and look at what dates are represented there, and let me join all of the segments together by day.  I can use mpgtx -j to do the actual joining; I&apos;m looking for the code that would let the script determine what dates are in the directory and then get each day&apos;s segments united into a single MP3 for that day&apos;s show.</description>
		<guid isPermaLink="false">post:ask.metafilter.com,2009:site.117747</guid>
		<pubDate>Wed, 25 Mar 2009 16:08:55 -0800</pubDate>
		<dc:creator>WCityMike</dc:creator>
		
			<category>join</category>
		
			<category>segment</category>
		
			<category>mp3</category>
		
			<category>day</category>
		
			<category>group</category>
		
			<category>unix</category>
		
			<category>perl</category>
		
			<category>tcsh</category>
		
			<category>csh</category>
		
			<category>bash</category>
		
			<category>script</category>
		
			<category>resolved</category>
		
	</item> <item>
		<title>By: devbrain</title>
		<link>http://ask.metafilter.com/117747/Joining-MP3-Files-Together-Based-on-Date-in-Filename#1686779</link>	
		<description>(assuming syntax for the mpgtx command is to just string the files on the end)&lt;br&gt;
&lt;br&gt;
for date in `ls -1  | cut -d_ -f1 | sort | uniq `; do echo Working for date $date; mpgtx -j ${date}_*; done</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2009:site.117747-1686779</guid>
		<pubDate>Wed, 25 Mar 2009 16:28:06 -0800</pubDate>
		<dc:creator>devbrain</dc:creator>
	</item><item>
		<title>By: devbrain</title>
		<link>http://ask.metafilter.com/117747/Joining-MP3-Files-Together-Based-on-Date-in-Filename#1686783</link>	
		<description>... and if you have multiple showcodes in one day, replace &quot;-f1&quot; with &quot;-f1-2&quot; to make the main for loop iterate over date_showcode pairs ...</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2009:site.117747-1686783</guid>
		<pubDate>Wed, 25 Mar 2009 16:29:40 -0800</pubDate>
		<dc:creator>devbrain</dc:creator>
	</item><item>
		<title>By: devbrain</title>
		<link>http://ask.metafilter.com/117747/Joining-MP3-Files-Together-Based-on-Date-in-Filename#1686787</link>	
		<description>... and one more adjustment.  If you have non zero padded part numbers (instead of 01 through 21 you have 1 through 21) they&apos;ll not sort correctly by default.  Here&apos;s how to force a numeric sort on the third field when combining ...&lt;br&gt;
&lt;br&gt;
for date in `ls -1  | cut -d_ -f1-2 | sort | uniq `; do echo Working for $date; echo COMMAND `ls -1 ${date}_* | sort -t _ -k3 -n`; done</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2009:site.117747-1686787</guid>
		<pubDate>Wed, 25 Mar 2009 16:32:39 -0800</pubDate>
		<dc:creator>devbrain</dc:creator>
	</item><item>
		<title>By: WCityMike</title>
		<link>http://ask.metafilter.com/117747/Joining-MP3-Files-Together-Based-on-Date-in-Filename#1686791</link>	
		<description>Thanks!  Iterations #2 and #3 won&apos;t be necessary at the moment, but it&apos;ll be great to refer back to if needed later.&lt;br&gt;
&lt;br&gt;
I did modify it very slightly -- mpgtx needs an output file name.  (And, also, as normally a tcsh user, I realized I had to head over to bash for this.)&lt;br&gt;
&lt;br&gt;
So:&lt;br&gt;
&lt;br&gt;
for date in `ls -1 | cut -d_ -f1 | sort | uniq `; do echo Working for date $date; mpgtx -j ${date}_*.mp3 -o &quot;[Show Title] ${date}.mp3&quot;; done&lt;br&gt;
&lt;br&gt;
Thanks! :)</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2009:site.117747-1686791</guid>
		<pubDate>Wed, 25 Mar 2009 16:34:59 -0800</pubDate>
		<dc:creator>WCityMike</dc:creator>
	</item><item>
		<title>By: flabdablet&apos;s sock puppet</title>
		<link>http://ask.metafilter.com/117747/Joining-MP3-Files-Together-Based-on-Date-in-Filename#1687420</link>	
		<description>The output of ls -1 is already sorted, so there&apos;s no need for another sort before the uniq. Also, wrapping the &lt;code&gt;ls | cut | uniq&lt;/code&gt; pipe in backticks and processing it in a &lt;code&gt;for&lt;/code&gt; loop loses the distinction between newlines that separate filenames and whitespace within the filenames, so if any filenames contain spaces it does the wrong thing.&lt;br&gt;
&lt;br&gt;
Better is&lt;br&gt;
&lt;code&gt;&lt;br&gt;
ls -1 | cut -d_ -f1-2 | uniq | while read -r prefix; do echo Merging &quot;$prefix&quot;; mpgtx -j -o &quot;$prefix.mp3&quot; &quot;$prefix&quot;*; done&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
which won&apos;t break unless your filenames contain newlines.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2009:site.117747-1687420</guid>
		<pubDate>Thu, 26 Mar 2009 05:59:30 -0800</pubDate>
		<dc:creator>flabdablet&apos;s sock puppet</dc:creator>
	</item>
	</channel>
</rss>
