"""
- Copyright (c) 2007 Daniel Svensson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
import xbmcgui import xbmc import os import sys import traceback
from xbmcutils.net import DownloadAbort, DownloadError
import xbmcutils.gui
from SVT import SVTMedia, ParseError
class Logger:
- def write(data):
- xbmc.log(data)
sys.stdout = Logger sys.stderr = Logger
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
- if not self.inited:
- try:
- self.list_contents(self.stack.pop()) self.inited = True
- xbmc.log('Exception (init): ' + str(sys.exc_info()[0])) traceback.print_exc() self.close()
- try:
- dlg = xbmcgui.Dialog() dlg.ok('Om', 'Av: Daniel Svensson, 2007',
'Paypal: dsvensson@gmail.com', 'Felrapporter: XBMC Forum - Python Script Development')
- data = self.download_data(url, self.svt.list_directory) if not self.populate_content_list(data):
- # Nothing to update. return False
- if term is None:
- term = xbmcutils.gui.get_input('Search')
- return False
- return False
- if data is None:
- return False
item = xbmcgui.ListItem (label=desc) if type is SVTMedia.DIR:
- item.setThumbnailImage('folder.png')
- item.setThumbnailImage('video-x-generic.png')
- file = self.download_data(url, self.svt.parse_video) if file is not None:
- self.player.play(str(file[0]))
- msg = 'Hamtar data (%dkB)' % int(done / 1024) percent = min(int((done * 100.0) / size), size) dlg.update(percent, msg) return not dlg.iscanceled()
- 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.')
except DownloadError, e:
- err_dlg = xbmcgui.Dialog() err_dlg.ok('Sveriges Television', 'Fel vid hämtning av data.') print e
except DownloadAbort, e:
- pass
- pass
- try:
- if control_id == SVTGui.CONTENT_LIST:
- list = self.getControl(SVTGui.CONTENT_LIST) pos = list.getSelectedPosition() desc, url, type = self.data[pos] if type is SVTMedia.DIR:
- self.list_contents(url)
- self.play_clip(url)
- self.show_about()
- self.search()
- list = self.getControl(SVTGui.CONTENT_LIST) pos = list.getSelectedPosition() desc, url, type = self.data[pos] if type is SVTMedia.DIR:
- xbmc.log('Exception (onControl): ' + str(sys.exc_info()[0])) traceback.print_exc() self.close()
- if control_id == SVTGui.CONTENT_LIST:
- try:
- if action == xbmcutils.gui.ACTION_PREVIOUS_MENU:
- self.close()
elif action == xbmcutils.gui.ACTION_PARENT_DIR and len(self.stack) > 1:
- cur = self.stack.pop() prev = self.stack.pop() if not self.list_contents(prev):
- # User aborted, still at the same ol' position. self.stack.append(prev) self.stack.append(cur)
- xbmc.log('Exception (onAction): ' + str(sys.exc_info()[0])) traceback.print_exc() self.close()
- if action == xbmcutils.gui.ACTION_PREVIOUS_MENU:
- self.stack = [] self.data = []
res_path = os.getcwd().replace(';',) svt = SVTGui('main.xml', res_path) svt.doModal() del svt