Example #1
0
	def active(self):
		util.LOG('SERVICE: ACTIVE')
				
		try:
			self.runServer()
		except:
			util.ERROR('Server Error')
			util.notify(util.T(32105),util.T(32106))
			xbmc.sleep(5000)

		if not xbmc.abortRequested: #If not shutting down, reset in case we died of error
			self.loadSettings()
Example #2
0
    def active(self):
        util.LOG('SERVICE: ACTIVE')

        try:
            self.runServer()
        except:
            util.ERROR('Server Error')
            util.notify(util.T(32105), util.T(32106))
            xbmc.sleep(5000)

        if not xbmc.abortRequested:  #If not shutting down, reset in case we died of error
            self.loadSettings()
Example #3
0
def isError(toCheck):
    try:
        if toCheck['error']:
            if toCheck['error_code'] == 8:
                # need to refresh token
                refreshToken()
                return 8
            else:
                util.notify(
                    "Error " + str(toCheck['error_code']) + ": " +
                    string.capwords(toCheck['error'].replace("_", " ")))
                util.logError("Error " + str(toCheck['error_code']) + ": " +
                              toCheck['error'])
                return True
    except:
        return False
def download(name, image, url, dest=addon.getSetting('download_path')):
    try:
        xbmc.executebuiltin('ActivateWindow(busydialognocancel)')
        import lib.control as control

        if url == None:
            return control.infoDialog(control.lang(30501).encode('utf-8'))
        headers = ("Authorization",
                   "Bearer " + str(xbmcaddon.Addon().getSetting('rd_access')))
        url = url.split('|')[0]

        content = re.compile('(.+?)\sS(\d*)E\d*$').findall(name)
        transname = name.translate('\/:*?"<>|').strip('.')
        levels = ['../../../..', '../../..', '../..', '..']

        dest = control.translatePath(dest)
        for level in levels:
            try:
                control.makeFile(os.path.abspath(os.path.join(dest, level)))
            except:
                pass
        control.makeFile(dest)
        dest = os.path.join(dest, os.path.splitext(transname)[0])

        control.makeFile(dest)
        dest = os.path.join(dest, transname)

        sysheaders = quote_plus(json.dumps(headers))

        sysurl = quote_plus(url)

        systitle = quote_plus(name)

        sysimage = quote_plus(image)

        sysdest = quote_plus(dest)

        script = inspect.getfile(inspect.currentframe())
        cmd = 'RunScript(%s, %s, %s, %s, %s, %s)' % (
            script, sysurl, sysdest, systitle, sysimage, sysheaders)

        xbmc.executebuiltin(cmd)

        xbmc.executebuiltin("Dialog.Close(busydialognocancel)")
    except:
        xbmc.executebuiltin("Dialog.Close(busydialognocancel)")
        util.notify(ADDON_ID, "Error Downloading")
Example #5
0
    def enableRecording(self, enable=True):
        if not os.path.exists(self.ACCESS_CONTROL_DIR_PATH):
            return

        with util.ServiceControl('service.multimedia.tvheadend.service'):
            for acf in os.listdir(self.ACCESS_CONTROL_DIR_PATH):
                full = os.path.join(self.ACCESS_CONTROL_DIR_PATH, acf)
                try:
                    with open(full, 'r') as f:
                        data = json.load(f)

                    data['dvr'] = enable
                    data['htsp_dvr'] = enable
                    data['all_dvr'] = enable
                    data['all_rw_dvr'] = enable

                    with open(full, 'w') as f:
                        json.dump(data, f, indent=4)

                except:
                    util.ERROR()
                    continue

            try:
                with open(self.TIMESHIFT_CONFIG_PATH, 'r') as f:
                    data = json.load(f)

                data['enabled'] = enable and 1 or 0
                data['ondemand'] = enable and 1 or 0
                data['path'] = self.timeshiftPath

                with open(self.TIMESHIFT_CONFIG_PATH, 'w') as f:
                    json.dump(data, f, indent=4)

            except:
                util.ERROR()

        msg = 'Recording {0}'.format(enable and 'Enabled' or 'Disabled')
        util.LOG(msg)
        util.notify(msg)
Example #6
0
    def enableRecording(self, enable=True):
        if not os.path.exists(self.ACCESS_CONTROL_DIR_PATH):
            return

        with util.ServiceControl('service.multimedia.tvheadend.service'):
            for acf in os.listdir(self.ACCESS_CONTROL_DIR_PATH):
                full = os.path.join(self.ACCESS_CONTROL_DIR_PATH, acf)
                try:
                    with open(full, 'r') as f:
                        data = json.load(f)

                    data['dvr'] = enable
                    data['htsp_dvr'] = enable
                    data['all_dvr'] = enable
                    data['all_rw_dvr'] = enable

                    with open(full, 'w') as f:
                        json.dump(data, f, indent=4)

                except:
                    util.ERROR()
                    continue

            try:
                with open(self.TIMESHIFT_CONFIG_PATH, 'r') as f:
                    data = json.load(f)

                data['enabled'] = enable and 1 or 0
                data['ondemand'] = enable and 1 or 0
                data['path'] = self.timeshiftPath

                with open(self.TIMESHIFT_CONFIG_PATH, 'w') as f:
                    json.dump(data, f, indent=4)

            except:
                util.ERROR()

        msg = 'Recording {0}'.format(enable and 'Enabled' or 'Disabled')
        util.LOG(msg)
        util.notify(msg)
Example #7
0
def unrestrict(parameters):
    cj_rd = cookielib.CookieJar()
    opener_rd = build_opener(HTTPCookieProcessor(cj_rd))
    opener_rd.addheaders = [
        ("Authorization", "Bearer " +
         str(xbmcaddon.Addon('script.realdebrid').getSetting('rd_access')))
    ]

    if 'url' in parameters:
        link = parameters['url']
    else:
        link = util.searchDialog("Enter link to unrestrict")

    if link:
        data_rd = urlencode({'link': link}).encode("utf-8")

        error = True
        attempts = 0
        while error:
            try:
                resp = opener_rd.open(
                    'https://api.real-debrid.com/rest/1.0/unrestrict/link',
                    data_rd)
                content = resp.read()

                credJSON = json.loads(content)
                error = True
                return credJSON
            except Exception as e:
                util.logError("realdebrid error: " + str(e))
                attempts = attempts + 1
                if attempts > 3:
                    error = True
                    util.notify("Unable to unrestrict link")
                    break
                elif "Unauthorized" in e:
                    refreshToken()

    return False
Example #8
0
    def runServer(self):
        while self.targetsBox.ready() and not xbmc.abortRequested:
            self.targetsBox.join()
            if self.targetsBox.device.hasPush():
                if self.instantPlay:
                    if not StreamUtils.isPlaying() or self.interruptMedia:
                        data = self.targetsBox.device.getNext()
                        if data: pushhandler.handlePush(data)
                else:
                    if self.showNotification:
                        data = self.targetsBox.device.getNext()
                        if data:
                            util.notify(
                                '{0}: {1}'.format(util.T(32090),
                                                  data.get('type', '?')),
                                data.get('title', ''))
                    self.targetsBox.device.clear()

            xbmc.sleep(200)

        self.targetsBox.close()
        self.targetsBox = None
Example #9
0
	def runServer(self):
		while self.targetsBox.ready() and not xbmc.abortRequested:
			self.targetsBox.join()
			if self.targetsBox.device.hasPush():
				if self.instantPlay:
					if not StreamUtils.isPlaying() or self.interruptMedia:
						data = self.targetsBox.device.getNext()
						if data: pushhandler.handlePush(data)
				else:
					if self.showNotification:
						data = self.targetsBox.device.getNext()
						if data:
							util.notify(
								'{0}: {1}'.format(util.T(32090),data.get('type','?')),
								data.get('title','')
							)
					self.targetsBox.device.clear()

			xbmc.sleep(200)
		
		self.targetsBox.close()
		self.targetsBox = None