def refresh_token():
	url = 'https://api.real-debrid.com/oauth/v2/token'
	data = {'client_id': kodi.get_setting('realdebrid_client_id', addon_id='script.module.scrapecore'), 'client_secret': kodi.get_setting('realdebrid_client_secret', addon_id='script.module.scrapecore'), 'code': kodi.get_setting('realdebrid_refresh_token', addon_id='script.module.scrapecore'), 'grant_type': 'http://oauth.net/grant_type/device/1.0'}
	response = session.post(url, data=data)
	response.json()
	if 'access_token' in response:
		kodi.set_setting('realdebrid_token', response['access_token'], addon_id='script.module.scrapecore')
	return response		
Beispiel #2
0
	def get_user_agent(self):
		user_agent = kodi.get_setting('user_agent')
		try: agent_refresh_time = int(kodi.get_setting('agent_refresh_time'))
		except: agent_refresh_time = 0
		if not user_agent or agent_refresh_time < (time.time() - (7 * 24 * 60 * 60)):
			user_agent = self.generate_user_agent()
			kodi.set_setting('user_agent', user_agent)
			kodi.set_setting('agent_refresh_time', str(int(time.time())))
		return user_agent
 def onInit(self):
     response = request_code()
     self.device_code = response['device_code']
     self.user_code = response['user_code']
     self.timeout = int(response['expires_in'])
     self.getControl(CONTROLS.CODE).setLabel(self.user_code)
     for tick in range(self.timeout, 0, -1):
         if tick == 0 or self._abort: break
         width = (float(tick) / self.timeout) * 596
         self.getControl(CONTROLS.PROGRESS).setWidth(int(width))
         if (tick % 5) == 0:
             r = poll_credentials(self.device_code)
             if r:
                 client_id = r['client_id']
                 client_secret = r['client_secret']
                 token = request_token(client_id, client_secret,
                                       self.device_code)
                 kodi.set_setting('realdebrid_client_id',
                                  client_id,
                                  addon_id='script.module.scrapecore')
                 kodi.set_setting('realdebrid_client_secret',
                                  client_secret,
                                  addon_id='script.module.scrapecore')
                 kodi.set_setting('realdebrid_token',
                                  token['access_token'],
                                  addon_id='script.module.scrapecore')
                 kodi.set_setting('realdebrid_refresh_token',
                                  token['refresh_token'],
                                  addon_id='script.module.scrapecore')
                 kodi.notify("RealDebrid Authorization", "Success!")
                 self._close()
                 return
         kodi.sleep(1000)
     self.close()
		def onInit(self):
			response = request_code()
			self.device_code = response['device_code']
			self.user_code = response['user_code']
			self.timeout = int(response['expires_in'])
			self.getControl(CONTROLS.CODE).setLabel(self.user_code)
			for tick in range(self.timeout, 0,-1):
				if tick == 0 or self._abort: break
				width = (float(tick) / self.timeout) * 596
				self.getControl(CONTROLS.PROGRESS).setWidth(int(width))
				if (tick % 5) == 0:
					r = poll_credentials(self.device_code)
					if r:
						client_id = r['client_id']
						client_secret = r['client_secret']
						token = request_token(client_id, client_secret, self.device_code)
						kodi.set_setting('realdebrid_client_id', client_id, addon_id='script.module.scrapecore')
						kodi.set_setting('realdebrid_client_secret', client_secret, addon_id='script.module.scrapecore')
						kodi.set_setting('realdebrid_token', token['access_token'], addon_id='script.module.scrapecore')
						kodi.set_setting('realdebrid_refresh_token', token['refresh_token'], addon_id='script.module.scrapecore')
						kodi.notify("RealDebrid Authorization", "Success!")
						self._close()
						return
				kodi.sleep(1000)
			self.close()
Beispiel #5
0
def install_feed():
	if not kodi.dialog_confirm('Install Feed?', "Click YES to proceed."): return
	from libs.database import DB
	from libs import github
	xml = github.install_feed(kodi.arg('url'))
	try:
		for f in xml.findAll('feeds'):
			name = f.find('name').text
			url = f.find('url').text
			DB.execute("INSERT INTO feed_subscriptions(name, url) VALUES(?,?)", [name, url])
		DB.commit()
		count = DB.query("SELECT count(1) FROM feed_subscriptions")
		kodi.set_setting('installed_feeds', str(count[0][0]))
		kodi.notify("Install Complete",'Feed Installed')
	except:
		kodi.notify("Install failed",'Invalid Format.')	
Beispiel #6
0
def show_about():
	if kodi.get_setting('disable_about') == 'true': return
	interval = int(kodi.get_setting('last_about'))
	if interval == 0:
		interval = 5
		try:
			import xbmc
			KODI_LANGUAGE = xbmc.getLanguage()
		except:
			KODI_LANGUAGE = 'English'
		path = kodi.vfs.join(kodi.get_path(), 'resources/language/%s/github_help.txt', KODI_LANGUAGE)
		if not kodi.vfs.exists(path):
			path = kodi.vfs.join(kodi.get_path(), 'resources/language/English/github_help.txt')
		text = kodi.vfs.read_file(path)
		kodi.dialog_textbox('GitHub Browser Instructions', text)
	else:
		interval -= 1	
	kodi.set_setting('last_about', interval)
Beispiel #7
0
def show_about():
	if kodi.get_setting('disable_about') == 'true': return
	interval = int(kodi.get_setting('last_about'))
	if interval == 0:
		interval = 5
		try:
			import xbmc
			KODI_LANGUAGE = xbmc.getLanguage()
		except:
			KODI_LANGUAGE = 'English'
		path = kodi.vfs.join(kodi.get_path(), 'resources/language/%s/github_help.txt', KODI_LANGUAGE)
		if not kodi.vfs.exists(path):
			path = kodi.vfs.join(kodi.get_path(), 'resources/language/English/github_help.txt')
		text = kodi.vfs.read_file(path)
		kodi.dialog_textbox('GitHub Browser Instructions', text)
	else:
		interval -= 1	
	kodi.set_setting('last_about', interval)
def refresh_token():
    url = 'https://api.real-debrid.com/oauth/v2/token'
    data = {
        'client_id':
        kodi.get_setting('realdebrid_client_id',
                         addon_id='script.module.scrapecore'),
        'client_secret':
        kodi.get_setting('realdebrid_client_secret',
                         addon_id='script.module.scrapecore'),
        'code':
        kodi.get_setting('realdebrid_refresh_token',
                         addon_id='script.module.scrapecore'),
        'grant_type':
        'http://oauth.net/grant_type/device/1.0'
    }
    response = session.post(url, data=data)
    response.json()
    if 'access_token' in response:
        kodi.set_setting('realdebrid_token',
                         response['access_token'],
                         addon_id='script.module.scrapecore')
    return response
Beispiel #9
0
def install_feed():
	from libs.database import DB
	from libs import github
	if kodi.mode == 'install_feed':
		url = kodi.arg('url')
		xml = github.install_feed(url)
	else:
		url = kodi.dialog_file_browser('Select a feed file', mask='.zip')
		if not github.re_feed.search(url): return
		xml = github.install_feed(url, True)
	if not kodi.dialog_confirm('Install Feed?', "Click YES to proceed."): return
	
	try:
		for f in xml.findAll('feeds'):
			name = f.find('name').text
			url = f.find('url').text
			DB.execute("INSERT INTO feed_subscriptions(name, url) VALUES(?,?)", [name, url])
		DB.commit()
		count = DB.query("SELECT count(1) FROM feed_subscriptions")
		kodi.set_setting('installed_feeds', str(count[0][0]))
		kodi.notify("Install Complete",'Feed Installed')
	except:
		kodi.notify("Install failed",'Invalid Format.')	
Beispiel #10
0
def install_feed():
	from libs.database import DB
	from libs import github
	if kodi.mode == 'install_feed':
		url = kodi.arg('url')
		xml = github.install_feed(url)
	else:
		url = kodi.dialog_file_browser('Select a feed file', mask='.zip')
		if not github.re_feed.search(url): return
		xml = github.install_feed(url, True)
	if not kodi.dialog_confirm('Install Feed?', "Click YES to proceed."): return
	
	try:
		for f in xml.findAll('feeds'):
			name = f.find('name').text
			url = f.find('url').text
			DB.execute("INSERT INTO feed_subscriptions(name, url) VALUES(?,?)", [name, url])
		DB.commit()
		count = DB.query("SELECT count(1) FROM feed_subscriptions")
		kodi.set_setting('installed_feeds', str(count[0][0]))
		kodi.notify("Install Complete",'Feed Installed')
	except:
		kodi.notify("Install failed",'Invalid Format.')	
Beispiel #11
0
def authorize():
    PB = kodi.ProgressBar()
    PB.new("Authorize RealDebrid: https://real-debrid.com/device", 600)
    response = request_code()
    device_code = response['device_code']
    user_code = response['user_code']
    timeout = response['expires_in']
    PB.update_subheading("Enter Code: %s" % user_code, "%s sec(s)" % 600)

    for tick in range(600, 0, -1):
        if PB.is_canceled(): return
        percent = int((tick / 600.0) * 100)
        PB.update_subheading("Enter Code: %s" % user_code,
                             "%s sec(s) remaining" % tick,
                             percent=percent)
        if (tick % 5) == 0:
            r = poll_credentials(device_code)
            if r:
                client_id = r['client_id']
                client_secret = r['client_secret']
                token = request_token(client_id, client_secret, device_code)
                kodi.set_setting('realdebrid_client_id',
                                 client_id,
                                 addon_id='script.module.scrapecore')
                kodi.set_setting('realdebrid_client_secret',
                                 client_secret,
                                 addon_id='script.module.scrapecore')
                kodi.set_setting('realdebrid_token',
                                 token['access_token'],
                                 addon_id='script.module.scrapecore')
                kodi.set_setting('realdebrid_refresh_token',
                                 token['refresh_token'],
                                 addon_id='script.module.scrapecore')
                PB.close()
                kodi.notify("RealDebrid Authorization", "Success!")
                return

        kodi.sleep(1000)
Beispiel #12
0
 def set_setting(self, k):
     kodi.set_setting(self.service + '_' + k, v, 'script.module.scrapecore')
Beispiel #13
0
def toggle_scraper():
    if kodi.get_setting(kodi.arg('service') + '_enable') == 'true':
        kodi.set_setting(kodi.arg('service') + '_enable', 'false')
    else:
        kodi.set_setting(kodi.arg('service') + '_enable', 'true')
    kodi.refresh()
Beispiel #14
0
def install_batch():
	import xbmcgui
	from libs import github
	from libs import github_installer
	if kodi.mode == 'install_batch':
		url = kodi.arg('url')
		xml, zip_ref = github.batch_installer(url)
	else:
		url = kodi.dialog_file_browser('Select a install file', mask='.zip')
		if not github.re_installer.search(url): return
		xml, zip_ref = github.batch_installer(url, True)
	if not kodi.dialog_confirm('Batch Installer?', "Click YES to proceed.", "This will install a list of addons.", "Some configuration files and settings may be overwritten."): return
	if not xml: return
	# Install each addon as instructed
	installed_list = []
	count = 0
	for a in xml.findAll('addon'): 
		count +=1 
	PB = kodi.ProgressBar()
	PB.new('Batch Installer - Progress', count)
	
	for a in xml.findAll('addon'):
		addon_id = a.find('addon_id')
		username = a.find('username')
		if addon_id is None or username is None: continue
		username = username.text
		addon_id = addon_id.text
		PB.next(addon_id)
		if not kodi.get_condition_visiblity("System.HasAddon(%s)"% addon_id):
			if PB.is_canceled(): return
			kodi.log("Batch install " + addon_id)
			url, filename, full_name, version = github.find_zip(username, addon_id)
			installed_list += github_installer.GitHub_Installer(addon_id, url, full_name, kodi.vfs.join("special://home", "addons"), quiet=True, batch=True, installed_list=installed_list).installed_list
			kodi.sleep(1000)

	# Look for config files.
	# Need to add error checking for missing config files
	configs= xml.find('configs')
	if configs is not None and 'dir' in configs.attrs[0]:
		config_dir = configs['dir']
		for config in configs.findAll('config'):
			source = config.find('source')
			destination = config.find('destination')
			if source is None or destination is None: continue
			source = source.text
			destination = destination.text
			if not kodi.vfs.exists(destination): kodi.vfs.mkdir(destination, True)
			kodi.vfs.write_file(kodi.vfs.join(destination, source), zip_ref.read(config_dir + '/' + source))
	
	# Now look for individual setting key and value pairs
	# Set them as instructed
	settings= xml.find('settings')
	if settings is not None:
		for setting in settings.findAll('setting'):
			if 'addon_id' in setting.attrs[0]:
				addon_id = setting['addon_id']
				k = setting.find('key')
				v = setting.find('value')
				if k is None or v is None: continue
				kodi.set_setting(k.text, v.text, addon_id)

	builtins= xml.find('builtins')
	if builtins is not None:
		for cmd in builtins.findAll('command'):
			cmd = cmd.text
			kodi.run_command(cmd)
			
	jsonrpc= xml.find('jsonrpc')
	if jsonrpc is not None:
		from ast import literal_eval
		for cmd in jsonrpc.findAll('command'):
			method = cmd.find('method').text
			params = literal_eval(cmd.find('params').text)
			id = cmd.find('id').text
			kodi.kodi_json_request(method, params, id)

	# Now clean up
	zip_ref.close()
	PB.close()	
	r = kodi.dialog_confirm(kodi.get_name(), 'Click Continue to install more addons or', 'Restart button to finalize addon installation', yes='Restart', no='Continue')
	if r:
		import sys
		import xbmc
		if sys.platform in ['linux', 'linux2', 'win32']:
			xbmc.executebuiltin('RestartApp')
		else:
			xbmc.executebuiltin('ShutDown')
Beispiel #15
0
def install_batch():
	import xbmcgui
	from libs import github
	from libs import github_installer
	if kodi.mode == 'install_batch':
		url = kodi.arg('url')
		xml, zip_ref = github.batch_installer(url)
	else:
		url = kodi.dialog_file_browser('Select a install file', mask='.zip')
		if not github.re_installer.search(url): return
		xml, zip_ref = github.batch_installer(url, True)
	if not kodi.dialog_confirm('Batch Installer?', "Click YES to proceed.", "This will install a list of addons.", "Some configuration files and settings may be overwritten."): return
	if not xml: return
	# Install each addon as instructed
	installed_list = []
	count = 0
	for a in xml.findAll('addon'): 
		count +=1 
	PB = kodi.ProgressBar()
	PB.new('Batch Installer - Progress', count)
	
	for a in xml.findAll('addon'):
		addon_id = a.find('addon_id')
		username = a.find('username')
		if addon_id is None or username is None: continue
		username = username.text
		addon_id = addon_id.text
		PB.next(addon_id)
		if not kodi.get_condition_visiblity("System.HasAddon(%s)"% addon_id):
			if PB.is_canceled(): return
			kodi.log("Batch install " + addon_id)
			url, filename, full_name, version = github.find_zip(username, addon_id)
			installed_list += github_installer.GitHub_Installer(addon_id, url, full_name, kodi.vfs.join("special://home", "addons"), quiet=True, batch=True, installed_list=installed_list).installed_list
			kodi.sleep(1000)

	# Look for config files.
	# Need to add error checking for missing config files
	configs= xml.find('configs')
	if configs is not None and 'dir' in configs.attrs[0]:
		config_dir = configs['dir']
		for config in configs.findAll('config'):
			source = config.find('source')
			destination = config.find('destination')
			if source is None or destination is None: continue
			source = source.text
			destination = destination.text
			if not kodi.vfs.exists(destination): kodi.vfs.mkdir(destination, True)
			kodi.vfs.write_file(kodi.vfs.join(destination, source), zip_ref.read(config_dir + '/' + source))
	
	# Now look for individual setting key and value pairs
	# Set them as instructed
	settings= xml.find('settings')
	if settings is not None:
		for setting in settings.findAll('setting'):
			if 'addon_id' in setting.attrs[0]:
				addon_id = setting['addon_id']
				k = setting.find('key')
				v = setting.find('value')
				if k is None or v is None: continue
				kodi.set_setting(k.text, v.text, addon_id)

	builtins= xml.find('builtins')
	if builtins is not None:
		for cmd in builtins.findAll('command'):
			cmd = cmd.text
			kodi.run_command(cmd)
			
	jsonrpc= xml.find('jsonrpc')
	if jsonrpc is not None:
		from ast import literal_eval
		for cmd in jsonrpc.findAll('command'):
			method = cmd.find('method').text
			params = literal_eval(cmd.find('params').text)
			id = cmd.find('id').text
			kodi.kodi_json_request(method, params, id)

	# Now clean up
	zip_ref.close()
	PB.close()	
	r = kodi.dialog_confirm(kodi.get_name(), 'Click Continue to install more addons or', 'Restart button to finalize addon installation', yes='Restart', no='Continue')
	if r:
		import sys
		import xbmc
		if sys.platform in ['linux', 'linux2', 'win32']:
			xbmc.executebuiltin('RestartApp')
		else:
			xbmc.executebuiltin('ShutDown')