Categories
Uncategorized

using python to set mp4 tags from a csv file

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

#!/usr/bin/python
import csv
import pipes
import StringIO

#metadata.csv has to contain the following rows:
#filename, show, season, episode, title, artwork, description
csvfile='metadata.csv'
csvreader = csv.reader(open(csvfile, 'rbU'), delimiter=',', quotechar='"')

class Command:
	def __init__(self, file):
		self.command = StringIO.StringIO()
		self.command.write('AtomicParsley ')
		self.command.write(pipes.quote(file))
	def addParam(self, key, value):
		self.command.write(' --')
		self.command.write(key)
		self.command.write(' ')
		self.command.write(pipes.quote(value))	
	def toString(self):
		return self.command.getvalue()
	def close(self):
		self.command.close()

def handleFile(row):
	m4vfile = row[0]
	show = row[1]
	season = row[2]
	episode = row[3]
	title = row[4]
	artwork = row[5]
	description = row[6]
	episodeCode = season + '' + str(episode).zfill(2) ##leading zeroes

	command = Command(m4vfile)
	
	command.addParam('artist', show)
	command.addParam('title', title)
	command.addParam('album', show + ', Season ' + season)
	command.addParam('artwork', artwork)
	command.addParam('stik', 'TV Show')
	command.addParam('description', description)
	command.addParam('TVShowName', show)
	command.addParam('TVEpisode', episodeCode)
	command.addParam('TVEpisodeNum', episode)
	command.addParam('TVSeasonNum', season)

	print command.toString()
	command.close()

for row in csvreader:
	handleFile(row)