using python to set mp4 tags from a csv file

using python to create the lengthy AtomicParsley calls described in the last post:

<br />
#!/usr/bin/python<br />
import csv<br />
import pipes<br />
import StringIO</p>
<p>#metadata.csv has to contain the following rows:<br />
#filename, show, season, episode, title, artwork, description<br />
csvfile='metadata.csv'<br />
csvreader = csv.reader(open(csvfile, 'rbU'), delimiter=',', quotechar='&quot;')</p>
<p>class Command:<br />
	def __init__(self, file):<br />
		self.command = StringIO.StringIO()<br />
		self.command.write('AtomicParsley ')<br />
		self.command.write(pipes.quote(file))<br />
	def addParam(self, key, value):<br />
		self.command.write(' --')<br />
		self.command.write(key)<br />
		self.command.write(' ')<br />
		self.command.write(pipes.quote(value))<br />
	def toString(self):<br />
		return self.command.getvalue()<br />
	def close(self):<br />
		self.command.close()</p>
<p>def handleFile(row):<br />
	m4vfile = row[0]<br />
	show = row[1]<br />
	season = row[2]<br />
	episode = row[3]<br />
	title = row[4]<br />
	artwork = row[5]<br />
	description = row[6]<br />
	episodeCode = season + '' + str(episode).zfill(2) ##leading zeroes</p>
<p>	command = Command(m4vfile)</p>
<p>	command.addParam('artist', show)<br />
	command.addParam('title', title)<br />
	command.addParam('album', show + ', Season ' + season)<br />
	command.addParam('artwork', artwork)<br />
	command.addParam('stik', 'TV Show')<br />
	command.addParam('description', description)<br />
	command.addParam('TVShowName', show)<br />
	command.addParam('TVEpisode', episodeCode)<br />
	command.addParam('TVEpisodeNum', episode)<br />
	command.addParam('TVSeasonNum', season)</p>
<p>	print command.toString()<br />
	command.close()</p>
<p>for row in csvreader:<br />
	handleFile(row)</p>
<p>

Comments are closed.