예제 #1
0
def clear_slideshow():
    get_players = json.loads(xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "Player.GetActivePlayers", "id": 1}'))  # @UndefinedVariable
    for _player in get_players['result']:
        if _player['type'] == 'picture':
            stop_slideshow = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "Player.Stop", "params": {"playerid":%i}, "id": 1}' % _player['playerid'])  # @UndefinedVariable
        else: continue
    clear_playlist = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "Playlist.Clear", "params": {"playlistid":2}, "id": 1}')  # @UndefinedVariable
예제 #2
0
def _youtube_search(query):
    FIELDS_BASE = ["dateadded", "file", "lastplayed", "plot", "title", "art", "playcount"]
    FIELDS_FILE = FIELDS_BASE + ["streamdetails", "director", "resume", "runtime"]
    FIELDS_FILES = FIELDS_FILE + [
        "plotoutline", "sorttitle", "cast", "votes", "trailer", "year", "country", "studio",
        "genre", "mpaa", "rating", "tagline", "writer", "originaltitle", "imdbnumber", "premiered", "episode",
        "showtitle",
        "firstaired", "watchedepisodes", "duration", "season"]
    data = {
        "jsonrpc": "2.0",
        "method": "Files.GetDirectory",
        "id": 1,
        "params": {
            "properties": FIELDS_FILES,
            "directory": "plugin://plugin.video.youtube/kodion/search/query/?q={0}".format(query)
        }
    }
    json_response = xbmc.executeJSONRPC(json.dumps(data))
    json_object = json.loads(json_response.decode('utf-8'))
    result = []
    if 'result' in json_object:
        for key, value in json_object['result'].iteritems():
            if not key == "limits" and (isinstance(value, list) or isinstance(value, dict)):
                result = value
    result = [i for i in result if not i["filetype"] == "directory"]
    return result
예제 #3
0
def add_playlist(images):
    items = []
    for image in images:
        item = '{"jsonrpc": "2.0", "method": "Playlist.Add", "params": {"playlistid": 2, "item": {"file" : "%s"}}, "id": 1}' % image['path'] 
        add_item = items.append(item.encode('ascii'))
    print 'Adding - %s images' %str(len(items))
    if len(items) > 0:
        add_playlist = xbmc.executeJSONRPC(str(items).replace("'",""))  # @UndefinedVariable
예제 #4
0
def start_slideshow(images):

    print 'Slideshow Images = '+ str(len(images))
    if len(images) > 0:
        clear_slideshow()
        add_playlist(images)
        get_playlist = json.loads(xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "Playlist.GetItems", "params": {"playlistid":2}, "id": 1}'))  # @UndefinedVariable
        if get_playlist['result']['limits']['total'] > 0:
            get_players = json.loads(xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "Player.GetActivePlayers", "id": 1}'))  # @UndefinedVariable
            pic_player = False
            for _player in get_players['result']:
                if _player['type'] == 'picture':
                    pic_player = True
                else: continue
            if not pic_player:
                play = xbmc.executeJSONRPC('{ "jsonrpc": "2.0", "method": "Player.Open","params":{"item":{"playlistid":2}} }')  # @UndefinedVariable
    else:
        clear_slideshow()
예제 #5
0
def has_movie_library():
    request = {"jsonrpc": "2.0",
               "method": "VideoLibrary.GetMovies",
               "id": "movies"}

    try:
        response = json.loads(xbmc.executeJSONRPC(json.dumps(request)))
        return response['result']['limits']['total'] > 0
    except:
        return False
예제 #6
0
def getSettingByRPC(key):
    """Get Kodi Setting by JSON-RPC

    Args:
        key (TYPE): Description

    Returns:
        TYPE: Description
    """
    result = xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"Settings.GetSettingValue","params":{"setting":"%s"},"id":1}' % key)
    result = json.loads(result)
    return result["result"]["value"]
예제 #7
0
파일: rpc.py 프로젝트: OpenELEQ/meta4kodi
def json_query(query):
    if not "jsonrpc" in query:
        query["jsonrpc"] = "2.0"
    if not "id" in query:
        query["id"] = 1
    
    xbmc_request = json.dumps(query)
    raw = xbmc.executeJSONRPC(xbmc_request)
    clean = unicode(raw, 'utf-8', errors='ignore')
    response = json.loads(clean)
    if "error" in response:
        raise RPCError(response["error"])
    return response.get('result', response)
예제 #8
0
def setSettingByRPC(key, value):
    """Set Kodi Setting by JSON-RPC

    Args:
        key (TYPE): Description
        value (TYPE): Description

    Returns:
        TYPE: Description
    """
    result = xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"Settings.SetSettingValue", "params":{"setting":"%s", "value":%s}, "id":1}' % (key, value))
    result = json.loads(result)
    return result
예제 #9
0
def json_query(query):
    if not "jsonrpc" in query:
        query["jsonrpc"] = "2.0"
    if not "id" in query:
        query["id"] = 1

    xbmc_request = json.dumps(query)
    raw = xbmc.executeJSONRPC(xbmc_request)
    clean = unicode(raw, 'utf-8', errors='ignore')
    response = json.loads(clean)
    if "error" in response:
        raise RPCError(response["error"])
    return response.get('result', response)
예제 #10
0
def getSettingByRPC(key):
    """Get Kodi Setting by JSON-RPC

    Args:
        key (TYPE): Description

    Returns:
        TYPE: Description
    """
    result = xbmc.executeJSONRPC(
        '{"jsonrpc":"2.0","method":"Settings.GetSettingValue","params":{"setting":"%s"},"id":1}'
        % key)
    result = json.loads(result)
    return result["result"]["value"]
예제 #11
0
def setSettingByRPC(key, value):
    """Set Kodi Setting by JSON-RPC

    Args:
        key (TYPE): Description
        value (TYPE): Description

    Returns:
        TYPE: Description
    """
    result = xbmc.executeJSONRPC(
        '{"jsonrpc":"2.0", "method":"Settings.SetSettingValue", "params":{"setting":"%s", "value":%s}, "id":1}'
        % (key, value))
    result = loads(result)
    return result
def get_xbmc_movies():
    import json
    query = {
        'jsonrpc': '2.0',
        'id': 0,
        'method': 'VideoLibrary.GetMovies',
        'params': {
            'properties': ['imdbnumber', 'file']
        }
    }
    response = json.loads(xbmc.executeJSONRPC(json.dumps(query)))
    movie_dict = dict(
        (movie['imdbnumber'], movie['file'])
        for movie in response.get('result', {}).get('movies', []))
    return movie_dict
예제 #13
0
def get_xbmc_movies():
    import json
    query = {
        'jsonrpc': '2.0',
        'id': 0,
        'method': 'VideoLibrary.GetMovies',
        'params': {
            'properties': ['imdbnumber', 'file']
        }
    }
    response = json.loads(xbmc.executeJSONRPC(json.dumps(query)))
    movie_dict = dict(
        (movie['imdbnumber'], movie['file'])
        for movie in response.get('result', {}).get('movies', [])
    )
    return movie_dict
예제 #14
0
def get_library_searches():
    request = {"jsonrpc": "2.0",
               "method": "VideoLibrary.GetMovies",
               "params": {"sort": {"order": "ascending", "method": "label", "ignorearticle": True},
                          "properties" : ["thumbnail"]},
               "id": "movies"}

    response = json.loads(xbmc.executeJSONRPC(json.dumps(request)))

    result = response['result']
    if 'movies' in result:
        for movie in result['movies']:
            name = movie['label'].encode('utf-8')
            item = {'label': name,
                    'thumbnail': movie['thumbnail'],
                    'path': plugin.url_for('youtube_search_result', query=name)}
            yield item
예제 #15
0
def InstallRepo(path="0", tracking_string=""):
    '''
	Cài đặt repo
	Parameters
	----------
	path : string
		Nếu truyền "gid" của Repositories sheet:
			Cài tự động toàn bộ repo trong Repositories sheet
		Nếu truyền link download zip repo
			Download và cài zip repo đó
	tracking_string : string
		 Tên dễ đọc của view
	'''
    GA(  # tracking
        "Install Repo - %s" % tracking_string, "/install-repo/%s" % path)
    if path.isdigit():  # xác định GID
        pDialog = xbmcgui.DialogProgress()
        pDialog.create('Vui lòng đợi', 'Đang cập nhật', 'Đang tải...')
        items = getItems(path)
        total = len(items)
        i = 0
        failed = []
        for item in items:
            done = int(100 * i / total)
            repo_id = item["label2"].split("/")[-1]
            json_result = xbmc.executeJSONRPC(
                '{"jsonrpc":"2.0","method":"Addons.GetAddons", "params":{"type":"xbmc.addon.repository"}, "id":1}'
            )
            repo_list = []
            for addon in json.loads(json_result)["result"]["addons"]:
                repo_list += [addon["addonid"]]
            pDialog.update(done, 'Đang tải', item["label2"] + '...')
            if (item["label2"] == "") or (repo_id not in repo_list):
                try:
                    item["path"] = "http" + item["path"].split("http")[-1]
                    download(urllib.unquote_plus(item["path"]), item["label2"])
                except:
                    failed += [item["label"].encode("utf-8")]
            if pDialog.iscanceled():
                break
            i += 1
        pDialog.close()
        if len(failed) > 0:
            dlg = xbmcgui.Dialog()
            s = "Không thể cài các rep sau:\n[COLOR orange]%s[/COLOR]" % "\n".join(
                failed)
            dlg.ok('Chú ý: Không cài đủ repo!', s)
        else:
            dlg = xbmcgui.Dialog()
            s = "Đã cập nhật thành công"
            dlg.ok('Cập nhật xong!', s)

    else:  # cài repo riêng lẻ
        try:
            download(path, "")
            dlg = xbmcgui.Dialog()
            s = "Repo %s đã được cài thành công" % tracking_string
            dlg.ok('Cài Repo thành công!', s)
        except:
            dlg = xbmcgui.Dialog()
            s = "Vùi lòng thử cài lại lần sau"
            dlg.ok('Cài repo thất bại!', s)

    xbmc.executebuiltin("XBMC.UpdateLocalAddons()")
    xbmc.executebuiltin("XBMC.UpdateAddonRepos()")
def InstallRepo(path = "0", tracking_string = ""):
	'''
	Cài đặt repo
	Parameters
	----------
	path : string
		Nếu truyền "gid" của Repositories sheet:
			Cài tự động toàn bộ repo trong Repositories sheet
		Nếu truyền link download zip repo
			Download và cài zip repo đó
	tracking_string : string
		 Tên dễ đọc của view
	'''
	GA( # tracking
		"Install Repo - %s" % tracking_string,
		"/install-repo/%s" % path
	)
	if path.isdigit(): # xác định GID
		pDialog = xbmcgui.DialogProgress()
		pDialog.create('Vui lòng đợi','Bắt đầu cài repo','Đang tải...')
		items = getItems(path)
		total = len(items)
		i = 0
		failed = []
		installed = []
		for item in items:
			done = int(100 * i / total)
			pDialog.update(done,'Đang tải', item["label"] + '...')
			if ":/" not in item["label2"]:
				result = xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"Addons.GetAddonDetails", "params":{"addonid":"%s", "properties":["version"]}, "id":1}' % item["label"])
				json_result = json.loads(result)
				if "version" in result and version_cmp(json_result["result"]["addon"]["version"], item["label2"]) >= 0:
					pass
				else:
					try:
						item["path"] = "http" + item["path"].split("http")[-1]
						download(urllib.unquote_plus(item["path"]), item["label"])
						installed += [item["label"].encode("utf-8")]
					except:
						failed += [item["label"].encode("utf-8")]
			else:
				if not os.path.exists(xbmc.translatePath(item["label2"])):
					try:
						item["path"] = "http" + item["path"].split("http")[-1]
						download(urllib.unquote_plus(item["path"]), item["label2"])
						installed += [item["label"].encode("utf-8")]
					except:
						failed += [item["label"].encode("utf-8")]


			if pDialog.iscanceled():
				break
			i+=1
		pDialog.close()
		if len(failed) > 0:
			dlg = xbmcgui.Dialog()
			s = "Không thể cài các rep sau:\n[COLOR orange]%s[/COLOR]" % "\n".join(failed)
			dlg.ok('Chú ý: Không cài đủ repo!', s)
		else:
			dlg = xbmcgui.Dialog()
			s = "Tất cả repo đã được cài thành công\n%s" % "\n".join(installed)
			dlg.ok('Cài Repo thành công!', s)

	else: # cài repo riêng lẻ
		try:
			download(path, "")
			dlg = xbmcgui.Dialog()
			s = "Repo %s đã được cài thành công" % tracking_string
			dlg.ok('Cài Repo thành công!', s)
		except:
			dlg = xbmcgui.Dialog()
			s = "Vùi lòng thử cài lại lần sau"
			dlg.ok('Cài repo thất bại!', s)

	xbmc.executebuiltin("XBMC.UpdateLocalAddons()")
	xbmc.executebuiltin("XBMC.UpdateAddonRepos()")
예제 #17
0
def InstallRepo(path="0", tracking_string=""):
	'''
	Cài đặt repo
	Parameters
	----------
	path : string
		Nếu truyền "gid" của Repositories sheet:
			Cài tự động toàn bộ repo trong Repositories sheet
		Nếu truyền link download zip repo
			Download và cài zip repo đó
	tracking_string : string
		 Tên dễ đọc của view
	'''
	GA(  # tracking
		"Install Repo - %s" % tracking_string,
		"/install-repo/%s" % path
	)
	if path.isdigit():  # xác định GID
		pDialog = xbmcgui.DialogProgress()
		pDialog.create('Vui lòng đợi', 'Bắt đầu cài repo', 'Đang tải...')
		items = getItems(path)
		total = len(items)
		i = 0
		failed = []
		installed = []
		for item in items:
			done = int(100 * i / total)
			pDialog.update(done, 'Đang tải', item["label"] + '...')
			if ":/" not in item["label2"]:
				result = xbmc.executeJSONRPC(
					'{"jsonrpc":"2.0","method":"Addons.GetAddonDetails", "params":{"addonid":"%s", "properties":["version"]}, "id":1}' % item["label"])
				json_result = json.loads(result)
				if "version" in result and version_cmp(json_result["result"]["addon"]["version"], item["label2"]) >= 0:
					pass
				else:
					try:
						item["path"] = "http" + item["path"].split("http")[-1]
						download(urllib.unquote_plus(item["path"]), item["label"])
						installed += [item["label"].encode("utf-8")]
					except:
						failed += [item["label"].encode("utf-8")]
			else:
				if not os.path.exists(xbmc.translatePath(item["label2"])):
					try:
						item["path"] = "http" + item["path"].split("http")[-1]
						download(urllib.unquote_plus(item["path"]), item["label2"])
						installed += [item["label"].encode("utf-8")]
					except:
						failed += [item["label"].encode("utf-8")]

			if pDialog.iscanceled():
				break
			i += 1
		pDialog.close()
		if len(failed) > 0:
			dlg = xbmcgui.Dialog()
			s = "Không thể cài các rep sau:\n[COLOR orange]%s[/COLOR]" % "\n".join(
				failed)
			dlg.ok('Chú ý: Không cài đủ repo!', s)
		else:
			dlg = xbmcgui.Dialog()
			s = "Tất cả repo đã được cài thành công\n%s" % "\n".join(installed)
			dlg.ok('Cài Repo thành công!', s)

	else:  # cài repo riêng lẻ
		try:
			download(path, "")
			dlg = xbmcgui.Dialog()
			s = "Repo %s đã được cài thành công" % tracking_string
			dlg.ok('Cài Repo thành công!', s)
		except:
			dlg = xbmcgui.Dialog()
			s = "Vùi lòng thử cài lại lần sau"
			dlg.ok('Cài repo thất bại!', s)

	xbmc.executebuiltin("XBMC.UpdateLocalAddons()")
	xbmc.executebuiltin("XBMC.UpdateAddonRepos()")
예제 #18
0
def setSettingByRPC(key, value):
    result = xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"Settings.SetSettingValue", "params":{"setting":"%s", "value":%s}, "id":1}' % (key, value))
    result = json.loads(result)
    return result
예제 #19
0
def getSettingByRPC(key):
    result = xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"Settings.GetSettingValue","params":{"setting":"%s"},"id":1}' % key)
    result = json.loads(result)
    return result["result"]["value"]