def item_play(self, data):
        progress = xbmcgui.DialogProgress()
        try:
            progress.create('Polonium-210', 'Stream is starting ...')
            progress.update(25)
            item = data['item'].copy()
            item['is_playable'] = True
            if 'streams' not in data:
                icon = self.plugin.addon.getAddonInfo('icon')
                xbmcgui.Dialog().notification('Polonium-210',
                                              'No stream',
                                              icon=icon)

            streams_qualities = data['streams'].keys()
            original_streams_qualities = list(
                filter(lambda x: x not in ['best', 'worst'],
                       streams_qualities))
            original_streams_qualities_len = len(original_streams_qualities)
            if original_streams_qualities_len > 1:
                selected = self._select_dialog("Select stream",
                                               streams_qualities)
                if selected < 0:
                    return
            else:
                selected = 0

            progress.update(50)

            selected_quality = streams_qualities[selected]
            stream = data['streams'][selected_quality]

            if stream['type'] in ('http', 'hls'):
                item['path'] = stream['url']
            elif stream['type'] == 'rtmp':
                params = stream['params'].copy()
                url = params.pop('rtmp')
                args = " ".join(
                    ["=".join([k, str(v)]) for k, v in params.items()])
                item['path'] = " ".join([url, args])
            else:
                icon = self.plugin.addon.getAddonInfo('icon')
                xbmcgui.Dialog().notification(
                    'Polonium-210',
                    "Unsupported stream type {0}".format(stream['type']),
                    icon=icon,
                )
            self.plugin.play_video(item)
            # self.plugin.set_resolved_url(item)
            progress.update(75)
        finally:
            if progress:
                progress.close()
 def __init__(self,
              heading,
              line1='',
              line2='',
              line3='',
              countdown=60,
              interval=5):
     self.heading = heading
     self.countdown = countdown
     self.interval = interval
     self.line3 = line3
     self.pd = xbmcgui.DialogProgress()
     if not self.line3: line3 = 'Expires in: %s seconds' % (countdown)
     self.pd.create(self.heading, line1, line2, line3)
     self.pd.update(100)
Esempio n. 3
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()")