def AddNewList(): listName = GetKeyboardText(getLocaleString(30004)).strip() if len(listName) < 1: return listUrl = GetChoice(30002, 30005, 30006, 30016, 30017, fileType=1, fileMask='.plx|.m3u|.m3u8') if len(listUrl) < 1: return image = GetChoice(30022, 30022, 30022, 30024, 30025, 30021, fileType=2) logosUrl = '' if listUrl.endswith('.plx') else GetChoice(30018, 30019, 30020, 30019, 30020, 30021, fileType=0) if logosUrl.startswith('http') and not logosUrl.endswith('/'): logosUrl += '/' epgUrl = '' if listUrl.endswith('.plx') else GetChoice(30046, 30047, 30048, 30047, 30048, 30021, fileType=1, fileMask='.xml') # if epgUrl.startswith('http') and not epgUrl.endswith('/'): # epgUrl += '/' cacheInMinutes = GetNumFromUser(getLocaleString(30034), '0') if listUrl.startswith('http') else 0 if cacheInMinutes is None: cacheInMinutes = 0 chList = common.ReadList(playlistsFile) for item in chList: if item["url"].lower() == listUrl.lower(): xbmc.executebuiltin('Notification({0}, "{1}" {2}, 5000, {3})'.format(AddonName, item["name"], getLocaleString(30007), icon)) return chList.append({"name": listName, "url": listUrl, "image": image, "logos": logosUrl, "epg": epgUrl, "cache": cacheInMinutes, "uuid": str(random.uuid4())}) if common.SaveList(playlistsFile, chList): xbmc.executebuiltin("Container.Refresh()")
def PlxCategory(url, cache): tmpList = [] chList = common.plx2list(url, cache) background = chList[0]["background"] for channel in chList[1:]: iconimage = "" if "thumb" not in channel else common.GetEncodeString( channel["thumb"]) name = common.GetEncodeString(channel["name"]) if channel["type"] == 'playlist': AddDir("[{0}]".format(name), channel["url"], 1, iconimage, background=background) else: AddDir(name, channel["url"], 3, iconimage, isFolder=False, IsPlayable=True, background=background) tmpList.append({ "url": channel["url"], "image": iconimage, "name": name }) common.SaveList(tmpListFile, tmpList)
def RemoveFromFavourites(index): favList = common.ReadList(favoritesFile) if index < 0 or index >= len(favList): return del favList[index] common.SaveList(favoritesFile, favList) xbmc.executebuiltin("Container.Refresh()")
def AddToDirectory(playlist_uuid): # if vdir is none, ask to choose one vdirs = common.ReadList(vDirectoriesFile) dialog = xbmcgui.Dialog() svdir = dialog.select("Choose the directory were to attach this playlist", [item["name"] for item in vdirs]) vdirs[svdir]["data"].append(playlist_uuid) common.SaveList(vDirectoriesFile, vdirs) xbmc.executebuiltin("Container.Refresh()")
def ChangeCache(iuuid, listFile): index = GetPlaylistIndex(iuuid, listFile) chList = common.ReadList(listFile) defaultText = chList[index].get('cache', 0) cacheInMinutes = GetNumFromUser(getLocaleString(30034), str(defaultText)) if chList[index].get('url', '0').startswith('http') else 0 if cacheInMinutes is None: return chList[index]['cache'] = cacheInMinutes if common.SaveList(listFile, chList): xbmc.executebuiltin("Container.Refresh()")
def DeleteDirectory(iuuid, with_contents=False): vDirs = common.ReadList(vDirectoriesFile) y = 0 for vdir in vDirs: if vdir["uuid"] == iuuid: if with_contents: contents = common.ReadList(playlistsFile) i = 0 uuids = vdir["data"] uuids = [uuid4 for uuid4 in uuids] for content in contents: if content["uuid"] in uuids: del contents[i] i += 1 common.SaveList(playlistsFile, contents) del vDirs[y] common.SaveList(vDirectoriesFile, vDirs) xbmc.executebuiltin("Container.Refresh()") y += 1
def AddNewDirectory(): dir_name = GetKeyboardText(getLocaleString(30040), "My new directory name") dir_icon = xbmcgui.Dialog().browse(1, getLocaleString(30042), 'files') if dir_name != "": vDirs = common.ReadList(vDirectoriesFile) vDirs.append({"name": dir_name, "data": [], "icon": dir_icon, "uuid": str(random.uuid4())}) common.SaveList(vDirectoriesFile, vDirs) xbmc.executebuiltin("Container.Refresh()")
def ChangeKey(iuuid, listFile, key, title, favourites=False): chList = common.ReadList(listFile) index = GetPlaylistIndex(iuuid, listFile) if not favourites else iuuid str = GetKeyboardText(getLocaleString(title), chList[index][key]) if len(str) < 1: return chList[index][key] = str if common.SaveList(listFile, chList): xbmc.executebuiltin("Container.Refresh()")
def ChangeChoice(iuuid, listFile, key, choiceTitle, fileTitle, urlTitle, choiceFile, choiceUrl, choiceNone=None, fileType=1, fileMask=None, favourites=False): index = GetPlaylistIndex(iuuid, listFile) if not favourites else iuuid chList = common.ReadList(listFile) defaultText = chList[index].get(key, "") str = GetChoice(choiceTitle, fileTitle, urlTitle, choiceFile, choiceUrl, choiceNone, fileType, fileMask, defaultText) if key == "url" and len(str) < 1: return elif key == "logos" and str.startswith('http') and not str.endswith('/'): str += '/' chList[index][key] = str if common.SaveList(listFile, chList): xbmc.executebuiltin("Container.Refresh()")
def RemoveFromLists(iuuid, listFile): chList = common.ReadList(listFile) vDirsList = common.ReadList(vDirectoriesFile) i = 0 for playlist in chList: if playlist["uuid"] == iuuid: del chList[i] i += 1 # Removing from vdir lists. for vDir in vDirsList: i = 0 for uuid4 in vDir["data"]: if iuuid in uuid4: del vDir["data"][i] i += 1 common.SaveList(listFile, chList) common.SaveList(vDirectoriesFile, vDirsList) xbmc.executebuiltin("Container.Refresh()")
def m3uCategory(url, logos, cache, gListIndex=-1): meta = None tmpList = [] chList = common.m3u2list(url, cache) groupChannels = [] for channel in chList: if makeGroups: matches = [groupChannels.index(x) for x in groupChannels if len(x) > 0 and x[0].get("group_title", x[0]["display_name"]) == channel.get("group_title", channel["display_name"])] if makeGroups and len(matches) == 1: groupChannels[matches[0]].append(channel) else: groupChannels.append([channel]) for channels in groupChannels: idx = groupChannels.index(channels) if gListIndex > -1 and gListIndex != idx: continue isGroupChannel = gListIndex < 0 and len(channels) > 1 chs = [channels[0]] if isGroupChannel else channels for channel in chs: name = common.GetEncodeString(channel["display_name"]) if not isGroupChannel else common.GetEncodeString(channel.get("group_title", channel["display_name"])) plot = "" if meta is None else meta[channel["group_title"]]["overview"] if channel["group_title"] in meta else "" fanart = "" if meta is None else meta[channel["group_title"]]["fanarts"][0] if (channel["group_title"] in meta and len(meta[channel["group_title"]]["fanarts"]) > 0) else "" if isGroupChannel: name = '{0}'.format(name) chUrl = url try: image = channel['tvg_logo'] if meta is None else meta[channel["group_title"]]["poster"] if channel["group_title"] in meta else channel['tvg_logo'] except KeyError: image = "DefaultTVShows.png" AddDir(name, url, 10, index=idx, iconimage=image, plot=plot, fanart=fanart) else: chUrl = common.GetEncodeString(channel["url"]) image = channel.get("tvg_logo", channel.get("logo", "")) if logos is not None and logos != '' and image != "" and not image.startswith('http'): image = logos + image AddDir(name, chUrl, 3, image, index=-1, isFolder=False, IsPlayable=True, plot=plot, fanart=fanart) tmpList.append({"url": chUrl, "image": image, "name": name}) common.SaveList(tmpListFile, tmpList)
def MoveInFavourites(index, step): theList = common.ReadList(favoritesFile) if index + step >= len(theList) or index + step < 0: return if step == 0: step = GetIndexFromUser(len(theList), index) if step < 0: tempList = theList[0:index + step] + [theList[index]] + theList[index + step:index] + theList[index + 1:] elif step > 0: tempList = theList[0:index] + theList[index + 1:index + 1 + step] + [theList[index]] + theList[index + 1 + step:] else: return common.SaveList(favoritesFile, tempList) xbmc.executebuiltin("Container.Refresh()")
def AddNewFavorite(): chName = GetKeyboardText(getLocaleString(30014)) if len(chName) < 1: return chUrl = GetKeyboardText(getLocaleString(30015)) if len(chUrl) < 1: return image = GetChoice(30023, 30023, 30023, 30024, 30025, 30021, fileType=2) favList = common.ReadList(favoritesFile) for item in favList: if item["url"].lower() == chUrl.lower(): xbmc.executebuiltin("Notification({0}, '{1}' {2}, 5000, {3})".format(AddonName, chName, getLocaleString(30011), icon)) return data = {"url": chUrl, "image": image, "name": chName} favList.append(data) if common.SaveList(favoritesFile, favList): xbmc.executebuiltin("Container.Refresh()")
def AddFavorites(url, iconimage, name): # Checking if url already in list. favList = common.ReadList(favoritesFile) for item in favList: if item["url"].lower() == url.lower(): xbmc.executebuiltin("Notification({0}, '{1}' {2}, 5000, {3})".format(AddonName, name, getLocaleString(30011), icon)) return chList = common.ReadList(tmpListFile) for channel in chList: if channel["name"].lower() == name.lower(): url = channel["url"] iconimage = channel["image"] break if not iconimage: iconimage = "" data = {"url": url, "image": iconimage, "name": name} favList.append(data) common.SaveList(favoritesFile, favList) xbmc.executebuiltin("Notification({0}, '{1}' {2}, 5000, {3})".format(AddonName, name, getLocaleString(30012), icon))
def MoveInList(iuuid, step, listFile): def moveOnPlaylist(index, step, tList): tempList = None if index + step >= len(tList) or index + step < 0: return None if step == 0: step = GetIndexFromUser(len(tList), index) if step < 0: tempList = tList[0:index + step] + [ tList[index] ] + tList[index + step:index] + tList[index + 1:] elif step > 0: tempList = tList[0:index] + tList[index + 1:index + 1 + step] + [ tList[index] ] + tList[index + 1 + step:] else: return None return tempList theList = common.ReadList(listFile) # Checking that playlist is not in a directory. dir = False vdirs = common.ReadList(vDirectoriesFile) for vdir in vdirs: uuids4 = [uuid4 for uuid4 in vdir["data"]] if iuuid in uuids4: dir = vdir if not dir is False: # Moving two sides, directories and global list ( in case of directory removal ) dirFiles = lsDir(dir["uuid"]) ffiles = [tfile for tfile in theList if tfile["uuid"] in dirFiles] rfiles = [tfile for tfile in theList if tfile["uuid"] not in dirFiles] ffiles = moveOnPlaylist(dirFiles.index(iuuid), step, ffiles) if not ffiles is None: common.SaveList(listFile, rfiles + ffiles) # Movin it directory side. idx = vdirs.index(vdir) vdir["data"] = [item["uuid"] for item in ffiles] vdirs[idx] = vdir common.SaveList(vDirectoriesFile, vdirs) else: dirFiles = [item for data in vdirs for item in lsDir(data["uuid"])] dirItems = [ playlist for playlist in common.ReadList(listFile) if playlist["uuid"] in dirFiles ] notDirFiles = [ playlist for playlist in common.ReadList(listFile) if not playlist["uuid"] in dirFiles ] idx = 0 for playlist in notDirFiles: if playlist["uuid"] == iuuid: break idx += 1 ffiles = moveOnPlaylist(idx, step, notDirFiles) if not ffiles is None: common.SaveList(listFile, dirItems + ffiles) xbmc.executebuiltin("Container.Refresh()")
def m3uCategory(url, logos, epg, cache, mode, gListIndex=-1): meta = None tmpList = [] chList = common.m3u2list(url, cache) if (mode == 2 or mode == 10) and epg != None and epg != '': epgDict = common.epg2dict(epg, cache=720) dnow = datetime.now(tz.UTC) to_zone = tz.tzlocal() use_percent = 'true' use_time = 'true' else: epgDict = {} #xbmc.log('EPGDICT') #xbmc.log(str(epgDict)) groupChannels = [] for channel in chList: if makeGroups: matches = [groupChannels.index(x) for x in groupChannels if len(x) > 0 and x[0].get("group_title", x[0]["display_name"]) == channel.get("group_title", channel["display_name"])] if makeGroups and len(matches) == 1: groupChannels[matches[0]].append(channel) else: groupChannels.append([channel]) for channels in groupChannels: idx = groupChannels.index(channels) if gListIndex > -1 and gListIndex != idx: continue isGroupChannel = gListIndex < 0 and len(channels) > 1 chs = [channels[0]] if isGroupChannel else channels for channel in chs: name = common.GetEncodeString(channel["display_name"]) if not isGroupChannel else common.GetEncodeString(channel.get("group_title", channel["display_name"])) plot = "" if meta is None else meta[channel["group_title"]]["overview"] if channel["group_title"] in meta else "" fanart = "" if meta is None else meta[channel["group_title"]]["fanarts"][0] if (channel["group_title"] in meta and len(meta[channel["group_title"]]["fanarts"]) > 0) else "" if isGroupChannel: name = '{0}'.format(name) chUrl = url try: image = channel['tvg_logo'] if meta is None else meta[channel["group_title"]]["poster"] if channel["group_title"] in meta else channel['tvg_logo'] except KeyError: image = "DefaultTVShows.png" AddDir(name ,url, 10, epg=epg, index=idx, iconimage=image, cacheMin=cache, plot=plot, fanart=fanart) else: chUrl = common.GetEncodeString(channel["url"]) image = channel.get("tvg_logo", channel.get("logo", "")) if epgDict: idx = None id = None if epgDict.get(u'name'): if name in epgDict.get(u'name'): idx = epgDict[u'name'].index(name) if image == "" and idx is not None: image = epgDict[u'data'][idx][1] t2len = 0 title2nd = '' edescr = '' next = False if idx is not None: #xbmc.log(str( epgDict.get('prg').get(epgDict[u'data'][idx][0]))) if epgDict.get('prg').get(epgDict[u'data'][idx][0]): for start,stop,title in epgDict.get('prg').get(epgDict[u'data'][idx][0]): stime = parser.parse(start) etime = parser.parse(stop) if stime <= dnow <= etime or next: ebgn = stime.astimezone(to_zone).strftime('%H:%M') eend = etime.astimezone(to_zone).strftime('%H:%M') if use_time == 'true': stmp = '%s-%s' % (ebgn, eend) t2len += (len(stmp) + 1) if not next: title2nd += ' [COLOR FF00BB66]%s[/COLOR]' % stmp else: title2nd += ' %s' % stmp title2nd += ' %s' % title t2len += (len(title) + 1) title2nd = title2nd.replace('"','`').replace('&',' & ') if not t2len: t2len = len(name) if not next: plot += '[B][COLOR FF0084FF]%s-%s[/COLOR]\n[COLOR FFFFFFFF]%s[/COLOR][/B]' % (ebgn, eend, title) name = '[B]%s[/B]\n%s' % (name.ljust(int(t2len * 1.65)), title2nd) next = True else: plot += '\n\n[B][COLOR FF0084FF]%s-%s[/COLOR]\n%s[/B]' % (ebgn, eend, title) next = False break elif dnow < stime and not next: break if logos is not None and logos != '' and image != "" and not image.startswith('http'): image = logos + image AddDir(name, chUrl, 3, image, epg=epg, index=-1, isFolder=False, IsPlayable=True, plot=plot, fanart=fanart) tmpList.append({"url": chUrl, "image": image, "name": name}) common.SaveList(tmpListFile, tmpList)
icon = Addon.getAddonInfo('icon') addonDir = Addon.getAddonInfo('path') iconsDir = os.path.join(addonDir, "resources", "images") addon_data_dir = xbmcvfs.translatePath(Addon.getAddonInfo("profile")) cacheDir = os.path.join(addon_data_dir, "cache") if not os.path.exists(cacheDir): os.makedirs(cacheDir) playlistsFile = os.path.join(addon_data_dir, "playLists.txt") vDirectoriesFile = os.path.join(addon_data_dir, "virtual_directoriesLists.txt") tmpListFile = os.path.join(addon_data_dir, 'tempList.txt') favoritesFile = os.path.join(addon_data_dir, 'favorites.txt') if not (os.path.isfile(favoritesFile)): common.SaveList(favoritesFile, []) if not (os.path.isfile(vDirectoriesFile)): common.SaveList(vDirectoriesFile, []) makeGroups = Addon.getSetting("makeGroups") == "true" def getLocaleString(id): return Addon.getLocalizedString(id) def AddListItems(chList, addToVdir=True): cacheList = [] i = 0