#~DamnVid-module:revver

class DamnModule_Revver(DamnVideoModule):
	def __init__(self,uri):
		DamnVideoModule.__init__(self,uri)
		self.name='revver'
		self.regex={
			'url':re.compile('revver\.com/(?:video/)(\d+)/?',re.IGNORECASE)
		}
		self.api=xmlrpclib.Server('https://api.revver.com/xml/1.0?login=DamnVid&passwd=oc83Y8XYaIiSTTj3CHKt') # O noes it's a password
		self.valid=self.regex['url'].search(uri)
		self.info=None
		if self.valid:
			self.id='rv:'+self.valid.group(1)
			self.link='http://revver.com/video/'+self.valid.group(0)+'/'
	def revver_getInfo(self):
		if self.info is None:
			self.info=self.api.video.find({'ids':[int(self.id[3:])]},['title','quicktimeDownloadUrl','quicktimeMediaUrl'],{'limit':1})[0]
		return self.info
	def getTitle(self):
		if self.title is not None:
			return self.title
		self.title=self.revver_getInfo()['title']
		return DamnVideoModule.getTitle(self)
	def getFFmpegArgs(self):
		return ['-map','0:6','-map','0:7'] # Revver videos have lots of streams, the sixth one is actually the video stream, and the seventh one is the audio stream
	def renewTicket(self):
		self.newTicket([self.revver_getInfo()['quicktimeDownloadUrl'],self.revver_getInfo()['quicktimeMediaUrl']])
DamnRegisterModule({
	'name':'revver',
	'title':'Revver',
	'type':'video',
	'version':'1.0',
	'author':{
		'name':'Etienne Perot',
		'email':'admin@biringa.com',
		'url':'http://biringa.com/'
	},
	'icon':{
		'small':'revver.png',
		'large':'revver-large.png',
	},
	'about':{
		'short':'DamnVid module for Revver.',
		'long':"""This is a video plugin for DamnVid that adds Revver video downloading capabilities.""",
		'url':'http://code.google.com/p/damnvid/wiki/Modules'
	},
	'sites':[
		{
			'title':'Revver',
			'icon':'revver.png',
			'url':'http://revver.com/videos/'
		}
	],
	'class':DamnModule_Revver,
	'preferences':{
		'profile':{
			'name':'Default profile',
			'type':DV.preference_type_profile,
			'kind':'profile',
			'strict':True,
			'default':3
		},
		'outdir':{
			'name':'Output directory',
			'type':DV.preference_type_misc,
			'kind':'dir',
			'strict':True,
			'default':'?DAMNVID_MY_VIDEOS?/DamnVid/Revver/'
		}
	},
	'register':{
		'listicons':{
			'revver':'revver.png'
		}
	}
})
