<?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>blog.autopsy.se &#187; mpg321</title>
	<atom:link href="http://blog.autopsy.se/tag/mpg321/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.autopsy.se</link>
	<description>basically; it sucks. everything sucks. but.. in a good way..</description>
	<lastBuildDate>Wed, 23 Nov 2011 18:25:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Converting audiobooks to m4b sucks!</title>
		<link>http://blog.autopsy.se/2009/02/converting-audiobooks-to-m4b-sucks/</link>
		<comments>http://blog.autopsy.se/2009/02/converting-audiobooks-to-m4b-sucks/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 13:50:22 +0000</pubDate>
		<dc:creator>ube</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Audiobooks]]></category>
		<category><![CDATA[faac]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[iPod]]></category>
		<category><![CDATA[iTunes]]></category>
		<category><![CDATA[mpg321]]></category>

		<guid isPermaLink="false">http://blog.autopsy.se/?p=75</guid>
		<description><![CDATA[Ok, I download stuff from the internet so sue me! Since I'm an iSheep I want to use my iPod/iPhone to listen to to my audiobooks that I download. The problem with this is that all releases are in MP3 format and this messes up my play lists when doing a shuffle of all songs; [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, I download stuff from the internet so <a title="sue me!" href="http://www.thelocal.se/tag/Pirate_Bay" target="_blank">sue me!</a> Since I'm an iSheep I want to use my iPod/iPhone to listen to to my audiobooks that I <a title="download" href="http://thepiratebay.org" target="_blank">download</a>. The problem with this is that all releases are in MP3 format and this messes up my play lists when doing a shuffle of all songs; all of a sudden there is a chapter from an audiobook read. So, what to do. A cupple of months ago I wrote a script that converted m3u to m4b, and now I've rewritten it. So, here it is! Execute the script with directory-with-m3u-files as argument.</p>
<p><span id="more-75"></span></p>
<pre class="perl"><span style="color: #808080; font-style: italic;">#!/usr/bin/perl</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> File::<span style="color: #006600;">Basename</span>;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@m3u</span>;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@files</span>;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$f</span>;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$count</span> = <span style="color: #cc66cc;">1</span>;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$discs</span>;
<a href="http://perldoc.perl.org/functions/opendir.html"><span style="color: #000066;">opendir</span></a><span style="color: #66cc66;">&#40;</span>DIR, <span style="color: #0000ff;">$ARGV</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">or</span> <a href="http://perldoc.perl.org/functions/die.html"><span style="color: #000066;">die</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Can't open <span style="color: #000099; font-weight: bold;">\&quot;</span>$ARGV[0]<span style="color: #000099; font-weight: bold;">\&quot;</span>!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">@files</span> = <a href="http://perldoc.perl.org/functions/readdir.html"><span style="color: #000066;">readdir</span></a><span style="color: #66cc66;">&#40;</span>DIR<span style="color: #66cc66;">&#41;</span>;
<a href="http://perldoc.perl.org/functions/closedir.html"><span style="color: #000066;">closedir</span></a><span style="color: #66cc66;">&#40;</span>DIR<span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$path</span> = <span style="color: #0000ff;">$ARGV</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>;
<span style="color: #b1b100;">foreach</span> <span style="color: #0000ff;">$f</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">@files</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> ! -d <span style="color: #0000ff;">$f</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$f</span> =~ <a href="http://perldoc.perl.org/functions/m.html"><span style="color: #000066;">m</span></a>/^.*\.m3u$/<span style="color: #66cc66;">&#41;</span> &amp;&amp; ! <span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">$f</span> =~ <a href="http://perldoc.perl.org/functions/m.html"><span style="color: #000066;">m</span></a>/^<span style="color: #cc66cc;">0000</span>.*$/<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                        <a href="http://perldoc.perl.org/functions/push.html"><span style="color: #000066;">push</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">@m3u</span>, <span style="color: #0000ff;">$f</span><span style="color: #66cc66;">&#41;</span>;
                <span style="color: #66cc66;">&#125;</span>
&nbsp;
        <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #0000ff;">@m3u</span> = <a href="http://perldoc.perl.org/functions/sort.html"><span style="color: #000066;">sort</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">@m3u</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$discs</span> = <span style="color: #0000ff;">@m3u</span>;
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;Found $discs m3u files.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
<span style="color: #b1b100;">foreach</span> <span style="color: #0000ff;">$m</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">@m3u</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@data</span>;
        <span style="color: #0000ff;">$file</span> = <span style="color: #0000ff;">$m</span>;
        <span style="color: #0000ff;">$file</span> =~ <a href="http://perldoc.perl.org/functions/s.html"><span style="color: #000066;">s</span></a>/^<span style="color: #66cc66;">&#40;</span>.*<span style="color: #66cc66;">&#41;</span>\..*/\<span style="color: #cc66cc;">1</span>/;
        <span style="color: #0000ff;">$outfile</span> = <span style="color: #0000ff;">$file</span>.<span style="color: #ff0000;">&quot;.m4b&quot;</span>;
        <a href="http://perldoc.perl.org/functions/open.html"><span style="color: #000066;">open</span></a> ID3, <span style="color: #ff0000;">&quot;&lt;$ARGV[0]/$m&quot;</span> <span style="color: #b1b100;">or</span> <a href="http://perldoc.perl.org/functions/die.html"><span style="color: #000066;">die</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;File <span style="color: #000099; font-weight: bold;">\&quot;</span>$ARGV[0]/$m<span style="color: #000099; font-weight: bold;">\&quot;</span> not found!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #009999;">&lt;ID3&gt;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                <a href="http://perldoc.perl.org/functions/push.html"><span style="color: #000066;">push</span></a> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">@data</span>,<span style="color: #0000ff;">$_</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
        <a href="http://perldoc.perl.org/functions/close.html"><span style="color: #000066;">close</span></a><span style="color: #66cc66;">&#40;</span>ID3<span style="color: #66cc66;">&#41;</span>;
        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> -f tmpfile <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                <a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;tmpfile found.. Deleteing<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
                <a href="http://perldoc.perl.org/functions/unlink.html"><span style="color: #000066;">unlink</span></a><span style="color: #66cc66;">&#40;</span>tmpfile<span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
        <a href="http://perldoc.perl.org/functions/open.html"><span style="color: #000066;">open</span></a><span style="color: #66cc66;">&#40;</span>TMPFILE, <span style="color: #ff0000;">&quot;&gt;tmpfile&quot;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #b1b100;">foreach</span> <span style="color: #0000ff;">$line</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">@data</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">$line</span> =~ <a href="http://perldoc.perl.org/functions/m.html"><span style="color: #000066;">m</span></a>/^<span style="color: #808080; font-style: italic;">#.*/ ) {</span>
                <span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
                        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">$line</span> !=~ <a href="http://perldoc.perl.org/functions/m.html"><span style="color: #000066;">m</span></a>/.*\.rar.*/ <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                                <a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> TMPFILE <span style="color: #ff0000;">&quot;$path/$line&quot;</span>;
                        <span style="color: #66cc66;">&#125;</span>
                <span style="color: #66cc66;">&#125;</span>
        <span style="color: #66cc66;">&#125;</span>
        <a href="http://perldoc.perl.org/functions/close.html"><span style="color: #000066;">close</span></a><span style="color: #66cc66;">&#40;</span>TMPFILE<span style="color: #66cc66;">&#41;</span>;
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$id3</span> = `head <span style="color: #cc66cc;">-1</span> tmpfile`;
        <a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;Getting id3-data from $id3<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
        <span style="color: #0000ff;">@id3</span> = `id3v2 --list <span style="color: #0000ff;">$id3</span>`;
        <span style="color: #b1b100;">foreach</span> <span style="color: #0000ff;">$line</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">@id3</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">$line</span> =~ <a href="http://perldoc.perl.org/functions/m.html"><span style="color: #000066;">m</span></a>/^TALB.*/ <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                        <span style="color: #0000ff;">$TITLE</span> = <span style="color: #0000ff;">$line</span>;
                        <span style="color: #0000ff;">$TITLE</span> =~ <a href="http://perldoc.perl.org/functions/s.html"><span style="color: #000066;">s</span></a>/^.*: <span style="color: #66cc66;">&#40;</span>.*<span style="color: #66cc66;">&#41;</span>\n$/\<span style="color: #cc66cc;">1</span>/;
                <span style="color: #66cc66;">&#125;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">$line</span> =~ <a href="http://perldoc.perl.org/functions/m.html"><span style="color: #000066;">m</span></a>/^TPE1.*/ <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                        <span style="color: #0000ff;">$AUTH</span> = <span style="color: #0000ff;">$line</span>;
                        <span style="color: #0000ff;">$AUTH</span> =~ <a href="http://perldoc.perl.org/functions/s.html"><span style="color: #000066;">s</span></a>/^.*: <span style="color: #66cc66;">&#40;</span>.*<span style="color: #66cc66;">&#41;</span>\n$/\<span style="color: #cc66cc;">1</span>/;
                <span style="color: #66cc66;">&#125;</span>
        <span style="color: #66cc66;">&#125;</span>
        <a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;Got:<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
        <a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;Title:  $TITLE<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
        <a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;Author: $AUTH<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
        <a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;Output: $outfile<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
        <a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;Converting..<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
        <a href="http://perldoc.perl.org/functions/system.html"><span style="color: #000066;">system</span></a> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;mpg321 -@ tmpfile -q -w - | faac -w --disc <span style="color: #000099; font-weight: bold;">\&quot;</span>$count/$discs<span style="color: #000099; font-weight: bold;">\&quot;</span> --track <span style="color: #000099; font-weight: bold;">\&quot;</span>1/1<span style="color: #000099; font-weight: bold;">\&quot;</span> --artist <span style="color: #000099; font-weight: bold;">\</span>
<span style="color: #000099; font-weight: bold;">\&quot;</span>$AUTH<span style="color: #000099; font-weight: bold;">\&quot;</span> --title <span style="color: #000099; font-weight: bold;">\&quot;</span>$TITLE<span style="color: #000099; font-weight: bold;">\&quot;</span> --album <span style="color: #000099; font-weight: bold;">\&quot;</span>$TITLE<span style="color: #000099; font-weight: bold;">\&quot;</span> --writer  <span style="color: #000099; font-weight: bold;">\&quot;</span>$AUTH<span style="color: #000099; font-weight: bold;">\&quot;</span> <span style="color: #000099; font-weight: bold;">\</span>
--genre <span style="color: #000099; font-weight: bold;">\&quot;</span>Audiobook<span style="color: #000099; font-weight: bold;">\&quot;</span> -o <span style="color: #000099; font-weight: bold;">\&quot;</span>$file.m4b<span style="color: #000099; font-weight: bold;">\&quot;</span> - &quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
        <span style="color: #0000ff;">$count</span>++;
<span style="color: #66cc66;">&#125;</span>
        <a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;Done, I think.. Have a nice day!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.autopsy.se/2009/02/converting-audiobooks-to-m4b-sucks/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

