Exemplo n.º 1
0
	def __init__(self, *args, **kwargs):
		self.stack = []
		self.data = []

		self.base_path = os.getcwd().replace(';','')

		self.svt = SVTMedia()

		self.player = xbmc.Player(xbmc.PLAYER_CORE_MPLAYER)

		self.stack.append(self.svt.get_start_url())

		self.inited = False
Exemplo n.º 2
0
class SVTGui(xbmcgui.WindowXML):
	CONTENT_LIST = 50
	ABOUT_BUTTON = 10
	SEARCH_BUTTON = 11

	def __init__(self, *args, **kwargs):
		self.stack = []
		self.data = []

		self.base_path = os.getcwd().replace(';','')

		self.svt = SVTMedia()

		self.player = xbmc.Player(xbmc.PLAYER_CORE_MPLAYER)

		self.stack.append(self.svt.get_start_url())

		self.inited = False

	def onInit(self):
		if not self.inited:
			try:
				self.list_contents(self.stack.pop())
				self.inited = True
			except:
				xbmc.log('Exception (init): ' + str(sys.exc_info()[0]))
				traceback.print_exc()
				self.close()

	def show_about(self):
		dlg = xbmcgui.Dialog()
		dlg.ok('Om', 'Av: Daniel Svensson, 2007',
		       'Paypal: [email protected]',
		       'Felrapporter: XBMC Forum - Python Script Development')

	def list_contents(self, url):
		data = self.download_data(url, self.svt.list_directory)
		if not self.populate_content_list(data):
			# Nothing to update.
			return False

		# Push directory to browsing stack
		self.stack.append(url)

		return True

	def search(self, term=None):
		if term is None:
			term = xbmcutils.gui.get_input('Search')

		# Only update the list if the user entered something.
		if term is None:
			return False

		data = self.download_data(term, self.svt.search)
		if not self.populate_content_list(data):
			return False

		# Dummy entry on the stack, search will only
		# return clips so no problemo.
		self.stack.append('search')

		return True

	def populate_content_list(self, data):
		if data is None:
			return False

		self.data = data

		list = self.getControl(SVTGui.CONTENT_LIST)

		xbmcgui.lock()
		list.reset()
		for desc, url, type in self.data:
			item = xbmcgui.ListItem (label=desc)
			if type is SVTMedia.DIR:
				item.setThumbnailImage('folder.png')
			elif type is SVTMedia.VIDEO:
				item.setThumbnailImage('video-x-generic.png')
			list.addItem(item)
		xbmcgui.unlock()

		return True

	def play_clip(self, url):
		file = self.download_data(url, self.svt.parse_video)
		if file is not None:
			self.player.play(str(file[0]))

	def update_progress(self, done, size, dlg):
		msg = 'Hamtar data (%dkB)' % int(done / 1024)
		percent = min(int((done * 100.0) / size), size)
		dlg.update(percent, msg)

		return not dlg.iscanceled()

	def download_data(self, url, func):
		data = None

		dlg = xbmcgui.DialogProgress()
		dlg.create('Sveriges Television', 'Hämtar data')

		self.svt.set_report_hook(self.update_progress, dlg)

		try:
			data = func(url)
		except ParseError, e:
			err_dlg = xbmcgui.Dialog()
			err_dlg.ok('Sveriges Television',
			           'Ett fel i programmet har påträffats.',
			           'Posta din XBMC\\xbmc.log på forumet.')
			print e
		except DownloadError, e:
			err_dlg = xbmcgui.Dialog()
			err_dlg.ok('Sveriges Television', 'Fel vid hämtning av data.')
			print e