<?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>directory tree &#8211; Accidents Happen</title>
	<atom:link href="https://ah.thameera.com/tag/directory-tree/feed/" rel="self" type="application/rss+xml" />
	<link>https://ah.thameera.com</link>
	<description>In the dark</description>
	<lastBuildDate>Sun, 11 Nov 2012 17:19:45 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
<site xmlns="com-wordpress:feed-additions:1">56521109</site>	<item>
		<title>Processing music tags with Python</title>
		<link>https://ah.thameera.com/processing-music-tags-with-python/</link>
					<comments>https://ah.thameera.com/processing-music-tags-with-python/#respond</comments>
		
		<dc:creator><![CDATA[thameera]]></dc:creator>
		<pubDate>Sun, 11 Nov 2012 17:19:45 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[directory tree]]></category>
		<category><![CDATA[id3reader]]></category>
		<category><![CDATA[mp3]]></category>
		<category><![CDATA[music]]></category>
		<category><![CDATA[python]]></category>
		<guid isPermaLink="false">http://noisythameera.wordpress.com/?p=236</guid>

					<description><![CDATA[I was looking for the optimal way to traverse the directory tree with Python and found out that os.walk is the answer. To put this into practice, I wrote the following script which traverses the music library and finds out which MP3s haven&#8217;t been properly tagged. In other words, it will print the full paths [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>I was looking for the optimal way to traverse the directory tree with Python and <a href="http://pythoncentral.org/how-to-traverse-a-directory-tree/" target="_blank">found out</a> that <code>os.walk</code> is the answer. To put this into practice, I wrote the following script which traverses the music library and finds out which MP3s haven&#8217;t been properly tagged. In other words, it will print the full paths of all MP3s that have any of the artist, album or title tracks missing. In my case, 502 of the 10466 songs had bad tags.</p>
<p>[sourcecode language=&#8221;python&#8221;]<br />
#!/usr/bin/python</p>
<p>import os<br />
import id3reader</p>
<p>rootdir = &quot;/home/thameera/Music&quot;<br />
processed = 0<br />
bad = 0</p>
<p>for thisDir, subdirList, fileList in os.walk(rootdir):<br />
	for fname in fileList:<br />
		if fname[-3:] == &#039;mp3&#039;:<br />
			processed += 1<br />
			fullPath = os.path.join(thisDir, fname)</p>
<p>			try:<br />
				id3r = id3reader.Reader(fullPath)<br />
			except:<br />
				bad += 1<br />
				print &quot;Error extracting id3 info from %s&quot; % fullPath<br />
				continue</p>
<p>			if None in (id3r.getValue(&#039;performer&#039;), id3r.getValue(&#039;album&#039;), id3r.getValue(&#039;title&#039;)):<br />
				bad += 1<br />
				print fullPath</p>
<p>print &quot;%d MP3s processed. Found bad tags in %d of them&quot; % (processed, bad)<br />
[/sourcecode]</p>
<p>It uses the <code><a href="http://nedbatchelder.com/code/modules/id3reader.html" target="_blank">id3reader</a></code> library to parse the tags. I don&#8217;t think it&#8217;ll work if you have files with other formats, like wma or flac. </p>
<p>This script can be further expanded to ignore certain directories, output only one entry per each directory that has bad tags, check for other tags as well, check if the artist tag does not match the name of the parent directory, etc, etc. </p>
]]></content:encoded>
					
					<wfw:commentRss>https://ah.thameera.com/processing-music-tags-with-python/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">236</post-id>	</item>
	</channel>
</rss>
