<?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>Gaurav &#187; ID3</title>
	<atom:link href="http://allyourcodearebelongto.me/blog/category/id3/feed/" rel="self" type="application/rss+xml" />
	<link>http://allyourcodearebelongto.me/blog</link>
	<description>All About Everything</description>
	<lastBuildDate>Sun, 23 Nov 2008 19:44:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Renaming MP3 files based on ID3 tag information</title>
		<link>http://allyourcodearebelongto.me/blog/2007/11/27/renaming-mp3-files-with-id3-tag-title-using-ruby/</link>
		<comments>http://allyourcodearebelongto.me/blog/2007/11/27/renaming-mp3-files-with-id3-tag-title-using-ruby/#comments</comments>
		<pubDate>Tue, 27 Nov 2007 16:35:59 +0000</pubDate>
		<dc:creator>Gaurav</dc:creator>
				<category><![CDATA[ID3]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://techblogging.wordpress.com/2007/11/27/renaming-mp3-files-with-id3-tag-title-using-ruby/</guid>
		<description><![CDATA[Here is a neat little trick that I often find useful for renaming mp3 files with wrong names and correct tag titles. Just run this ruby script in the directory where you have stored your songs and it will read the tag title and rename the current file using it.


   1: require "rubygems"
 [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a neat little trick that I often find useful for renaming mp3 files with wrong names and correct tag titles. Just run this ruby script in the directory where you have stored your songs and it will read the tag title and rename the current file using it.</p>
<div style="border-right:gray 1px solid;border-top:gray 1px solid;font-size:8pt;overflow:auto;border-left:gray 1px solid;width:97.5%;cursor:text;max-height:200px;line-height:12pt;border-bottom:gray 1px solid;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> require <span style="color:#006080;">"rubygems"</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span> require <span style="color:#006080;">"id3lib"</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span> require <span style="color:#006080;">"fileutils"</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span> files = `dir /s /b *.mp3`</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span>&nbsp; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span> files.split(<span style="color:#006080;">"\n"</span>).<span style="color:#0000ff;">each</span> <span style="color:#0000ff;">do</span> |file|</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span>   dir = File.dirname(file)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   9:</span>   tag = ID3Lib::Tag.<span style="color:#0000ff;">new</span>(file)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  10:</span>   new_name = tag.title.gsub(<span style="color:#006080;">"00"</span>,<span style="color:#008000;">'') if tag.title</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  11:</span>   FileUtils.move(file, File.join(dir, new_name + <span style="color:#006080;">".mp3"</span>)) <span style="color:#0000ff;">if</span> new_name <span style="color:#0000ff;">and</span> !new_name.empty? rescue nil</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  12:</span> end</pre>
</div>
</div>
<p>This script requires id3lib gem for ruby which can be installed simply by running the command:</p>
<p>gem install id3lib-ruby</p>
<p>One thing to notice in the script is that currently it works only on windows, but only with a little modification it can be made to work on other OSes as well (The only change I guess will be in the 5th line).</p>
<p><a href="http://pastie.caboo.se/173944">Here</a> is the pastie link for this code.</p>
<div class="wlWriterSmartContent" id="f0b1a552-8a56-4ff5-a150-53d6990b5aa8" style="display:inline;margin:0;padding:0;">del.icio.us Tags: <a href="http://del.icio.us/popular/id3" rel="tag">id3</a>,<a href="http://del.icio.us/popular/mp3" rel="tag">mp3</a>,<a href="http://del.icio.us/popular/winamp" rel="tag">winamp</a></div>
]]></content:encoded>
			<wfw:commentRss>http://allyourcodearebelongto.me/blog/2007/11/27/renaming-mp3-files-with-id3-tag-title-using-ruby/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

