示例#1
0
			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()

@kodi.register('search_filter')
def search_filter():
	from commoncore.core import format_color
	options = display =['None', 'Repository', 'Feed', 'Music Plugin', 'Video Plugin', 'Script']
	filter = kodi.get_property('search.filter')
	if filter in options:
		index = options.index(filter)
		display[index] = format_color(display[index], 'yellow')
	else:
		display[0] = format_color(display[0], 'yellow')
		
	c = kodi.dialog_select("Filter Results by:", display)
	if c is not False:
示例#2
0
def get_art(media, id, id_type='trakt_id', season=None, episode=None):
    k = id_type.replace("_id", "")
    import json
    from commoncore import trakt
    from commoncore.dispatcher import dispatcher
    DB = BASE_FANART_API()
    try:

        @dispatcher.register('show')
        def show():
            ids = DB.query(
                "SELECT ids FROM id_table WHERE primary_id=? AND media=?",
                [id, media])
            if ids:
                ids = json.loads(ids[0][0])
            else:
                response = trakt.get_show_info(id)
                ids = response['items']['ids']
                DB.execute(
                    "INSERT INTO id_table(media, primary_id, id_type, ids) VALUES(?,?,?,?)",
                    [media, ids[k], id_type,
                     json.dumps(ids)])
                DB.commit()
            return get_show_art(ids['tmdb'], ids['tvdb'], ids['imdb'])

        @dispatcher.register('movie')
        def movie():
            ids = DB.query(
                "SELECT ids FROM id_table WHERE primary_id=? AND media=?",
                [id, media])
            if ids:
                ids = json.loads(ids[0][0])
            else:
                response = trakt.get_movie_info(id)
                ids = response['items']['ids']
                DB.execute(
                    "INSERT INTO id_table(media, primary_id, id_type, ids) VALUES(?,?,?,?)",
                    [media, ids[k], id_type,
                     json.dumps(ids)])
                DB.commit()
            return get_movie_art(ids['tmdb'], ids['imdb'])

        @dispatcher.register('season')
        def f_season():
            ids = DB.query(
                "SELECT ids FROM id_table WHERE primary_id=? AND media=?",
                [id, media])
            if ids:
                ids = json.loads(ids[0][0])
            else:
                response = trakt.get_show_info(id)
                ids = response['items']['ids']
                ids['season'] = season
                DB.execute(
                    "INSERT INTO id_table(media, primary_id, id_type, ids) VALUES(?,?,?,?)",
                    [media, ids[k], id_type,
                     json.dumps(ids)])
                DB.commit()
            return get_season_art(ids['tvdb'], ids['season'])

        @dispatcher.register('episode')
        def f_episode():
            ids = DB.query(
                "SELECT ids FROM id_table WHERE primary_id=? AND media=?",
                [id, media])
            if ids:
                ids = json.loads(ids[0][0])
            else:
                response = trakt.get_show_info(id)
                ids = response['items']['ids']
                ids['season'] = season
                ids['episode'] = episode
                DB.execute(
                    "INSERT INTO id_table(media, primary_id, id_type, ids) VALUES(?,?,?,?)",
                    [media, ids[k], id_type,
                     json.dumps(ids)])
                DB.commit()
            return get_episode_art(ids['tmdb'], ids['tvdb'], ids['imdb'],
                                   ids['season'], ids['episode'])

        return dispatcher.run(media)

    except:
        raise FanartException
示例#3
0
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()
示例#4
0
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()