def history_delete(): if not kodi.arg('id'): return from libs.database import DB DB.execute("DELETE FROM search_history WHERE search_id=?", [kodi.arg('id')]) DB.commit() kodi.refresh()
def new_feed(): from libs.database import DB url = kodi.dialog_input('Feed URL') if not url: return DB.execute("INSERT INTO feed_subscriptions(url) VALUES(?)", [url]) DB.commit() kodi.refresh()
def new_feed(): from libs.database import DB url = kodi.dialog_input('Feed URL') if not url: return DB.execute("INSERT INTO feed_subscriptions(url) VALUES(?)", [url]) DB.commit() kodi.refresh()
def delete_feed(): if not kodi.dialog_confirm('Delete Feed?', kodi.arg('title'), "Click YES to proceed."): return from libs.database import DB DB.execute("DELETE FROM feed_subscriptions WHERE feed_id=?", [kodi.arg('id')]) DB.commit() kodi.refresh()
def feed_count(): from libs.database import DB try: count = DB.query("SELECT count(1) FROM feed_subscriptions")[0][0] except: count = 0 return count
def __init__(self, secret): # Accedo a la base de datos self.db = DB(secret) # Arranco en Async Scheduler self.sched = AsyncIOScheduler() self.sched.start()
def feed_count(): from libs.database import DB try: count = DB.query("SELECT count(1) FROM feed_subscriptions")[0][0] except: count = 0 return count
def feed_menu(): from libs.database import DB kodi.add_menu_item({'mode': 'new_feed'}, {'title': "*** New Search Feed ***"}, icon='null') feeds = DB.query_assoc( "SELECT feed_id, name, url, enabled FROM feed_subscriptions") for feed in feeds: menu = kodi.ContextMenu() name = feed['name'] if feed['name'] else feed['url'] if not feed['enabled']: title = "[COLOR darkred]%s[/COLOR]" % name else: title = name menu.add('Delete Feed', { "mode": "delete_feed", "title": title, "id": feed['feed_id'] }) kodi.add_menu_item({ 'mode': 'list_feed', 'url': feed['url'] }, {'title': title}, menu=menu, icon='null') kodi.eod()
def update_addons(quiet=True): from distutils.version import LooseVersion if not quiet: kodi.open_busy_dialog() sources = DB.query("SELECT addon_id, source FROM install_history") update_count = 0 for source in sources: addon_id = source[0] source = json.loads(source[1]) if kodi.get_condition_visiblity("System.HasAddon(%s)" % addon_id): if source['type'] == SOURCES.ZIP: url, filename, full_name, version = github_api.find_zip( source['user'], addon_id) if LooseVersion(version) > LooseVersion(source['version']): GitHub_Installer(addon_id, url, full_name, kodi.vfs.join("special://home", "addons"), False, quiet) update_count += 1 elif source['type'] == SOURCES.REPO: full_name = sources['user'] + '/' + sources['repo'] xml_str = github_api.find_xml(full_name) xml = BeautifulSoup(xml_str) addon = xml.find('addon') if LooseVersion(addon['version']) > LooseVersion( source['version']): GitHub_Installer(addon_id, source['url'], full_name, kodi.vfs.join("special://home", "addons"), True, quiet) update_count += 1 if not quiet: kodi.close_busy_dialog() if update_count > 0: kodi.notify("Update complete", 'Some addons may require restarting kodi.') else: kodi.notify("Update complete", 'No updates found.')
def update_addons(quiet=True): from distutils.version import LooseVersion if not quiet: kodi.open_busy_dialog() sources = DB.query("SELECT addon_id, source FROM install_history") update_count = 0 for source in sources: addon_id = source[0] source = json.loads(source[1]) if kodi.get_condition_visiblity("System.HasAddon(%s)" % addon_id): if source['type'] == SOURCES.ZIP: url, filename, full_name, version = github_api.find_zip(source['user'], addon_id) if LooseVersion(version) > LooseVersion(source['version']): GitHub_Installer(addon_id, url, full_name, kodi.vfs.join("special://home", "addons"), False, quiet) update_count += 1 elif source['type'] == SOURCES.REPO: full_name = sources['user'] + '/' + sources['repo'] xml_str = github_api.find_xml(full_name) xml = BeautifulSoup(xml_str) addon = xml.find('addon') if LooseVersion(addon['version']) > LooseVersion(source['version']): GitHub_Installer(addon_id, source['url'], full_name, kodi.vfs.join("special://home", "addons"), True, quiet) update_count += 1 if not quiet: kodi.close_busy_dialog() if update_count > 0: kodi.notify("Update complete",'Some addons may require restarting kodi.') else: kodi.notify("Update complete",'No updates found.')
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.')
def search_menu(): from libs.database import DB kodi.add_menu_item({'mode': 'void'}, {'title': "[COLOR darkorange]%s[/COLOR]" % kodi.arg('title')}, icon='null') kodi.add_menu_item({'mode': 'search', 'type': kodi.arg('type')}, {'title': "*** New Search ***"}, icon='null') results = DB.query_assoc("SELECT search_id, query FROM search_history WHERE search_type=? ORDER BY ts DESC LIMIT 10", [kodi.arg('type')], silent=True) if results is not None: for result in results: menu = kodi.ContextMenu() menu.add('Delete from search history', {"mode": "history_delete", "id": result['search_id']}) kodi.add_menu_item({'mode': 'search', 'type': kodi.arg('type'), 'query': result['query']}, {'title': result['query']}, menu=menu, icon='null') kodi.eod()
def search_menu(): from libs.database import DB kodi.add_menu_item({'mode': 'void'}, {'title': "[COLOR darkorange]%s[/COLOR]" % kodi.arg('title')}, icon='null') kodi.add_menu_item({'mode': 'search', 'type': kodi.arg('type')}, {'title': "*** New Search ***"}, icon='null') results = DB.query_assoc("SELECT search_id, query FROM search_history WHERE search_type=? ORDER BY ts DESC LIMIT 10", [kodi.arg('type')], silent=True) if results is not None: for result in results: menu = kodi.ContextMenu() menu.add('Delete from search history', {"mode": "history_delete", "id": result['search_id']}) kodi.add_menu_item({'mode': 'search', 'type': kodi.arg('type'), 'query': result['query']}, {'title': result['query']}, menu=menu, icon='null') kodi.eod()
def search(): from libs.database import DB from libs import github_api from libs.github_api import re_repository q = kodi.arg('query') if kodi.arg('query') else kodi.dialog_input('Search GitHub') if q in [None, False, '']: return False DB.execute('INSERT INTO search_history(search_type, query) VALUES(?,?)', [kodi.arg('type'), q]) DB.commit() if kodi.arg('type') == 'username': rtype = 'api' response = github_api.find_zips(q) if response is None: return for r in github_api.sort_results(response['items']): url = github_api.content_url % (r['repository']['full_name'], r['path']) menu = kodi.ContextMenu() if re_repository.search(r['name']): menu.add('Browse Repository Contents', {"mode": "browse_repository", "url": url, "file": r['name'], "full_name": "%s/%s" % (q, r['repository']['name'])}) kodi.add_menu_item({'mode': 'github_install', "url": url, "user": q, "file": r['name'], "full_name": "%s/%s" % (q, r['repository']['name'])}, {'title': r['name']}, menu=menu, icon='null') kodi.eod() elif kodi.arg('type') == 'repository': rtype = 'api' results = github_api.search(q, 'title') if results is None: return for i in results['items']: user = i['owner']['login'] response = github_api.find_zips(user) if response is None: continue for r in github_api.sort_results(response['items']): url = github_api.content_url % (r['repository']['full_name'], r['path']) menu = kodi.ContextMenu() if re_repository.search(r['name']): menu.add('Browse Repository Contents', {"mode": "browse_repository", "url": url, "file": r['name'], "full_name": "%s/%s" % (q, r['repository']['name'])}) kodi.add_menu_item({'mode': 'github_install', "url": url, "user": q, "file": r['name'], "full_name": "%s/%s" % (q, r['repository']['name'])}, {'title': r['name']}, menu=menu, icon='null') kodi.eod() elif kodi.arg('type') == 'addonid': rtype = 'web' results = github_api.web_search(q) if results is None: return for r in results['items']: kodi.add_menu_item({'mode': 'github_install', "user": r['owner']['login'], "repo": r['name'], "rtype": rtype}, {'title': "%s/%s" % (r['owner']['login'], r['name'])}, icon='null') kodi.eod()
def search(): from libs.database import DB from libs import github_api from libs.github_api import re_repository q = kodi.arg('query') if kodi.arg('query') else kodi.dialog_input('Search GitHub') if q in [None, False, '']: return False DB.execute('INSERT INTO search_history(search_type, query) VALUES(?,?)', [kodi.arg('type'), q]) DB.commit() if kodi.arg('type') == 'username': rtype = 'api' response = github_api.find_zips(q) if response is None: return for r in github_api.sort_results(response['items']): url = github_api.content_url % (r['repository']['full_name'], r['path']) menu = kodi.ContextMenu() if re_repository.search(r['name']): menu.add('Browse Repository Contents', {"mode": "browse_repository", "url": url, "file": r['name'], "full_name": "%s/%s" % (q, r['repository']['name'])}) kodi.add_menu_item({'mode': 'github_install', "url": url, "user": q, "file": r['name'], "full_name": "%s/%s" % (q, r['repository']['name'])}, {'title': r['name']}, menu=menu, icon='null') kodi.eod() elif kodi.arg('type') == 'repository': rtype = 'api' results = github_api.search(q, 'title') if results is None: return for i in results['items']: user = i['owner']['login'] response = github_api.find_zips(user) if response is None: continue for r in github_api.sort_results(response['items']): url = github_api.content_url % (r['repository']['full_name'], r['path']) menu = kodi.ContextMenu() if re_repository.search(r['name']): menu.add('Browse Repository Contents', {"mode": "browse_repository", "url": url, "file": r['name'], "full_name": "%s/%s" % (q, r['repository']['name'])}) kodi.add_menu_item({'mode': 'github_install', "url": url, "user": q, "file": r['name'], "full_name": "%s/%s" % (q, r['repository']['name'])}, {'title': r['name']}, menu=menu, icon='null') kodi.eod() elif kodi.arg('type') == 'addonid': rtype = 'web' results = github_api.web_search(q) if results is None: return for r in results['items']: kodi.add_menu_item({'mode': 'github_install', "user": r['owner']['login'], "repo": r['name'], "rtype": rtype}, {'title': "%s/%s" % (r['owner']['login'], r['name'])}, icon='null') kodi.eod()
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.')
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.')
def _get_cached_response(url, cache_limit=0): if cache_limit == 0: return False, False, False else: cache_limit = float(cache_limit) * 3600 result = False SQL = "SELECT results, current_page, total_pages FROM cached_requests WHERE age < ? AND url=?" cache = DB.query(SQL, [cache_limit, url], force_double_array=False) if cache: kodi.log('Returning cached response') result = json.loads(cache[0]) return result, int(cache[1]), int(cache[2]) else: return False, False, False
def _get_cached_response(url, cache_limit=0): if cache_limit == 0: return False, False, False else: cache_limit = float(cache_limit) * 3600 result = False SQL = "SELECT results, current_page, total_pages FROM cached_requests WHERE age < ? AND url=?" cache = DB.query(SQL, [cache_limit, url], force_double_array=False) if cache: kodi.log('Returning cached response') result = json.loads(cache[0]) return result, int(cache[1]), int(cache[2]) else: return False, False, False
def feed_menu(): from libs.database import DB kodi.add_menu_item({'mode': 'install_local_feed'}, {'title': "*** Local Search Feed File ***"}, icon='install_feed_local.png') #kodi.add_menu_item({'mode': 'search', 'query': 'gitbrowser.feed', 'type': 'addonid'}, {'title': "*** Search for Feeds ***"}, icon='null') feeds = DB.query_assoc("SELECT feed_id, name, url, enabled FROM feed_subscriptions") for feed in feeds: menu = kodi.ContextMenu() name = feed['name'] if feed['name'] else feed['url'] if not feed['enabled']: title = "[COLOR darkred]%s[/COLOR]" % name else: title = name menu.add('Delete Feed', {"mode": "delete_feed", "title": title, "id": feed['feed_id']}) kodi.add_menu_item({'mode': 'list_feed', 'url': feed['url']}, {'title': title}, menu=menu, icon='null') kodi.eod()
def feed_menu(): from libs.database import DB kodi.add_menu_item({'mode': 'install_local_feed'}, {'title': "*** Local Search Feed File ***"}, icon='install_feed_local.png') #kodi.add_menu_item({'mode': 'search', 'query': 'gitbrowser.feed', 'type': 'addonid'}, {'title': "*** Search for Feeds ***"}, icon='null') feeds = DB.query_assoc("SELECT feed_id, name, url, enabled FROM feed_subscriptions") for feed in feeds: menu = kodi.ContextMenu() name = feed['name'] if feed['name'] else feed['url'] if not feed['enabled']: title = "[COLOR darkred]%s[/COLOR]" % name else: title = name menu.add('Delete Feed', {"mode": "delete_feed", "title": title, "id": feed['feed_id']}) kodi.add_menu_item({'mode': 'list_feed', 'url': feed['url']}, {'title': title}, menu=menu, icon='null') kodi.eod()
def search(): from commoncore.dispatcher import dispatcher from libs.database import DB from libs import github from libs.github import get_download_url q = kodi.arg('query') if kodi.arg('query') else kodi.dialog_input('Search GitHub') if q in [None, False, '']: return False DB.execute('REPLACE INTO search_history(search_type, query) VALUES(?,?)', [kodi.arg('type'), q]) DB.commit() @dispatcher.register('username') def username(): rtype = 'api' response = github.find_zips(q) if response is None: return for r in github.sort_results(response['items']): url = get_download_url(r['repository']['full_name'], r['path']) menu = kodi.ContextMenu() if r['is_repository']: menu.add('Browse Repository Contents', {"mode": "browse_repository", "url": url, "file": r['name'], "full_name": "%s/%s" % (q, r['repository']['name'])}) if r['is_feed']: r['display'] = "[COLOR yellow]%s[/COLOR]" % r['name'] kodi.add_menu_item({'mode': 'install_feed', "url": url}, {'title': r['name'], 'display': r['display']}, menu=menu, icon='null') elif r['is_installer']: r['display'] = "[COLOR orange]%s[/COLOR]" % r['name'] kodi.add_menu_item({'mode': 'install_batch', "url": url}, {'title': r['name'], 'display': r['display']}, menu=menu, icon='null') else: kodi.add_menu_item({'mode': 'github_install', "url": url, "user": q, "file": r['name'], "full_name": "%s/%s" % (q, r['repository']['name'])}, {'title': r['name']}, menu=menu, icon='null') @dispatcher.register('repository') def repository(): rtype = 'api' results = github.search(q, 'title') if results is None: return for i in results['items']: user = i['owner']['login'] response = github.find_zips(user) if response is None: continue for r in github.sort_results(response['items']): url = get_download_url(r['repository']['full_name'], r['path']) menu = kodi.ContextMenu() if r['is_repository']: menu.add('Browse Repository Contents', {"mode": "browse_repository", "url": url, "file": r['name'], "full_name": "%s/%s" % (q, r['repository']['name'])}) if r['is_feed']: r['display'] = "[COLOR yellow]%s[/COLOR]" % r['name'] kodi.add_menu_item({'mode': 'install_feed', "url": url}, {'title': r['name']}, menu=menu, icon='null') elif r['is_installer']: r['display'] = "[COLOR orange]%s[/COLOR]" % r['name'] kodi.add_menu_item({'mode': 'install_batch', "url": url}, {'title': r['name'], 'display': r['display']}, menu=menu, icon='null') else: kodi.add_menu_item({'mode': 'github_install', "url": url, "user": q, "file": r['name'], "full_name": "%s/%s" % (q, r['repository']['name'])}, {'title': r['name']}, menu=menu, icon='null') @dispatcher.register('addonid') def addonid(): from commoncore.core import highlight from libs.github import version_sort rtype = 'api' results = github.search(q, 'id') if results is None: return results.sort(key=lambda x:version_sort(x['name']), reverse=True) for i in results: menu = kodi.ContextMenu() r = i['repository'] full_name = r['full_name'] title = highlight("%s/%s" % (full_name, i['name']), q, 'yellow') url = get_download_url(full_name, i['path']) menu.add("Search Username", {'mode': 'search', 'type': 'username', 'query': r['owner']['login']}) kodi.add_menu_item({'mode': 'github_install', "url": url, "file": i['name'], "full_name": full_name}, {'title': title}, menu=menu, icon='null') dispatcher.run(kodi.arg('type')) kodi.eod()
def save_source(self, addon_id, source): DB.execute( "REPLACE INTO install_history(addon_id, source) VALUES(?,?)", [addon_id, json.dumps(source)]) DB.commit()
def save_source(self, addon_id, source): DB.execute("REPLACE INTO install_history(addon_id, source) VALUES(?,?)", [addon_id, json.dumps(source)]) DB.commit()
def search(): from commoncore.dispatcher import dispatcher from libs.database import DB from libs import github q = kodi.arg('query') if kodi.arg('query') else kodi.dialog_input( 'Search GitHub') if q in [None, False, '']: return False DB.execute('INSERT INTO search_history(search_type, query) VALUES(?,?)', [kodi.arg('type'), q]) DB.commit() @dispatcher.register('username') def username(): rtype = 'api' response = github.find_zips(q) if response is None: return for r in github.sort_results(response['items']): url = github.content_url % (r['repository']['full_name'], r['path']) menu = kodi.ContextMenu() if r['is_repository']: menu.add( 'Browse Repository Contents', { "mode": "browse_repository", "url": url, "file": r['name'], "full_name": "%s/%s" % (q, r['repository']['name']) }) if r['is_feed']: r['display'] = "[COLOR yellow]%s[/COLOR]" % r['name'] kodi.add_menu_item({ 'mode': 'install_feed', "url": url }, { 'title': r['name'], 'display': r['display'] }, menu=menu, icon='null') else: kodi.add_menu_item( { 'mode': 'github_install', "url": url, "user": q, "file": r['name'], "full_name": "%s/%s" % (q, r['repository']['name']) }, {'title': r['name']}, menu=menu, icon='null') @dispatcher.register('repository') def repository(): rtype = 'api' results = github.search(q, 'title') if results is None: return for i in results['items']: user = i['owner']['login'] response = github.find_zips(user) if response is None: continue for r in github.sort_results(response['items']): url = github.content_url % (r['repository']['full_name'], r['path']) menu = kodi.ContextMenu() if r['is_repository']: menu.add( 'Browse Repository Contents', { "mode": "browse_repository", "url": url, "file": r['name'], "full_name": "%s/%s" % (q, r['repository']['name']) }) if r['is_feed']: kodi.add_menu_item({ 'mode': 'install_feed', "url": url }, {'title': r['name']}, menu=menu, icon='null') else: kodi.add_menu_item( { 'mode': 'github_install', "url": url, "user": q, "file": r['name'], "full_name": "%s/%s" % (q, r['repository']['name']) }, {'title': r['name']}, menu=menu, icon='null') @dispatcher.register('addonid') def addonid(): from commoncore.core import highlight from libs.github import re_version, content_url from distutils.version import LooseVersion rtype = 'api' results = github.search(q, 'id') if results is None: return def version_sort(name): v = re_version.search(name) if v: return LooseVersion(v.group(1)) else: return LooseVersion('0.0.0') results.sort(key=lambda x: version_sort(x['name']), reverse=True) for i in results: menu = kodi.ContextMenu() r = i['repository'] full_name = r['full_name'] title = highlight("%s/%s" % (full_name, i['name']), q, 'yellow') url = content_url % (full_name, i['path']) menu.add("Search Username", { 'mode': 'search', 'type': 'username', 'query': r['owner']['login'] }) kodi.add_menu_item( { 'mode': 'github_install', "url": url, "file": i['name'], "full_name": full_name }, {'title': title}, menu=menu, icon='null') dispatcher.run(kodi.arg('type')) kodi.eod()
def _cache_response(url, response, current_page=1, total_pages=1): DB.execute( "REPLACE INTO request_cache(url, results, current_page, total_pages) VALUES(?,?,?,?)", [url, json.dumps(response), current_page, total_pages]) DB.commit()
if results is not None: for result in results: menu = kodi.ContextMenu() menu.add('Search Filter', {"mode": "search_filter"}) menu.add('Delete from search history', {"mode": "history_delete", "id": result['search_id']}) kodi.add_menu_item({'mode': 'search', 'type': kodi.arg('type'), 'query': result['query']}, {'title': result['query']}, menu=menu, icon='null') kodi.eod() @kodi.register('search') def search(): from commoncore.dispatcher import dispatcher from libs.database import DB from libs import github q = kodi.arg('query') if kodi.arg('query') else kodi.dialog_input('Search GitHub') if q in [None, False, '']: return False DB.execute('INSERT OR REPLACE INTO search_history(search_type, query) VALUES(?,?)', [kodi.arg('type'), q]) DB.commit() @dispatcher.register('username') def username(): rtype = 'api' response = github.find_zips(q) if response is None: return for r in github.sort_results(response['items']): url = github.content_url % (r['repository']['full_name'], r['path']) menu = kodi.ContextMenu() if r['is_repository']: menu.add('Browse Repository Contents', {"mode": "browse_repository", "url": url, "file": r['name'], "full_name": "%s/%s" % (q, r['repository']['name'])}) if r['is_feed']: r['display'] = "[COLOR yellow]%s[/COLOR]" % r['name'] kodi.add_menu_item({'mode': 'install_feed', "url": url}, {'title': r['name'], 'display': r['display']}, menu=menu, icon='null')
def history_delete(): if not kodi.arg('id'): return from libs.database import DB DB.execute("DELETE FROM search_history WHERE search_id=?", [kodi.arg('id')]) DB.commit() kodi.refresh()
def _cache_response(url, response, current_page=1, total_pages=1): DB.execute("REPLACE INTO request_cache(url, results, current_page, total_pages) VALUES(?,?,?,?)", [url, json.dumps(response), current_page, total_pages]) DB.commit()
def delete_feed(): if not kodi.dialog_confirm('Delete Feed?', kodi.arg('title'), "Click YES to proceed."): return from libs.database import DB DB.execute("DELETE FROM feed_subscriptions WHERE feed_id=?", [kodi.arg('id')]) DB.commit() kodi.refresh()