Exemplo n.º 1
0
    def _connect(self):
        if self.quiet is False:
            kodi.log("Connecting to " + self.db_file)
        try:
            from sqlite3 import dbapi2 as database

            if self.quiet is False:
                kodi.log("%s loading sqlite3 as DB engine" % kodi.get_name())
        except:
            from pysqlite2 import dbapi2 as database

            if self.quiet is False:
                kodi.log("%s loading pysqlite2 as DB engine" % kodi.get_name())
        if self.quiet is False:
            kodi.log("Connecting to SQLite on: " + self.db_file)
        directory = kodi.vfs.dirname(self.db_file)
        if not kodi.vfs.exists(directory):
            kodi.vfs.mkdir(directory)
        self.DBH = database.connect(self.db_file, check_same_thread=False)
        try:
            self.DBC = self.DBH.cursor()
            self.__connected = True
        except Exception as e:
            self.handel_error(
                DatabaseException("SQLite Database Error: %s" % e))
            kodi.log("SQLite Database Error: %s" % e)
Exemplo n.º 2
0
def github_install():
    import re
    from libs import github_installer
    from libs import github
    c = kodi.dialog_confirm("Confirm Install",
                            kodi.arg('file'),
                            yes="Install",
                            no="Cancel")
    if not c: return
    addon_id = re.sub("-[\d\.]+zip$", "", kodi.arg('file'))
    github_installer.GitHub_Installer(
        addon_id, kodi.arg('url'), kodi.arg('full_name'),
        kodi.vfs.join("special://home", "addons"))
    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')
Exemplo n.º 3
0
def get_installed_resources():
    global search_path
    import os
    main = kodi.vfs.join(os.path.dirname(os.path.abspath(__file__)),
                         'scrapers')
    results = [{
        'path': main,
        'name': 'ScrapeCore',
        'addonid': 'script.module.scrapecore'
    }]
    test_path = kodi.vfs.join(kodi.get_path(), 'resources/scrapers/')
    if kodi.vfs.exists(test_path):
        results += [{
            'path': kodi.vfs.join(kodi.get_path(), 'resources'),
            'name': kodi.get_name(),
            'addonid': kodi.get_id()
        }]

    temp = kodi.kodi_json_request(
        "Addons.GetAddons", {
            "installed": True,
            'type': 'kodi.resource.images',
            "properties": ["path", "name"]
        })
    for a in temp['result']['addons']:
        if a['type'] == 'kodi.resource.images' and a['addonid'].startswith(
                'resource.scrapecore.'):
            del a['type']
            results.append(a)
    return results
Exemplo n.º 4
0
def master_control():
    options = [
        "Send to Master Control", "Stream with Master Control",
        "Master Control Queue"
    ]
    c = kodi.dialog_select("Master Control Menu", options)
    if c is False: return
    if c == 2:
        kodi.execute_url("plugin://master.control?mode=queue")
    elif c == 1:
        from scrapecore import scrapers
        resolved_url = scrapers.get_scraper_by_name(
            kodi.args['service']).resolve_url(kodi.args['raw_url'])
        if not resolved_url: return
        from mastercontrol import api as master_control
        stream_url = master_control.get_streaming_url(resolved_url)
        kodi.play_url(stream_url)
    elif c == 0:
        ids = kodi.arg('ids', decode='json')
        from commoncore import trakt
        from mastercontrol import api as master_control
        if kodi.args['media'] == 'movie':
            media = 'movie'
            title = "%s (%s)" % (kodi.args['title'], kodi.args['year'])
            filename = kodi.vfs.clean_file_name(title)
            destination = ''
        else:
            media = 'tvshow'
            destination = kodi.vfs.join(kodi.args['title'],
                                        "Season %s" % kodi.args['season'])
            title = "%s - S%02dE%02d" % (kodi.args['title'],
                                         int(kodi.args['season']),
                                         int(kodi.args['episode']))
            filename = kodi.vfs.clean_file_name(title)

        from scrapecore import scrapers
        resolved_url = scrapers.get_scraper_by_name(
            kodi.args['service']).resolve_url(kodi.args['raw_url'])
        if not resolved_url: return
        video = {
            "type": media,
            "filename": filename,
            "url": resolved_url,
            "title": title,
            "addon": kodi.get_id(),
            "destination": destination,
            "trakt_id": kodi.args['trakt_id']
        }
        response = master_control.enqueue(video)
        kodi.log(response)
        message = 'Failed Adding to Queue %s.' % (title)
        try:
            if response['status'] == 200:
                message = 'Added to Queue %s.' % (title)
        except:
            pass
        kodi.notify(kodi.get_name(), message)
Exemplo n.º 5
0
def create_custom_list(title, description=None, private=True, allow_comments=False):
	uri = '/users/me/lists'
	post_dict = {
		"name": title,
		"description": "Created by %s" % kodi.get_name() if description is None else description,
		"privacy": "private",
		"display_numbers": private,
		"allow_comments": allow_comments
	}
	return trakt.request(uri, data=post_dict, auth=True)
Exemplo n.º 6
0
def github_install():
	import re
	from libs import github_installer
	from libs import github
	c = kodi.dialog_confirm("Confirm Install", kodi.arg('file'), yes="Install", no="Cancel")
	if not c: return
	addon_id = re.sub("-[\d\.]+zip$", "", kodi.arg('file'))
	github_installer.GitHub_Installer(addon_id, kodi.arg('url'), kodi.arg('full_name'), kodi.vfs.join("special://home", "addons"))
	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')
Exemplo n.º 7
0
def create_custom_list(title,
                       description=None,
                       private=True,
                       allow_comments=False):
    uri = '/users/me/lists'
    post_dict = {
        "name":
        title,
        "description":
        "Created by %s" %
        kodi.get_name() if description is None else description,
        "privacy":
        "private",
        "display_numbers":
        private,
        "allow_comments":
        allow_comments
    }
    return trakt.request(uri, data=post_dict, auth=True)
Exemplo n.º 8
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')
Exemplo n.º 9
0
def movie_list():
    from commoncore import trakt
    from coreplayback import in_progress
    api = kodi.arg('api', decode='json')
    if api['method'] == "search":
        query = core.get_query('Movies', api['args'][0])
        api['args'] = (query, 'movie')
    results = core.execute_api(locals(), api)
    if not results:
        kodi.handel_error(kodi.get_name(), 'Not results found')
    watched = trakt.get_watched_history(
        'movies') if trakt.is_authorized() else []

    @kodi.map_directory(results['items'])
    def make_movie_directory(record):
        ids = record['movie']['ids'] if 'movie' in record else record['ids']
        infoLabel = core.make_infolabel('movie', record, watched=watched)
        infoLabel['display'] = "%s (%s)" % (infoLabel['title'],
                                            infoLabel['year'])
        menu = kodi.ContextMenu()
        inprogress = in_progress('movie', infoLabel['trakt_id'])
        menu.add(
            'Toggle Watched', {
                "mode": "toggle_watched",
                "api": {
                    "name":
                    "trakt",
                    "method":
                    "set_watched_state",
                    "args":
                    ("movie", infoLabel['trakt_id'], infoLabel['playcount']
                     == 0),
                    "refresh":
                    True
                }
            })
        if kodi.mode in ['shows_watchlist', 'shows_custom_list']:
            menu.add(
                'Remove From List', {
                    "mode": "execute_api",
                    "api": {
                        "name": "trakt",
                        "method": "remove_from_list",
                        "args":
                        ("movie", api['args'][0], infoLabel['trakt_id']),
                        "refresh": True,
                        "confirm": "Confirm Remove from List?",
                        "message": api['args'][0]
                    }
                })
        else:
            menu.add(
                'Add to List', {
                    "mode": "execute_api",
                    "api": {
                        "name": "trakt",
                        "method": "add_to_list",
                        "args": ("movie", infoLabel['trakt_id'])
                    }
                })
        menu.add(
            'Set Default View', {
                "mode": "set_default_view",
                "api": {
                    "name": "kodi",
                    "method": "set_default_view",
                    "args": ("movie", )
                }
            })
        kodi.add_menu_item(
            {
                "mode": "search_streams",
                "media": "movie",
                "trakt_id": infoLabel['trakt_id'],
                "title": infoLabel['title'],
                "year": infoLabel["year"],
                "ids": ids
            },
            infoLabel,
            in_progress=inprogress,
            menu=menu,
            image=infoLabel['poster'])

    if 'total_pages' in results and results['total_pages'] > 1 and results[
            'current_page'] < results['total_pages']:
        kodi.add_menu_item(
            {
                "mode": kodi.mode,
                "api": api,
                "page": results['current_page'] + 1
            }, {"title": core.format_color("Next Page >>", 'green')},
            icon="next_page.png")
    kodi.eod(DEFAULT_VIEWS.MOVIES)
Exemplo n.º 10
0
def tv_list():
    from commoncore import trakt
    api = kodi.arg('api', decode='json')
    if api['method'] == "search":
        query = core.get_query('Shows', api['args'][0])
        api['args'] = (query, 'show')
    results = core.execute_api(locals(), api)
    if not results:
        kodi.handel_error(kodi.get_name(), 'Not results found')

    @kodi.map_directory(results['items'])
    def make_show_directory(record):
        infoLabel = core.make_infolabel('show', record)
        ids = record['show']['ids'] if 'show' in record else record['ids']
        infoLabel['display'] = "%s (%s)" % (infoLabel['title'],
                                            infoLabel['year'])
        menu = kodi.ContextMenu()
        menu.add(
            'Set Default View', {
                "mode": "set_default_view",
                "api": {
                    "name": "kodi",
                    "method": "set_default_view",
                    "args": ("show", )
                }
            })
        if kodi.mode in ['shows_watchlist', 'shows_custom_list']:
            menu.add(
                'Remove From List', {
                    "mode": "execute_api",
                    "api": {
                        "name": "trakt",
                        "method": "remove_from_list",
                        "args":
                        ("show", api['args'][0], infoLabel['trakt_id']),
                        "refresh": True,
                        "confirm": "Confirm Remove from List?",
                        "message": api['args'][0]
                    }
                })
        else:
            menu.add(
                'Add to List', {
                    "mode": "execute_api",
                    "api": {
                        "name": "trakt",
                        "method": "add_to_list",
                        "args": ("show", infoLabel['trakt_id'])
                    }
                })
        kodi.add_menu_item(
            {
                "mode": "list_seasons",
                "trakt_id": infoLabel['trakt_id'],
                "ids": ids
            },
            infoLabel,
            menu=menu,
            image=infoLabel['poster'])

    if 'total_pages' in results and results['total_pages'] > 1 and results[
            'current_page'] < results['total_pages']:
        kodi.add_menu_item(
            {
                "mode": kodi.mode,
                "api": api,
                "page": results['current_page'] + 1
            }, {"title": core.format_color("Next Page >>", 'green')},
            icon="next_page.png")
    kodi.eod(DEFAULT_VIEWS.SHOWS)
Exemplo n.º 11
0
def in_progress():
    import json
    from commoncore import trakt
    import coreplayback
    api = kodi.arg('api', decode='json')
    results = core.execute_api(locals(), api)
    if not results:
        kodi.handel_error(kodi.get_name(), 'Not results found')
        return

    def make_show_directory(record):
        ids = json.loads(record[0])
        metadata = json.loads(record[1])
        episode = metadata['episode']
        show = metadata['show']['items']
        infoLabel = metadata['episode']
        infoLabel['display'] = "%sx%s. %s - %s" % (
            infoLabel['season'], infoLabel['episode'], show['title'],
            infoLabel['title'])
        menu = kodi.ContextMenu()
        menu.add(
            'Set Default View', {
                "mode": "set_default_view",
                "api": {
                    "name": "kodi",
                    "method": "set_default_view",
                    "args": ("show", )
                }
            })
        menu.add(
            'Add to List', {
                "mode": "execute_api",
                "api": {
                    "name": "trakt",
                    "method": "add_to_list",
                    "args": ("show", infoLabel['trakt_id'])
                }
            })
        kodi.add_menu_item(
            {
                "mode": "search_streams",
                "media": "episode",
                "trakt_id": infoLabel['trakt_id'],
                "title": show['title'],
                "year": show['year'],
                "season": infoLabel['season'],
                "episode": infoLabel['episode'],
                "ids": ids
            },
            infoLabel,
            menu=menu,
            in_progress=True,
            image=infoLabel['poster'])

    def make_movie_directory(record):
        ids = json.loads(record[0])
        infoLabel = json.loads(record[1])
        infoLabel['display'] = "%s (%s)" % (infoLabel['title'],
                                            infoLabel['year'])
        menu = kodi.ContextMenu()
        menu.add(
            'Set Default View', {
                "mode": "set_default_view",
                "api": {
                    "name": "kodi",
                    "method": "set_default_view",
                    "args": ("movie", )
                }
            })
        menu.add(
            'Add to List', {
                "mode": "execute_api",
                "api": {
                    "name": "trakt",
                    "method": "add_to_list",
                    "args": ("movie", infoLabel['trakt_id'])
                }
            })
        kodi.add_menu_item(
            {
                "mode": "search_streams",
                "media": "movie",
                "trakt_id": infoLabel['trakt_id'],
                "title": infoLabel['title'],
                "year": infoLabel['year'],
                "ids": ids
            },
            infoLabel,
            menu=menu,
            in_progress=True,
            image=infoLabel['poster'])

    if kodi.mode == 'shows_inprogress':
        map(make_show_directory, results)
    else:
        map(make_movie_directory, results)
    kodi.eod(DEFAULT_VIEWS.SHOWS)
Exemplo n.º 12
0
def search_streams():
    from scrapecore import scrapers
    results = scrapers.search(kodi.args['media'],
                              kodi.args['title'],
                              episode_title=kodi.arg('episode_title'),
                              year=kodi.arg('year'),
                              season=kodi.arg('season'),
                              episode=kodi.arg('episode'),
                              trakt_id=kodi.arg('trakt_id'))
    if len(results) == 0:
        kodi.handel_error(kodi.get_name(), 'Not results found')
        return
    ids = kodi.arg('ids', decode='json')
    ids['season'] = kodi.arg('season')
    ids['episode'] = kodi.arg('episode')

    @kodi.map_directory(results)
    def make_stream_directory(r):
        menu = kodi.ContextMenu()
        menu.add(
            'Set Default View', {
                "mode": "set_default_view",
                "api": {
                    "name": "kodi",
                    "method": "set_default_view",
                    "args": ("stream", )
                }
            })
        infoLabel = {"title": r['title'], "display": r['display']}
        menu.add(
            'Master Control', {
                "mode": "master_control",
                "media": kodi.args['media'],
                "raw_url": r['raw_url'],
                "service": r['service'],
                "title": kodi.args['title'],
                "year": kodi.arg('year'),
                "season": kodi.arg('season'),
                "episode": kodi.arg('episode'),
                "trakt_id": kodi.arg('trakt_id')
            })
        if r['torrent']:
            menu.add(
                'Add to Cloud', {
                    "mode": "execute_api",
                    "api": {
                        "name": "premiumize",
                        "method": "create_transfer",
                        "args": (r['raw_url'], ),
                        "notify": True,
                        "confirm": "Add to Premiumize Cloud?",
                        "message": r['title']
                    }
                })
        kodi.add_video_item(
            {
                "mode": "play_stream",
                "raw_url": r['raw_url'],
                "title": kodi.args['title'],
                "service": r['service'],
                "ids": ids,
                "media": kodi.args['media'],
                "trakt_id": kodi.args['trakt_id']
            },
            infoLabel,
            menu=menu,
            icon=r['icon'])

    kodi.eod(DEFAULT_VIEWS.STREAMS)
Exemplo n.º 13
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')