def RemoveFromLists(iuuid, listFile):
    # Removin the tv db and the movie db data first to ensure a clean file system.
    '''
    if common.isScannedByTheTvDB(index):
        common.removeTheTvDBData(index)
    
    if common.isScannedByTheMovieDB(index):
        common.removeTheMovieDBData(index)
    '''
    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("XBMC.Container.Refresh()")
def ChangeChoice(index,
                 listFile,
                 key,
                 choiceTitle,
                 fileTitle,
                 urlTitle,
                 choiceFile,
                 choiceUrl,
                 choiceNone=None,
                 fileType=1,
                 fileMask=None):
    list = common.ReadList(listFile)
    if key == "logos":
        listUrl = list[index].get("url", "")
        if listUrl.endswith('.plx'):
            return
    defaultText = list[index].get(key, "")
    str = GetChoice(choiceTitle, fileTitle, urlTitle, choiceFile,
                    choiceUrl, choiceNone, fileType, fileMask,
                    defaultText.encode("utf-8"))
    if key == "url" and len(str) < 1:
        return
    elif key == "logos" and str.startswith('http') and not str.endswith('/'):
        str += '/'
    list[index][key] = str.decode("utf-8")
    if common.SaveList(listFile, list):
        xbmc.executebuiltin("XBMC.Container.Refresh()")
def m3uCategory(url, logos, cache, gListIndex=-1):	
	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"]))
			if isGroupChannel:
				name = '[{0}]'.format(name)
				chUrl = url
				image = ''
				AddDir(name ,url, 10, index=idx)
			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)
			tmpList.append({"url": chUrl.decode("utf-8"), "image": image.decode("utf-8"), "name": name.decode("utf-8")})
	common.SaveList(tmpListFile, tmpList)
Beispiel #4
0
def AddNewList(method="url"):
    listName = GetKeyboardText("Playlist name").strip()
    if len(listName) < 1:
        return

    if method == "url":
        listUrl = GetKeyboardText("Playlist URL").strip()
    else:
        listUrl = xbmcgui.Dialog().browse(int(1), "Choose list", 'myprograms',
                                          '.plx|.m3u').decode("utf-8")
        if not listUrl:
            return

    if len(listUrl) < 1:
        return

    list = common.ReadList(playlistsFile)
    for item in list:
        if item["url"].lower() == listUrl.lower():
            xbmc.executebuiltin(
                'Notification(Playlist Loader, "{0}" already in playlists, 5000, {1})'
                .format(listName, icon))
            return
    list.append({"name": listName, "url": listUrl})
    if common.SaveList(playlistsFile, list):
        xbmc.executebuiltin(
            "XBMC.Container.Update('plugin://{0}')".format(AddonID))
def m3uCategory(url, logos):
    if isM3UDir(url):
        m3uDir(url, logos)
        return

    tmpList = []
    list = common.m3u2list(url)

    for channel in list:
        name = common.GetEncodeString(channel["display_name"])
        image = channel.get("tvg_logo", "")
        if image == "":
            image = channel.get("logo", "")
        if logos is not None and logos != '' and image is not None and image != '' and not image.startswith(
                'http'):
            image = logos + image
        url = common.GetEncodeString(channel["url"])
        AddDir(name, url, 3, image, isFolder=False)
        tmpList.append({
            "url": url.decode("utf-8"),
            "image": image.decode("utf-8"),
            "name": name.decode("utf-8")
        })

    common.SaveList(tmpListFile, tmpList)
Beispiel #6
0
def AddFavorites(url, iconimage, name):
    favList = common.ReadList(favoritesFile)
    for item in favList:
        if item["url"].lower() == url.lower():
            xbmc.executebuiltin(
                "Notification('Playlist Loader', '{0}' is already in favorites, 5000, {1})"
                .format(name, icon))
            return

    list = common.ReadList(tmpListFile)
    for channel in list:
        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('Playlist Loader', '{0}' added to favorites, 5000, {1})".
        format(name, icon))
Beispiel #7
0
def AddFavorites(url, iconimage, name, mode, file):
    file = os.path.join(addon_data_dir, file)
    favList = common.ReadList(file)
    for item in favList:
        if item["url"].lower() == url.decode("utf-8").lower():
            if "favorites" in file:
                xbmc.executebuiltin(
                    "Notification({0}, '{1}' {2}, 5000, {3})".format(
                        AddonName, name, getLocaleString(30011), icon))
            return
    chList = []
    for channel in chList:
        if channel["name"].lower() == name.decode("utf-8").lower():
            url = channel["url"].encode("utf-8")
            iconimage = channel["image"].encode("utf-8")
            break
    if not iconimage:
        iconimage = ""
    data = {
        "url": url.decode("utf-8"),
        "image": iconimage.decode("utf-8"),
        "name": name.decode("utf-8"),
        "mode": mode
    }
    favList.append(data)
    common.SaveList(file, favList)
    if "favorites" in file:
        xbmc.executebuiltin("Notification({0}, '{1}' {2}, 5000, {3})".format(
            AddonName, name, getLocaleString(30012), icon))
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=0)
    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"].encode("utf-8"), getLocaleString(30007), icon))
            return
    chList.append({"name": listName.decode("utf-8"), "url": listUrl, "image": image, "logos": logosUrl, "epg": epgUrl, "cache": cacheInMinutes, "uuid":str(random.uuid4())})
    if common.SaveList(playlistsFile, chList):
        xbmc.executebuiltin("XBMC.Container.Refresh()")
def AddNewFavorite():
    chName = GetKeyboardText(getLocaleString(10014))
    if len(chName) < 1:
        return
    chUrl = GetKeyboardText(getLocaleString(10015))
    if len(chUrl) < 1:
        return
    image = GetChoice(10023, 10023, 10023, 10024, 10025, 10021, fileType=2)

    favList = common.ReadList(favoritesFile)
    for item in favList:
        if item["url"].lower() == chUrl.decode("utf-8").lower():
            xbmc.executebuiltin(
                "Notification({0}, '{1}' {2}, 5000, {3})".format(
                    AddonName, chName, getLocaleString(10011), icon))
            return

    data = {
        "url": chUrl.decode("utf-8"),
        "image": image,
        "name": chName.decode("utf-8")
    }

    favList.append(data)
    if common.SaveList(favoritesFile, favList):
        xbmc.executebuiltin("XBMC.Container.Refresh()")
def AddFavorites(url, iconimage, name):
    favList = common.ReadList(favoritesFile)
    for item in favList:
        if item["url"].lower() == url.decode("utf-8").lower():
            xbmc.executebuiltin(
                "Notification({0}, '{1}' {2}, 5000, {3})".format(
                    AddonName, name, getLocaleString(10011), icon))
            return
    list = common.ReadList(tmpListFile)
    for channel in list:
        if channel["name"].lower() == name.decode("utf-8").lower():
            url = channel["url"].encode("utf-8")
            iconimage = channel["image"].encode("utf-8")
            break
    if not iconimage:
        iconimage = ""
    data = {
        "url": url.decode("utf-8"),
        "image": iconimage.decode("utf-8"),
        "name": name.decode("utf-8")
    }
    favList.append(data)
    common.SaveList(favoritesFile, favList)
    xbmc.executebuiltin("Notification({0}, '{1}' {2}, 5000, {3})".format(
        AddonName, name, getLocaleString(10012), icon))
def PlxCategory(url, cache):
    tmpList = []
    chList = common.plx2list(url, cache)
    background = chList[0]["background"]
    for channel in chList[1:]:
        iconimage = "" if not channel.has_key(
            "thumb") 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)
Beispiel #12
0
def AddNewFavortie():
    chName = GetKeyboardText("{0}".format(
        localizedString(10014).encode('utf-8'))).strip()
    if len(chName) < 1:
        return
    chUrl = GetKeyboardText("{0}".format(
        localizedString(10015).encode('utf-8'))).strip()
    if len(chUrl) < 1:
        return

    favList = common.ReadList(favoritesFile)
    for item in favList:
        if item["url"].lower() == url.lower():
            xbmc.executebuiltin(
                "Notification({0}, '{1}' {2}, 5000, {3})".format(
                    AddonName, chName,
                    localizedString(10011).encode('utf-8'), icon))
            return

    data = {"url": chUrl, "image": "", "name": chName.decode("utf-8")}

    favList.append(data)
    if common.SaveList(favoritesFile, favList):
        xbmc.executebuiltin(
            "XBMC.Container.Update('plugin://{0}?mode=30&url=favorites')".
            format(AddonID))
Beispiel #13
0
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, "")
    option = GetChoice(choiceTitle, fileTitle, urlTitle, choiceFile, choiceUrl,
                       choiceNone, fileType, fileMask, defaultText)
    if key == "url" and len(option) < 1:
        return
    elif key == "logos" and option.startswith(
            'http') and not option.endswith('/'):
        option += '/'
    chList[index][key] = option
    if common.SaveList(listFile, chList):
        xbmc.executebuiltin("Container.Refresh()")
def RemoveFromLists(index, listFile):
    list = common.ReadList(listFile)
    if index < 0 or index >= len(list):
        return
    del list[index]
    common.SaveList(listFile, list)
    xbmc.executebuiltin("XBMC.Container.Refresh()")
Beispiel #15
0
def AddNewList():
    keyboard = xbmc.Keyboard("", "Playlist name")
    keyboard.doModal()
    if keyboard.isConfirmed():
        listName = keyboard.getText()
    else:
        return

    keyboard = xbmc.Keyboard("", "Playlist URL")
    keyboard.doModal()
    if keyboard.isConfirmed():
        listUrl = keyboard.getText()
    else:
        return

    print "{0}. {1}".format(listName, listUrl)

    list = common.ReadList(playlistsFile)
    for item in list:
        if item["url"].lower() == listUrl.lower():
            xbmc.executebuiltin(
                'Notification(Playlist Loader, "{0}" already in playlists, 5000, {1})'
                .format(listName, icon))
            return
    list.append({"name": listName, "url": listUrl})
    if common.SaveList(playlistsFile, list):
        xbmc.executebuiltin(
            "XBMC.Container.Update('plugin://{0}')".format(AddonID))
Beispiel #16
0
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.encode("utf-8"))
    if key == "url" and len(str) < 1:
        return
    elif key == "logos" and str.startswith('http') and not str.endswith('/'):
        str += '/'
    chList[index][key] = str.decode("utf-8")
    if common.SaveList(listFile, chList):
        xbmc.executebuiltin("XBMC.Container.Refresh()")
Beispiel #17
0
def AddNewList():
	listName = GetKeyboardText(localizedString(10004).encode('utf-8')).strip()
	if len(listName) < 1:
		return

	method = GetSourceLocation(localizedString(10002).encode('utf-8'), [localizedString(10016).encode('utf-8'), localizedString(10017).encode('utf-8')])	
	#print method
	if method == -1:
		return
	elif method == 0:
		listUrl = GetKeyboardText(localizedString(10005).encode('utf-8')).strip()
	else:
		listUrl = xbmcgui.Dialog().browse(int(1), localizedString(10006).encode('utf-8'), 'myprograms','.plx|.m3u').decode("utf-8")
		if not listUrl:
			return
	
	if len(listUrl) < 1:
		return

	list = common.ReadList(playlistsFile)
	for item in list:
		if item["url"].lower() == listUrl.lower():
			xbmc.executebuiltin('Notification({0}, "{1}" {2}, 5000, {3})'.format(AddonName, listName, localizedString(10007).encode('utf-8'), icon))
			return
	list.append({"name": listName.decode("utf-8"), "url": listUrl})
	if common.SaveList(playlistsFile, list):
		xbmc.executebuiltin("XBMC.Container.Update('plugin://{0}')".format(AddonID))
def PlxCategory(url):
    tmpList = []
    list = common.plx2list(url)
    background = list[0]["background"]
    for channel in list[1:]:
        iconimage = "" if not channel.has_key(
            "thumb") else common.GetEncodeString(channel["thumb"])
        name = common.GetEncodeString(channel["name"])
        if channel["type"] == 'playlist':
            AddDir("[COLOR blue][{0}][/COLOR]".format(name),
                   channel["url"].encode("utf-8"),
                   1,
                   iconimage,
                   background=background.encode("utf-8"))
        else:
            AddDir(name,
                   channel["url"].encode("utf-8"),
                   3,
                   iconimage,
                   isFolder=False,
                   background=background)
            tmpList.append({
                "url": channel["url"],
                "image": iconimage.decode("utf-8"),
                "name": name.decode("utf-8")
            })

    common.SaveList(tmpListFile, tmpList)
Beispiel #19
0
def RemoveFromLists(url):
    list = common.ReadList(playlistsFile)
    for item in list:
        if item["url"].lower() == url.lower():
            list.remove(item)
            if common.SaveList(playlistsFile, list):
                xbmc.executebuiltin("XBMC.Container.Refresh()")
            break
def RemoveFromFavourites(index):

    favList = common.ReadList(favoritesFile)
    if index < 0 or index >= len(favList):
        return
    del favList[index]
    common.SaveList(favoritesFile, favList)
    xbmc.executebuiltin("XBMC.Container.Refresh()")
Beispiel #21
0
def RemoveFromLists(url):
	list = common.ReadList(playlistsFile)
	for item in list:
		if item["url"].lower() == url.lower():
			list.remove(item)
			if common.SaveList(playlistsFile, list):
				xbmc.executebuiltin("XBMC.Container.Update('plugin://{0}')".format(AddonID))
			break
def ChangeKey(index, listFile, key, title):
	list = common.ReadList(listFile)
	str = GetKeyboardText(getLocaleString(title), list[index][key].encode("utf-8"))
	if len(str) < 1:
		return
	list[index][key] = str.decode("utf-8")
	if common.SaveList(listFile, list):
		xbmc.executebuiltin("XBMC.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("XBMC.Container.Refresh()")
Beispiel #24
0
def RemoveFavorties(url):
    list = common.ReadList(favoritesFile)
    for channel in list:
        if channel["url"].lower() == url.lower():
            list.remove(channel)
            break

    common.SaveList(favoritesFile, list)
    xbmc.executebuiltin("XBMC.Container.Refresh()")
def ChangeCache(index, listFile):
	list = common.ReadList(listFile)
	defaultText = list[index].get('cache', 0)
	cacheInMinutes = GetNumFromUser(getLocaleString(10034), str(defaultText)) if list[index].get('url', '0').startswith('http') else 0
	if cacheInMinutes is None:
		return
	list[index]['cache'] = cacheInMinutes
	if common.SaveList(listFile, list):
		xbmc.executebuiltin("XBMC.Container.Refresh()")
Beispiel #26
0
def RemoveFavorties(url):
	list = common.ReadList(favoritesFile) 
	for channel in list:
		if channel["url"].lower() == url.lower():
			list.remove(channel)
			break
			
	common.SaveList(favoritesFile, list)
	xbmc.executebuiltin("XBMC.Container.Update('plugin://{0}?mode=30&url=favorites')".format(AddonID))
Beispiel #27
0
def m3uCategory(url):
    tmpList = []
    list = common.m3u2list(url)

    for channel in list:
        name = GetEncodeString(channel["display_name"])
        AddDir(name, channel["url"], 3, "", isFolder=False)
        tmpList.append({"url": channel["url"], "image": "", "name": name})

    common.SaveList(tmpListFile, tmpList)
def AddNewDirectory():
    dir_name = GetKeyboardText(getLocaleString(30040), "My new directory name").decode("utf-8")
    dir_icon = xbmcgui.Dialog().browse(1, getLocaleString(30042), 'files').decode("utf-8")
    
    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("XBMC.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("XBMC.Container.Refresh()")
        y += 1
def m3uCategory(url, logos, cache, gListIndex=-1): 
      
    meta = None
    '''
    meta_id = common.searchMetaTVDBId(url, playlistsFile)
    if not meta_id is None:
        if common.isScannedByTheTvDB(meta_id):
            meta = common.loadDataFromTheTvDB(meta_id)

    elif common.isScannedByTheMovieDB(gListIndex):
        meta = common.loadDataFromTheMovieDB(gListIndex)
    '''
    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.decode("utf-8"), "image": image.decode("utf-8"), "name": name.decode("utf-8")})
    
    common.SaveList(tmpListFile, tmpList)