I'm in need of a menu item that basically re-downloads an xml list of channels.
How should I go about doing that.
At present, I'm reusing a function that already exists, as it's used to pull the channel list initially. However when I put it in as a callback in the key value of a directory object, it chokes on a 'referenced before assignment' error when i try to use the passed variable SERVER.
The Menu function:
def UpdateChannelLists(TITLE):
# Open an Object Container for the update channel lists menu
UPDATE_CHANNELS_MENU = ObjectContainer(
title1 = TITLE
)
# Add option to update main server channel list
UPDATE_CHANNELS_MENU.add(
DirectoryObject(
title = "Main Server Channel List",
thumb = R(ICON),
summary = "Updates the channel list for the main server",
key = Callback(
GetChannelListXML,
SERVER = "Main"
)
)
)
# Add option to update BT server channel list
UPDATE_CHANNELS_MENU.add(
DirectoryObject(
title = "BT Server Channel List",
thumb = R("BT.png"),
summary = "Updates the channel list for the BT server",
key = Callback(
GetChannelListXML,
SERVER = "BT"
)
)
)
return UPDATE_CHANNELS_MENU
The GetChannelListXML function:
def GetChannelListXML(SERVER):
# Deletes any existing channel lists
Data.Remove(XML_PREFIX + SERVER + XML_SUFFIX)
# Construct CHANNEL_LIST_URL based on SERVER variable
if SERVER is "Main":
CHANNEL_LIST_URL = URL_BASE + URL_MEMBERS_AREA + URL_CHANNEL_LIST_MAIN
elif SERVER is "BT":
CHANNEL_LIST_URL = URL_BASE + URL_MEMBERS_AREA + URL_CHANNEL_LIST_BT
# Grab the XML file
CHANNEL_LIST_SOURCE = HTTP.Request(CHANNEL_LIST_URL).content
# Save the data as an XML file based on value of SERVER variable
Data.Save(XML_PREFIX + SERVER + XML_SUFFIX,CHANNEL_LIST_SOURCE)
# Gets the alert to show the user
ALERT = SuccessChannelList(SERVER)
return ALERT
The error I get when I click either of the two menu items:
2014-08-25 18:12:07,621 (111c01000) : CRITICAL (sandbox:303) - Exception when calling function 'GetChannelListXML' (most recent call last):
File "/Users/loz/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/code/sandbox.py", line 294, in call_named_function
result = f(*args, **kwargs)
File "/Users/loz/Library/Application Support/Plex Media Server/Plug-ins/PremierAdLive.bundle/Contents/Code/__init__.py", line 190, in GetChannelListXML
CHANNEL_LIST_SOURCE = HTTP.Request(CHANNEL_LIST_URL).content
UnboundLocalError: local variable 'CHANNEL_LIST_URL' referenced before assignment
So, it's skipping the if/elif statement at the top of the GetChannelListXML function, but I don't know why – I'm passing in correct values so there should be a match.