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 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 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 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(): 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 _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 save_source(self, addon_id, source): DB.execute( "REPLACE INTO install_history(addon_id, source) VALUES(?,?)", [addon_id, json.dumps(source)]) 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()
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()
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 _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 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 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 save_source(self, addon_id, source): DB.execute("REPLACE INTO install_history(addon_id, source) VALUES(?,?)", [addon_id, json.dumps(source)]) DB.commit()