<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Big Bad Code &#187; m4a</title>
	<atom:link href="http://bigbadcode.com/category/m4a/feed/" rel="self" type="application/rss+xml" />
	<link>http://bigbadcode.com</link>
	<description>this blog is retired. I&#039;m leaving it up as a reference</description>
	<lastBuildDate>Wed, 19 Aug 2009 21:49:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Convert m4a to mp3</title>
		<link>http://bigbadcode.com/2007/06/06/convert-m4a-to-mp3/</link>
		<comments>http://bigbadcode.com/2007/06/06/convert-m4a-to-mp3/#comments</comments>
		<pubDate>Wed, 06 Jun 2007 14:15:41 +0000</pubDate>
		<dc:creator>jbloom</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[audio]]></category>
		<category><![CDATA[m4a]]></category>
		<category><![CDATA[mp3]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[utility]]></category>

		<guid isPermaLink="false">http://bigbadcode.com/2007/06/06/convert-m4a-to-mp3/</guid>
		<description><![CDATA[I&#8217;ve been moving a bunch of my brothers music out of iTunes for him so he can use it with portable players besides iPod. Unfortunately he encoded a lot of his cd&#8217;s in .m4a format. I found a decent utility for converting to mp3 (and other formats) http://www.bonkenc.org/ Unfortunately when you point Bonk at a [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been moving a bunch of my brothers music out of iTunes for him so he can use it with portable players besides iPod. Unfortunately he encoded a lot of his cd&#8217;s in .m4a format. I found a decent <a href="http://www.bonkenc.org/">utility for converting to mp3 (and other formats) http://www.bonkenc.org/</a></p>
<p>Unfortunately when you point Bonk at a directory full of m4a&#8217;s it crashes on certain files for some reason (encoding issues probably.) After the crash you need to setup all of your settings and add the files again, which is really time consuming and annoying.</p>
<p>To make this easier I whipped  up a short python script that calls Bonk for you on each file, if it runs into a bad file it will rename the file for you so you don&#8217;t try to process it again. </p>
<p>Here&#8217;s the python code:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">pprint</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">subprocess</span>
curDir = <span style="color: #dc143c;">os</span>.<span style="color: black;">getcwd</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># The current directory. This should contain your .m4a files</span>
pathToBonk = <span style="color: #483d8b;">&quot;C:<span style="color: #000099; font-weight: bold;">\\</span>Program Files<span style="color: #000099; font-weight: bold;">\\</span>BonkEnc<span style="color: #000099; font-weight: bold;">\\</span>becmd.exe&quot;</span> <span style="color: #808080; font-style: italic;">#Where the becmd.exe file lives</span>
problemFiles = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span> <span style="color: #808080; font-style: italic;">#A list of files that failed conversion</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #ff7700;font-weight:bold;">for</span> item <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">listdir</span><span style="color: black;">&#40;</span>curDir<span style="color: black;">&#41;</span>:
	<span style="color: #ff7700;font-weight:bold;">if</span> item.<span style="color: black;">upper</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">endswith</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'.M4A'</span><span style="color: black;">&#41;</span>:
		fullPath = <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>curDir,item<span style="color: black;">&#41;</span>
		<span style="color: #dc143c;">cmd</span> = <span style="color: #483d8b;">'&quot;%s&quot; -e LAME -d &quot;%s&quot; &quot;%s&quot;'</span> <span style="color: #808080; font-style: italic;">#The command to convert a single file</span>
		<span style="color: #dc143c;">cmd</span> = <span style="color: #dc143c;">cmd</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>pathToBonk, curDir, fullPath<span style="color: black;">&#41;</span>
		val = <span style="color: #dc143c;">subprocess</span>.<span style="color: black;">call</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">cmd</span><span style="color: black;">&#41;</span>
		<span style="color: #ff7700;font-weight:bold;">if</span> val == <span style="color: #ff4500;">0</span>: <span style="color: #808080; font-style: italic;">#Successfull conversion, delete the original</span>
			<span style="color: #dc143c;">os</span>.<span style="color: black;">remove</span><span style="color: black;">&#40;</span>fullPath<span style="color: black;">&#41;</span>
		<span style="color: #ff7700;font-weight:bold;">else</span>:
			problemFiles.<span style="color: black;">append</span><span style="color: black;">&#40;</span>fullPath<span style="color: black;">&#41;</span>
			<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Problem converting %s'</span> <span style="color: #66cc66;">%</span> item
			<span style="color: #dc143c;">os</span>.<span style="color: black;">rename</span><span style="color: black;">&#40;</span>fullPath, fullPath + <span style="color: #483d8b;">&quot;.BAD&quot;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'These files had problems converting and have been renamed with .BAD extensions:'</span>
<span style="color: #dc143c;">pprint</span>.<span style="color: #dc143c;">pprint</span><span style="color: black;">&#40;</span>problemFiles<span style="color: black;">&#41;</span></pre></div></div>

<p>NOTES: This will <strong>delete </strong>the .m4a file after converting it. If you want to keep your old files for some reason make sure to run this on a copy of your files. IE in a different directory.</p>
]]></content:encoded>
			<wfw:commentRss>http://bigbadcode.com/2007/06/06/convert-m4a-to-mp3/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

