Exemplo n.º 1
0
	def onInit(self):
		try:
			self.getControl(401).addLabel(commons.translate(30002))
			self.getControl(402).addLabel(commons.translate(30010) % self.TIMEOUT)
		except AttributeError:
			self.getControl(401).setLabel(commons.translate(30002))
			self.getControl(402).setLabel(commons.translate(30010) % self.TIMEOUT)
Exemplo n.º 2
0
	def start(self):
		while True:
			idx = xbmcgui.Dialog().select(commons.translate(30007), self.WINDOWS.values())
			if idx == -1:
				break
			window = self.WINDOWS.keys()[idx]
			while True:
				idx = xbmcgui.Dialog().select(commons.translate(30008), self.ACTIONS.keys())
				if idx == -1:
					break
				category = self.ACTIONS.keys()[idx]
				while True:
					curr_keymap = self._current_keymap(window, category)
					labels = ["%s - %s" % (name, key) for _, key, name in curr_keymap]
					idx = xbmcgui.Dialog().select(commons.translate(30009), labels)
					if idx == -1:
						break
					action, oldkey, _ = curr_keymap[idx]
					newkey = KeyListener.record_key()
					if newkey is None:
						continue
					old = (window, action, oldkey)
					new = (window, action, newkey)
					if old in self.userkeymap:
						self.userkeymap.remove(old)
					self.userkeymap.append(new)
					if old != new:
						self.dirty = True
Exemplo n.º 3
0
 def __init__(self):
     self.userdata = xbmc.translatePath('special://userdata/keymaps')
     self.userkeymapfile = os.path.join(self.userdata, 'gen.xml')
     self.userkeymap = []
     self.syskeymapfile = xbmc.translatePath(
         'special://xbmc/system/keymaps/keyboard.xml')
     self.syskeymap = []
     try:
         if not os.path.exists(self.userdata):
             os.makedirs(self.userdata)
         else:
             # make sure there are no user defined keymaps
             for name in os.listdir(self.userdata):
                 if name.endswith('.xml') and name != os.path.basename(
                         self.userkeymapfile):
                     src = os.path.join(self.userdata, name)
                     for i in xrange(100):
                         dst = os.path.join(self.userdata,
                                            "%s.bak.%d" % (name, i))
                         if os.path.exists(dst):
                             continue
                         shutil.move(src, dst)
                         # successfully renamed
                         break
     except Exception as ex:
         KeyEditor.rpc('GUI.ShowNotification',
                       title="Keymap Editor",
                       message=commons.translate(30011),
                       image='error')
         commons.debug("Failed to remove old keymap file: %s" % str(ex))
     # load system keymap
     if os.path.exists(self.syskeymapfile):
         try:
             self.syskeymap = self.getKeymap(self.syskeymapfile)
         except Exception as ex:
             KeyEditor.rpc('GUI.ShowNotification',
                           title="Keymap Editor",
                           message=commons.translate(30012),
                           image='error')
             commons.error("Failed to load system keymap file: %s" %
                           str(ex))
     # load user keymap
     if os.path.exists(self.userkeymapfile):
         try:
             self.userkeymap = self.getKeymap(self.userkeymapfile)
         except Exception as ex:
             KeyEditor.rpc('GUI.ShowNotification',
                           title="Keymap Editor",
                           message=commons.translate(30013),
                           image='error')
             commons.error("Failed to load user keymap file: %s" % str(ex))
Exemplo n.º 4
0
 def execute(self):
     confirm_discard = False
     while True:
         idx = xbmcgui.Dialog().select(commons.translate(30000), [
             commons.translate(30003),
             commons.translate(30004),
             commons.translate(30005)
         ])
         if idx == 0:
             # edit
             editor = KeyEditor(self.syskeymap, self.userkeymap)
             editor.start()
             confirm_discard = editor.dirty
         elif idx == 1:
             # reset
             confirm_discard = bool(self.userkeymap)
             self.userkeymap = []
         elif idx == 2:
             # save
             if os.path.exists(self.userkeymapfile):
                 shutil.copyfile(self.userkeymapfile,
                                 self.userkeymapfile + ".old")
             self.setKeymap(self.userkeymap, self.userkeymapfile)
             xbmc.executebuiltin("action(reloadkeymaps)")
             break
         elif idx == -1 and confirm_discard:
             if xbmcgui.Dialog().yesno(commons.translate(30000),
                                       commons.translate(30006)) == 1:
                 break
         else:
             break
     sys.modules.clear()
Exemplo n.º 5
0
 def getChannelV1(self, channel):
     # 0. Initialize browser
     browser = urllib2.build_opener(
         urllib2.HTTPCookieProcessor(self.getCookie()))
     commons.debug("Initializing browser using cookie: %s" %
                   str(self._cookie))
     # 1. Run data collection process: epg info, channel scope and master key
     try:
         url = HTMLParser.HTMLParser().unescape(channel["url"])
         commons.debug(
             "Executing HTTP GET call to collect channel data: %s" % url)
         httpget = browser.open(url)
         content = httpget.read()
     except:
         content = ''
         pass
     # 1.1 Identify epg info
     if content is not None and '<div class="info" epg-data=' in content:
         seps = ["[", "]", "'", "{", "}", "start:", "stop:", "title:"]
         tagdata = str(
             re.compile('<div class="info" epg-data="(.+?)"').findall(
                 content)).replace("&quot;", "")
         for i in range(len(seps)):
             tagdata = tagdata.replace(str(seps[i]), "")
         if len(tagdata) > 0:
             parts = tagdata.split(',')
             nowinfo = None
             nextinfo = None
             try:
                 nowinfo = commons.translate(30010) + ": " + time.strftime(
                     "%H:%M", time.localtime(int(
                         parts[1]))) + " - " + time.strftime(
                             "%H:%M", time.localtime(int(
                                 parts[2]))) + " " + str(parts[0])
                 nextinfo = commons.translate(30011) + ": " + time.strftime(
                     "%H:%M", time.localtime(int(
                         parts[4]))) + " - " + time.strftime(
                             "%H:%M", time.localtime(int(
                                 parts[5]))) + " " + str(parts[3])
             except:
                 pass
             if nowinfo is not None and nextinfo is not None:
                 channel["plot"] = nowinfo + " | " + nextinfo
             elif nowinfo is not None and nextinfo is None:
                 channel["plot"] = nowinfo
         if channel.get("plot") is not None:
             commons.debug("Added [plot] property to '%s' channel: %s" %
                           (channel["id"], channel["plot"]))
     # 1.2 Identify channel scope
     match = re.compile('data-balancer-scope-name="(.+?)"').findall(content)
     if len(match) > 0:
         channel["scope"] = str(match[0]).strip()
     else:
         channel["scope"] = channel["id"]
     commons.debug("Added [scope] property to '%s' channel: %s" %
                   (channel["id"], channel["scope"]))
     # 1.3 Identify master key
     match = re.compile('data-balancer-key="(.+?)"').findall(content)
     if len(match) > 0:
         channel["key"] = str(match[0]).strip()
         commons.debug("Added [key] property to '%s' channel: %s" %
                       (channel["id"], channel["key"]))
     # 2. Run Authentication process for configured account
     if commons.any2bool(channel["auth"]) and commons.setting(
             "digionline.login.enabled"):
         url = "http://www.digi-online.ro/xhr-login.php"
         browser.addheaders = [('Host', "www.digi-online.ro"),
                               ('Accept', '*/*'),
                               ('Origin', "http://www.digi-online.ro"),
                               ('X-Requested-With', 'XMLHttpRequest'),
                               ('User-Agent', self.getAgent()),
                               ('Content-type',
                                'application/x-www-form-urlencoded'),
                               ('Referer', "http://www.digi-online.ro"),
                               ('Accept-Encoding', 'identity'),
                               ('Accept-Language', 'en-ie'),
                               ('Connection', 'close')]
         formdata = urllib.urlencode({
             'user':
             commons.getSetting('digionline.login.username'),
             'password':
             commons.getSetting('digionline.login.password'),
             'browser':
             self._appname,
             'model':
             self._appversion,
             'os':
             self._osname
         })
         try:
             commons.debug(
                 "Executing HTTP POST for authentication: %s, form data: %s"
                 % (url, formdata))
             httppost = browser.open(url, formdata)
             response = httppost.read()
             commons.debug("Received HTTP POST answer: %s" % response)
         except:
             raise LoginException(commons.translate(30051))
         if commons.any2bool(response):
             for cookie in self._cookie:
                 if str(cookie.name) == 'sid':
                     channel["sid"] = str(cookie.value).strip()
                     commons.debug(
                         "Added [sid] property to '%s' channel: %s" %
                         (channel["id"], channel["sid"]))
         else:
             raise LoginException(commons.translate(30050))
     elif commons.any2bool(channel["auth"]) and not commons.setting(
             "digionline.login.enabled"):
         raise LoginException(commons.translate(30052))
     # 3.1 Execute authorization to access resources
     url = 'http://www.digi-online.ro/xhr-gen-stream.php'
     browser.addheaders = [('X-Requested-With', 'XMLHttpRequest')]
     formdata = urllib.urlencode({'scope': channel["scope"]})
     try:
         commons.debug(
             "Executing HTTP POST call to authorize the scope: %s, form data: %s"
             % (url, formdata))
         httppost = browser.open(url, formdata)
         response = httppost.read()
         commons.debug("Received HTTP GET answer: %s" % response)
     except:
         pass
     # 3.2 Generates master key if is not already detected
     if channel.get("key") is None:
         url = "http://balancer.digi24.ro/streamer/make_key.php"
         browser.addheaders = [('Host', "balancer.digi24.ro"),
                               ('Accept', '*/*'),
                               ('Origin', "http://www.digi-online.ro"),
                               ('User-Agent', self.getAgent()),
                               ('Referer', channel["url"]),
                               ('Accept-Encoding', 'identity'),
                               ('Accept-Language', 'en-GB,en;q=0.5'),
                               ('Connection', 'close')]
         try:
             commons.debug("Executing HTTP GET call to get master key: %s" %
                           url)
             httpget = browser.open(url)
             content = httpget.read()
             commons.debug("Received HTTP GET answer: %s" % content)
         except:
             content = ''
             pass
         if len(content) > 0:
             channel["key"] = str(content)
             commons.debug("Added [key] property to '%s' channel: %s" %
                           (channel["id"], channel["key"]))
     # 3.3 Get video information
     url = 'http://balancer.digi24.ro/streamer.php?&scope=' + channel[
         "scope"] + '&key=' + channel[
             "key"] + '&outputFormat=json&type=hls&quality=' + commons.getSetting(
                 "digionline.playback.quality")
     try:
         commons.debug(
             "Executing HTTP GET call to obtain video information: %s" %
             url)
         content = browser.open(url).read()
         commons.debug("Received HTTP GET answer: %s" % content)
     except:
         raise DigiOnlineException(commons.translate(30053))
     data = json.loads(content)
     if data.get("file") is not None and "http:" not in data["file"]:
         channel["url"] = "http:" + data["file"]
     elif data.get("file") is not None and "http:" not in data["file"]:
         channel["url"] = data["file"]
     else:
         raise DigiOnlineException(commons.translate(30054))
     commons.debug("Updated [url] property to '%s' channel: %s" %
                   (channel["id"], channel["url"]))
     return channel