def history_del(num=0): litems = [] litems = list(history_load()) delitem = None for item in litems: hnum = item.get('label', '0: ').split(':', 1)[0] if int(hnum) == int(num): delitem = item break if delitem is not None: litems.remove(delitem) count = 1 items = [] for item in litems: lbl = item.get('label', '0: ') vnum = lbl.split(':', 1)[0] lbl = lbl.split(':', 1)[-1].strip() newlbl = "{0}: {1}".format(count, lbl) item.update({'label': newlbl}) count+=1 items.append(item) litems = items histpath = os.path.join(plugin.storage_path, 'history.json') histfile = file(histpath, mode='w') json.dump(litems, fp=histfile) histfile.close() plugin.notify(msg="DELETED #{0}: {1}".format(str(num), delitem.get('label', ''))) else: plugin.notify(msg="ERROR deleting search #{0}".format(str(num))) xbmc.executebuiltin("Container.Refresh")
def AddPlaylist(tracking_string="Add Playlist"): sheet_url = plugin.keyboard( heading= 'Nhập URL của Google Spreadsheet (có hỗ trợ link rút gọn như bit.ly, goo.gl)' ) if sheet_url: if not re.match("^https*://", sheet_url): sheet_url = "https://" + sheet_url try: resp, content = http.request(sheet_url, "HEAD") sid, gid = re.compile("/d/(.+?)/.+?gid=(\d+)").findall( resp["content-location"])[0] match_passw = re.search('passw=(.+?)($|&)', resp["content-location"]) playlists = plugin.get_storage('playlists') name = plugin.keyboard(heading='Đặt tên cho Playlist') item = "[[COLOR yellow]%s[/COLOR]] %s@%s" % (name, gid, sid) if match_passw: item += "@@" + match_passw.group(1) if 'sections' in playlists: playlists["sections"] = [item] + playlists["sections"] else: playlists["sections"] = [item] xbmc.executebuiltin('Container.Refresh') except: line1 = "Vui lòng nhập URL hợp lệ. Ví dụ dạng đầy đủ:" line2 = "http://docs.google.com/spreadsheets/d/xxx/edit#gid=###" line3 = "Hoặc rút gọn: http://bit.ly/xxxxxx hoặc http://goo.gl/xxxxx" dlg = xbmcgui.Dialog() dlg.ok("URL không hợp lệ!!!", line1, line2, line3)
def PasswordSection(password="******", path="0", tracking_string="Home"): ''' Liệt kê danh sách các item của một sheet Parameters ---------- path : string "gid" của sheet tracking_string : string Tên dễ đọc của view ''' GA( # tracking "Password Section - %s" % tracking_string, "/password-section/%s" % path ) passwords = plugin.get_storage('passwords') if password in passwords and (time.time() - passwords[password] < 1800): items = AddTracking(getItems(path)) return plugin.finish(items) else: passw_string = plugin.keyboard(heading='Nhập password') if passw_string == password: passwords[password] = time.time() items = AddTracking(getItems(path)) return plugin.finish(items) else: header = "Sai mật khẩu!!!" message = "Mật khẩu không khớp. Không tải được nội dung" xbmc.executebuiltin('Notification("%s", "%s", "%d", "%s")' % (header, message, 10000, '')) return plugin.finish()
def history_del(num=0): litems = [] litems = list(history_load()) delitem = None for item in litems: hnum = item.get('label', '0: ').split(':', 1)[0] if int(hnum) == int(num): delitem = item break if delitem is not None: litems.remove(delitem) count = 1 items = [] for item in litems: lbl = item.get('label', '0: ') vnum = lbl.split(':', 1)[0] lbl = lbl.split(':', 1)[-1].strip() newlbl = "{0}: {1}".format(count, lbl) item.update({'label': newlbl}) count += 1 items.append(item) litems = items histpath = os.path.join(plugin.storage_path, 'history.json') histfile = file(histpath, mode='w') json.dump(litems, fp=histfile) histfile.close() plugin.notify( msg="DELETED #{0}: {1}".format(str(num), delitem.get('label', ''))) else: plugin.notify(msg="ERROR deleting search #{0}".format(str(num))) xbmc.executebuiltin("Container.Refresh")
def AddPlaylist(tracking_string="Add Playlist"): sheet_url = plugin.keyboard( heading='Nhập URL của Google Spreadsheet (có hỗ trợ link rút gọn như bit.ly, goo.gl)') if sheet_url: if not re.match("^https*://", sheet_url): sheet_url = "https://" + sheet_url try: resp, content = http.request(sheet_url, "HEAD") sid, gid = re.compile( "/d/(.+?)/.+?gid=(\d+)").findall(resp["content-location"])[0] match_passw = re.search('passw=(.+?)($|&)', resp["content-location"]) playlists = plugin.get_storage('playlists') name = plugin.keyboard(heading='Đặt tên cho Playlist') item = "[[COLOR yellow]%s[/COLOR]] %s@%s" % (name, gid, sid) if match_passw: item += "@@" + match_passw.group(1) if 'sections' in playlists: playlists["sections"] = [item] + playlists["sections"] else: playlists["sections"] = [item] xbmc.executebuiltin('Container.Refresh') except: line1 = "Vui lòng nhập URL hợp lệ. Ví dụ dạng đầy đủ:" line2 = "http://docs.google.com/spreadsheets/d/xxx/edit#gid=###" line3 = "Hoặc rút gọn: http://bit.ly/xxxxxx hoặc http://goo.gl/xxxxx" dlg = xbmcgui.Dialog() dlg.ok("URL không hợp lệ!!!", line1, line2, line3)
def PasswordSection(password="******", path="0", tracking_string="Home"): ''' Liệt kê danh sách các item của một sheet Parameters ---------- path : string "gid" của sheet tracking_string : string Tên dễ đọc của view ''' GA( # tracking "Password Section - %s" % tracking_string, "/password-section/%s" % path) passwords = plugin.get_storage('passwords') if password in passwords and (time.time() - passwords[password] < 1800): items = AddTracking(getItems(path)) return plugin.finish(items) else: passw_string = plugin.keyboard(heading='Nhập password') if passw_string == password: passwords[password] = time.time() items = AddTracking(getItems(path)) return plugin.finish(items) else: header = "Sai mật khẩu!!!" message = "Mật khẩu không khớp. Không tải được nội dung" xbmc.executebuiltin('Notification("%s", "%s", "%d", "%s")' % (header, message, 10000, '')) return plugin.finish()
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("Install Repo - %s" % tracking_string, "/install-repo/%s" % path) # tracking should_update = False 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 = [] for item in items: done = int(100 * i / total) pDialog.update(done, "Đang tải", item["label2"] + "...") try: item["path"] = "http" + item["path"].split("http")[-1] download(urllib.unquote_plus(item["path"]), item["label2"]) should_update = True 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" dlg.ok("Cài Repo thành công!", s) else: # cài repo riêng lẻ try: download(path, "") should_update = True 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) if should_update: xbmc.executebuiltin("XBMC.UpdateLocalAddons()") xbmc.executebuiltin("XBMC.UpdateAddonRepos()")
def execbuiltin(path, tracking_string=""): GA( # tracking "Execute Builtin - %s" % tracking_string, "/repo-execbuiltin/%s" % path) try: xbmc.executebuiltin('XBMC.RunPlugin(%s)' % urllib.unquote_plus(path)) except: pass
def execbuiltin(path, tracking_string=""): GA( # tracking "Execute Builtin - %s" % tracking_string, "/repo-execbuiltin/%s" % path ) try: xbmc.executebuiltin('XBMC.RunPlugin(%s)' % urllib.unquote_plus(path)) except: pass
def open_web_url(url): if not is_android(): try: import webbrowser webbrowser.open_new(url) except Exception as ex: log("open_web_url error: %s" % ex, level=xbmc.LOGERROR) else: xbmc.executebuiltin( 'XBMC.StartAndroidActivity(,"android.intent.action.VIEW", ,"%s")' % url)
def notify(self, msg='', title=None, delay=5000, image=''): """Displays a temporary notification message to the user. If title is not provided, the plugin name will be used. To have a blank title, pass '' for the title argument. The delay argument is in milliseconds. """ if not msg: log.warning('Empty message for notification dialog') if title is None: title = self.addon.getAddonInfo('name') xbmc.executebuiltin('Kodi.Notification("%s", "%s", "%s", "%s")' % (msg, title, delay, image))
def RemovePlaylists(item=""): item = urllib.unquote_plus(item) if item is not "": playlists = plugin.get_storage('playlists') if 'sections' in playlists: new_playlists = [] for section in playlists["sections"]: if section != item: new_playlists += [section] playlists["sections"] = new_playlists else: plugin.get_storage('playlists').clear() xbmc.executebuiltin('Container.Refresh')
def remove_from_playlist(self, playlist, url): '''Deletes an item from the given playlist whose url matches the provided url. ''' # We don't have the full item in temp_items, so have to iterate over items # in the list and match on url my_playlists = self.plugin.get_storage('my_playlists') try: match = (item for item in my_playlists[playlist] if item['path'] == url).next() my_playlists[playlist].remove(match) my_playlists.sync() xbmc.executebuiltin('Container.Refresh') except StopIteration: pass
def remove_playlist(self, playlist): '''Deletes a user specified playlist. If the playlist is not empty, the user will be presented with a yes/no confirmation dialog before deletion. ''' my_playlists = self.plugin.get_storage('my_playlists') num_items = len(my_playlists[playlist]) delete = True if num_items > 0: dialog = xbmcgui.Dialog() delete = dialog.yesno(self.plugin.name, 'Are you sure you wish to delete?') if delete: del my_playlists[playlist] my_playlists.sync() xbmc.executebuiltin('Container.Refresh')
def fav_del(idvid=''): litems = [] litems = list(history_load()) delitem = None for item in litems: hnum = item.get('label2', '0: ') if hnum == idvid: delitem = item break if delitem is not None: litems.remove(delitem) count = 1 items = [] histpath = os.path.join(plugin.storage_path, 'fav.json') histfile = file(histpath, mode='w') json.dump(litems, fp=histfile) histfile.close() plugin.notify(msg="DELETED #{0}: {1}".format(idvid, delitem.get('label', ''))) else: plugin.notify(msg="ERROR deleting search #{0}".format(idvid)) xbmc.executebuiltin("Container.Refresh")
def start_bitx(magnet_link): if is_android() and is_bitx_installed(): # noinspection PyBroadException try: notice(_lang(33027), _lang(33026)) # StartAndroidActivity(package,[intent,dataType,dataURI]) # Launch an Android native app with the given package name. # Optional parms (in order): intent, dataType, dataURI. # example: StartAndroidActivity(com.android.chrome,android.intent.action.VIEW,,http://kodi.tv/) v13 Addition intent = "android.intent.action.VIEW" xbmc.executebuiltin( 'XBMC.StartAndroidActivity("%s", "%s", , "%s")' % (bitx_package, intent, magnet_link)) return except Exception as ex: log("Android intent error: %s" % ex, level=xbmc.LOGERROR) if os_is_android: xbmcgui.Dialog().ok(_lang(33028), _lang(33029)) open_web_url(BITIX_PLAY_LINK)
def LoginOKNoti(user="", lvl=""): header = "[COLOR yellow]ENTETAINMENT![/COLOR]" message = "[COLOR blue][B]Enjoy Your Time[/B][/COLOR]" xbmc.executebuiltin('Notification("{}", "{}","{}", "")'.format( header, message, "10000"))
def LoginOKNoti(user="", lvl=""): header = "[COLOR blue]TRUNG TÂM GIẢI TRÍ [/COLOR][COLOR lime]CINEMA CENTER![/COLOR]" message = "[COLOR yellow][B]ENJOY YOUR LIFE![/B][/COLOR]" xbmc.executebuiltin('Notification("{}", "{}","{}", "")'.format( header, message, "10000"))
def get_playable_url(url): if "youtube" in url: match = re.compile( '(youtu\.be\/|youtube-nocookie\.com\/|youtube\.com\/(watch\?(.*&)?v=|(embed|v|user)\/))([^\?&"\'>]+)').findall(url) yid = match[0][len(match[0])-1].replace('v/', '') url = 'plugin://plugin.video.youtube/play/?video_id=%s' % yid elif "thvli.vn/backend/cm/detail/" in url: get_thvl = "https://docs.google.com/spreadsheets/d/13VzQebjGYac5hxe1I-z1pIvMiNB0gSG7oWJlFHWnqsA/export?format=tsv&gid=1287121588" try: (resp, content) = http.request( get_thvl, "GET" ) except: header = "Server quá tải!" message = "Xin vui lòng thử lại sau" xbmc.executebuiltin('Notification("%s", "%s", "%d", "%s")' % (header, message, 10000, '')) return "" tmps = content.split('\n') random.shuffle(tmps) for tmp in tmps: try: thvl_headers = { 'User-Agent': 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.3; WOW64; Trident/7.0)', "Accept-Encoding": "gzip, deflate, br", 'Accept': 'application/json', 'Authorization': tmp.decode('base64') } (resp, content) = http.request( url, "GET", headers=thvl_headers ) resp_json = json.loads(content) if "link_play" in resp_json: return resp_json["link_play"] except: pass elif "sphim.tv" in url: http.follow_redirects = False get_sphim = "https://docs.google.com/spreadsheets/d/13VzQebjGYac5hxe1I-z1pIvMiNB0gSG7oWJlFHWnqsA/export?format=tsv&gid=1082544232" try: (resp, content) = http.request( get_sphim, "GET" ) except: header = "Server quá tải!" message = "Xin vui lòng thử lại sau" xbmc.executebuiltin('Notification("%s", "%s", "%d", "%s")' % (header, message, 10000, '')) return "" tmps = content.split('\n') random.shuffle(tmps) for tmp in tmps: try: sphim_headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36', "Accept-Encoding": "gzip, deflate", 'Cookie': tmp.decode("base64") } (resp, content) = http.request( url, "GET", headers=sphim_headers ) match = re.search('"(http.+?\.smil/playlist.m3u8.+?)"', content) if match: return match.group(1) except: pass elif url.startswith("acestream://") or url.endswith(".acelive") or "arenavision.in" in url: if "arenavision.in" in url: h = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36', 'Cookie': '__cfduid=d36d59e9714c527d920417ed5bbc9315e1496259947; beget=begetok; ads_smrt_popunder=1%7CSat%2C%2003%20Jun%202017%2018%3A57%3A05%20GMT; 141054_245550_1rhpmin=yes; 141054_245550_1rhpmax=4|Sat%2C%2003%20Jun%202017%2018%3A57%3A14%20GMT; has_js=1; _ga=GA1.2.652127938.1496259947; _gid=GA1.2.653920302.1496429805; _gat=1', 'Accept-Encoding': 'gzip, deflate' } (resp, content) = http.request( url, "GET", headers=h ) url = re.search('(acestream://.+?)"', content).group(1) try: (resp, content) = http.request( "http://localhost:6878/webui/api/service", "HEAD" ) url = url.replace( "acestream://", "http://localhost:6878/ace/getstream?id=") + "&.mp4" if url.endswith(".acelive"): url = "http://localhost:6878/ace/getstream?url=" + \ urllib.quote_plus(url) + "&.mp4" except: url = 'plugin://program.plexus/?url=%s&mode=1&name=P2PStream&iconimage=' % urllib.quote_plus( url) elif any(domain in url for domain in ["m.tivi8k.net", "m.xemtvhd.com", "xemtiviso.com"]): play_url = "" if "xemtiviso.com" not in url: for i in range(1, 8): try: if i > 1: range_url = url.replace(".php", "-%s.php" % i) h1 = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36', 'Accept-Encoding': 'gzip, deflate', 'Referer': '%s' % url.replace("/m.", "/www.") } (resp, content) = http.request( range_url, "GET", headers=h1, ) content = content.replace("'", '"') try: play_url = re.search("https*://api.tivi8k.net/.+?'", content).group(1) (resp, content) = http.request( range_url, "GET", headers=h1, ) if "#EXTM3U" in content: return play_url else: return content.strip() except: pass play_url = play_url.replace("q=medium", "q=high") if "v4live" in play_url: return play_url except: pass try: xemtiviso_id = re.search("/(.+?).php", url).group(1).split("-")[0] xemtiviso_url = "http://sv2.xemtiviso.com/mimi.php?id=" + xemtiviso_id h1 = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36', 'Accept-Encoding': 'gzip, deflate', 'Referer': '%s' % xemtiviso_url } (resp, content) = http.request( xemtiviso_url, "GET", headers=h1, ) content = content.replace("'", '"') play_url = re.search('source\: "(.+?)"', content).group(1) play_url = play_url.replace("q=medium", "q=high") if "v4live" in play_url: return play_url except: pass else: try: h1 = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36', 'Accept-Encoding': 'gzip, deflate', 'Referer': '%s' % url.replace("/m.", "/www.") } (resp, content) = http.request( url, "GET", headers=h1, ) content = content.replace("'", '"') play_url = re.search('source\: "(.+?)"', content).group(1) play_url = play_url.replace("q=medium", "q=high") except: pass return play_url elif "vtc.gov.vn" in url: headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.92 Safari/537.36', 'Accept-Encoding': 'None' } (resp, content) = http.request( url, "GET", headers=headers ) match = re.search("src: '(.+?)'", content) return match.group(1) elif "livestream.com" in url: headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0', 'Accept-Encoding': 'gzip, deflate', } try: if "events" not in url: (resp, content) = http.request( url, "GET", headers=headers, ) match = re.search("accounts/\d+/events/\d+", content) url = "https://livestream.com/api/%s" % match.group() (resp, content) = http.request( url, "GET", headers=headers, ) j = json.loads(content) url = j["stream_info"]["m3u8_url"] except: pass elif "onecloud.media" in url: ocid = url.split("/")[-1].strip() oc_url = "http://onecloud.media/embed/" + ocid h = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.96 Safari/537.36', 'Accept-Encoding': 'gzip, deflate, sdch', 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 'X-Requested-With': 'XMLHttpRequest', 'Cookie': 'TimeOut=999999999'} (resp, content) = http.request( oc_url, "POST", headers=h, body=urllib.urlencode({'type': 'directLink', 'ip': ''}) ) try: url = json.loads(content)["list"][0]["file"] except: header = "Có lỗi xảy ra!" message = "Không lấy được link (link hỏng hoặc bị xóa)" xbmc.executebuiltin('Notification("%s", "%s", "%d", "%s")' % (header, message, 10000, '')) return "" elif "pscp.tv" in url: pscpid = re.search("w/(.+?)($|\?)", url).group(1) api_url = "https://proxsee.pscp.tv/api/v2/accessVideoPublic?broadcast_id=%s&replay_redirect=false" % pscpid (resp, content) = http.request( api_url, "GET" ) return json.loads(content)["hls_url"] elif "google.com" in url: url = getGDriveHighestQuality(url) elif re.match("^https*\://www\.fshare\.vn/file", url): try: cred = GetFShareCred() if cred: fshare_headers = { "Accept-Encoding": "gzip, deflate, br", 'Cookie': 'session_id=%s' % cred["session_id"] } data = { "url": url, "token": cred["token"], "password": "" } (resp, content) = http.request( convert_ipv4_url("https://api2.fshare.vn/api/session/download"), "POST", body=json.dumps(data), headers=fshare_headers ) url = json.loads(content)["location"] url = convert_ipv4_url(url) if resp.status == 404: header = "Không lấy được link FShare VIP!" message = "Link không tồn tại hoặc file đã bị xóa" xbmc.executebuiltin('Notification("%s", "%s", "%d", "%s")' % (header, message, 10000, '')) return None (resp, content) = http.request( url, "HEAD" ) if '/ERROR' in resp['content-location']: header = "Không lấy được link FShare VIP!" message = "Link không tồn tại hoặc file đã bị xóa" xbmc.executebuiltin('Notification("%s", "%s", "%d", "%s")' % (header, message, 10000, '')) return None return url return None except: pass elif "tv24.vn" in url: cid = re.compile('/(\d+)/').findall(url)[0] return "plugin://plugin.video.sctv/play/" + cid elif "dailymotion.com" in url: did = re.compile("/(\w+)$").findall(url)[0] return "plugin://plugin.video.dailymotion_com/?url=%s&mode=playVideo" % did else: if "://" not in url: url = None return url
def set_view_mode(view_mode_id): """Calls Kodi's Container.SetViewMode. Requires an integer view_mode_id""" xbmc.executebuiltin('Container.SetViewMode(%d)' % view_mode_id)
def LoginOKNoti(user="", lvl=""): header = "[COLOR red]FAMILY[/COLOR][COLOR lime]ENTERTAINMENT![/COLOR]" message = "[COLOR blue][B]ENJOY YOUR TIME[/B][/COLOR]" xbmc.executebuiltin('Notification("{}", "{}", "{}", "")'.format( header, message, "10000"))
def LoginOKNoti(user="", lvl=""): header = "[COLOR red]HieuHien.vn [/COLOR][COLOR lime]chúc bạn xem phim vui vẻ![/COLOR]" message = "[COLOR blue][B]facebook.com/HieuHien.vn[/B][/COLOR]" xbmc.executebuiltin('Notification("{}", "{}","{}", "")'.format( header, message, "10000"))
def LoginOKNoti(user="", lvl=""): header = "Đăng nhập thành công!" message = "Chào user [COLOR orange]{}[/COLOR] (lvl [COLOR yellow]{}[/COLOR])".format( user, lvl) xbmc.executebuiltin('Notification("{}", "{}", "{}", "")'.format( header, message, "10000"))
def LoginOKNoti(user="", lvl=""): header = "[COLOR yellow]Đăng nhập thành công![/COLOR]" message = "Chào [COLOR red]VIP[/COLOR] [COLOR lime]{}[/COLOR] (lvl [COLOR yellow]{}[/COLOR])".format( user, lvl) xbmc.executebuiltin('Notification("{}", "{}", "{}", "")'.format( header, message, "10000"))
def showimage(url, tracking_string): xbmc.executebuiltin("ShowPicture(%s)" % urllib.unquote_plus(url))
def LoginOKNoti(user="",lvl=""): header = "Đăng nhập thành công!" message = "Chào user [COLOR orange]{}[/COLOR] (lvl [COLOR yellow]{}[/COLOR])".format(user, lvl) xbmc.executebuiltin('Notification("{}", "{}", "{}", "")'.format(header, message, "10000"))
def action_custom_action(action): log("action_custom_action: %s" % action) xbmc.executebuiltin(action)
def execbuiltin(path, tracking_string=""): GA("Execute Builtin - %s" % tracking_string, "/repo-execbuiltin/%s" % path) # tracking xbmc.executebuiltin("XBMC.RunPlugin(%s)" % urllib.unquote_plus(path))
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()")
def LoginOKNoti(user="",lvl=""): header = "[COLOR red][B]CHÚC MỪNG NĂM MỚI![/B][/COLOR]" message = "[COLOR red][B]HAPPY NEW YEAR ![/B][/COLOR]" xbmc.executebuiltin('Notification("{}", "{}", "{}", "")'.format(header, message, "15000"))
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()")
def LoginOKNoti(user="", lvl=""): header = "[COLOR red]ALOHA[/COLOR] [COLOR lime]CINEMA![/COLOR]" message = "[COLOR blue][B]KÍNH CHÀO QUÝ KHÁCH[/B][/COLOR]" xbmc.executebuiltin('Notification("{}", "{}", "{}", "")'.format( header, message, "10000"))
def get_playable_url(url): if "youtube" in url: match = re.compile( '(youtu\.be\/|youtube-nocookie\.com\/|youtube\.com\/(watch\?(.*&)?v=|(embed|v|user)\/))([^\?&"\'>]+)' ).findall(url) yid = match[0][len(match[0]) - 1].replace('v/', '') url = 'plugin://plugin.video.youtube/play/?video_id=%s' % yid elif "thvli.vn/backend/cm/detail/" in url: get_thvl = "https://docs.google.com/spreadsheets/d/13VzQebjGYac5hxe1I-z1pIvMiNB0gSG7oWJlFHWnqsA/export?format=tsv&gid=1287121588" try: (resp, content) = http.request(get_thvl, "GET") except: header = "Server quá tải!" message = "Xin vui lòng thử lại sau" xbmc.executebuiltin('Notification("%s", "%s", "%d", "%s")' % (header, message, 10000, '')) return "" tmps = content.split('\n') random.shuffle(tmps) for tmp in tmps: try: thvl_headers = { 'User-Agent': 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.3; WOW64; Trident/7.0)', "Accept-Encoding": "gzip, deflate, br", 'Accept': 'application/json', 'Authorization': tmp.decode('base64') } (resp, content) = http.request(url, "GET", headers=thvl_headers) resp_json = json.loads(content) if "link_play" in resp_json: return resp_json["link_play"] except: pass elif "sphim.tv" in url: http.follow_redirects = False get_sphim = "https://docs.google.com/spreadsheets/d/13VzQebjGYac5hxe1I-z1pIvMiNB0gSG7oWJlFHWnqsA/export?format=tsv&gid=1082544232" try: (resp, content) = http.request(get_sphim, "GET") except: header = "Server quá tải!" message = "Xin vui lòng thử lại sau" xbmc.executebuiltin('Notification("%s", "%s", "%d", "%s")' % (header, message, 10000, '')) return "" tmps = content.split('\n') random.shuffle(tmps) for tmp in tmps: try: sphim_headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36', "Accept-Encoding": "gzip, deflate", 'Cookie': tmp.decode("base64") } (resp, content) = http.request(url, "GET", headers=sphim_headers) match = re.search('"(http.+?\.smil/playlist.m3u8.+?)"', content) if match: return match.group(1) except: pass elif url.startswith("acestream://") or url.endswith( ".acelive") or "arenavision.in" in url: if "arenavision.in" in url: h = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36', 'Cookie': '__cfduid=d36d59e9714c527d920417ed5bbc9315e1496259947; beget=begetok; ads_smrt_popunder=1%7CSat%2C%2003%20Jun%202017%2018%3A57%3A05%20GMT; 141054_245550_1rhpmin=yes; 141054_245550_1rhpmax=4|Sat%2C%2003%20Jun%202017%2018%3A57%3A14%20GMT; has_js=1; _ga=GA1.2.652127938.1496259947; _gid=GA1.2.653920302.1496429805; _gat=1', 'Accept-Encoding': 'gzip, deflate' } (resp, content) = http.request(url, "GET", headers=h) url = re.search('(acestream://.+?)"', content).group(1) try: (resp, content) = http.request("http://localhost:6878/webui/api/service", "HEAD") url = url.replace( "acestream://", "http://localhost:6878/ace/getstream?id=") + "&.mp4" if url.endswith(".acelive"): url = "http://localhost:6878/ace/getstream?url=" + \ urllib.quote_plus(url) + "&.mp4" except: url = 'plugin://program.plexus/?url=%s&mode=1&name=P2PStream&iconimage=' % urllib.quote_plus( url) elif any(domain in url for domain in ["m.tivi8k.net", "m.xemtvhd.com", "xemtiviso.com"]): play_url = "" if "xemtiviso.com" not in url: for i in range(1, 8): try: if i > 1: range_url = url.replace(".php", "-%s.php" % i) h1 = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36', 'Accept-Encoding': 'gzip, deflate', 'Referer': '%s' % url.replace("/m.", "/www.") } (resp, content) = http.request( range_url, "GET", headers=h1, ) content = content.replace("'", '"') try: play_url = re.search("https*://api.tivi8k.net/.+?'", content).group(1) (resp, content) = http.request( range_url, "GET", headers=h1, ) if "#EXTM3U" in content: return play_url else: return content.strip() except: pass play_url = play_url.replace("q=medium", "q=high") if "v4live" in play_url: return play_url except: pass try: xemtiviso_id = re.search("/(.+?).php", url).group(1).split("-")[0] xemtiviso_url = "http://sv2.xemtiviso.com/mimi.php?id=" + xemtiviso_id h1 = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36', 'Accept-Encoding': 'gzip, deflate', 'Referer': '%s' % xemtiviso_url } (resp, content) = http.request( xemtiviso_url, "GET", headers=h1, ) content = content.replace("'", '"') play_url = re.search('source\: "(.+?)"', content).group(1) play_url = play_url.replace("q=medium", "q=high") if "v4live" in play_url: return play_url except: pass else: try: h1 = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36', 'Accept-Encoding': 'gzip, deflate', 'Referer': '%s' % url.replace("/m.", "/www.") } (resp, content) = http.request( url, "GET", headers=h1, ) content = content.replace("'", '"') play_url = re.search('source\: "(.+?)"', content).group(1) play_url = play_url.replace("q=medium", "q=high") except: pass return play_url elif "vtc.gov.vn" in url: headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.92 Safari/537.36', 'Accept-Encoding': 'None' } (resp, content) = http.request(url, "GET", headers=headers) match = re.search("src: '(.+?)'", content) return match.group(1) elif "livestream.com" in url: headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0', 'Accept-Encoding': 'gzip, deflate', } try: if "events" not in url: (resp, content) = http.request( url, "GET", headers=headers, ) match = re.search("accounts/\d+/events/\d+", content) url = "https://livestream.com/api/%s" % match.group() (resp, content) = http.request( url, "GET", headers=headers, ) j = json.loads(content) url = j["stream_info"]["m3u8_url"] except: pass elif "onecloud.media" in url: ocid = url.split("/")[-1].strip() oc_url = "http://onecloud.media/embed/" + ocid h = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.96 Safari/537.36', 'Accept-Encoding': 'gzip, deflate, sdch', 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 'X-Requested-With': 'XMLHttpRequest', 'Cookie': 'TimeOut=999999999' } (resp, content) = http.request(oc_url, "POST", headers=h, body=urllib.urlencode({ 'type': 'directLink', 'ip': '' })) try: url = json.loads(content)["list"][0]["file"] except: header = "Có lỗi xảy ra!" message = "Không lấy được link (link hỏng hoặc bị xóa)" xbmc.executebuiltin('Notification("%s", "%s", "%d", "%s")' % (header, message, 10000, '')) return "" elif "pscp.tv" in url: pscpid = re.search("w/(.+?)($|\?)", url).group(1) api_url = "https://proxsee.pscp.tv/api/v2/accessVideoPublic?broadcast_id=%s&replay_redirect=false" % pscpid (resp, content) = http.request(api_url, "GET") return json.loads(content)["hls_url"] elif "google.com" in url: url = getGDriveHighestQuality(url) elif re.match("^https*\://www\.fshare\.vn/file", url): try: cred = GetFShareCred() if cred: fshare_headers = { "Accept-Encoding": "gzip, deflate, br", 'Cookie': 'session_id=%s' % cred["session_id"] } data = {"url": url, "token": cred["token"], "password": ""} (resp, content) = http.request( "https://118.69.164.19/api/session/download", "POST", body=json.dumps(data), headers=fshare_headers) url = json.loads(content)["location"] url = convert_ipv4_url(url) if resp.status == 404: header = "Không lấy được link FShare VIP!" message = "Link không tồn tại hoặc file đã bị xóa" xbmc.executebuiltin( 'Notification("%s", "%s", "%d", "%s")' % (header, message, 10000, '')) return None (resp, content) = http.request(url, "HEAD") if '/ERROR' in resp['content-location']: header = "Không lấy được link FShare VIP!" message = "Link không tồn tại hoặc file đã bị xóa" xbmc.executebuiltin( 'Notification("%s", "%s", "%d", "%s")' % (header, message, 10000, '')) return None return url return None except: pass elif "tv24.vn" in url: cid = re.compile('/(\d+)/').findall(url)[0] return "plugin://plugin.video.sctv/play/" + cid elif "dailymotion.com" in url: did = re.compile("/(\w+)$").findall(url)[0] return "plugin://plugin.video.dailymotion_com/?url=%s&mode=playVideo" % did else: if "://" not in url: url = None return url
def kodi_go_back(): # Go back in navigation. xbmc.executebuiltin("Action(Back)")