I'm running into an awkward issue with objects displaying out of their assigned order. Basically what's happening is that when I add a bunch of objects to the container, the results seem to be placing all of my VideoClipObjects to the top of the list, while the DirectoryObjects are at the bottom of the list; instead of in their correct blended position. At this menu level, the container may contain a VideoClipObject or a DirectoryObject (for either a playlist or error message). Although the index numbers are assigned correctly, the actual display order seems to put all DirectoryObjects to the bottom (kind of how windows filters folders to the top of a file list) and it is driving me crazy!!
I've check all logic and all assignments are made during the loop so I do not understand how this is happening unless Plex is re-ordering it on it's own based on the type of object. If this is to be expected, can I stop it? It's completely destroying my alphabetical order and the only other workaround would be to add an extra level for video clips to keep them all as DirectoryObjects and retain the order. That said, this would cause unnecessary extra clicks for the user to do that so I'd like to keep that as a last resort.
Below is an example of the code, as you can see it all falls under the for loop so the order should be retained automatically (note that I have removed some unrelated code to keep it simple. If this issue is self generated, then it would have to be within the try/except clauses and not within random string definitions).
Sample Code:
for i, key in enumerate(keys):
i = i+1
item = {"title": "%s. " % (i), "thumb_url": ICON, "summary": "",
"ratings": "0.0", "votes": "0", "url": "", "genre": ""}
try:
#(...variable definitions go here...)
if "youtube" in item["url"]:
if y_id[1] == TYPE_PLAYLIST:
oc.add(DirectoryObject(
key = Callback(PlaylistMenu, pl_id=y_id[0], heading=genre, url=item["url"], page=1, items=items["data"]),
title = item["title"],
thumb = Resource.ContentsOfURLWithFallback(url=item["thumb_url"], fallback=ICON),
summary = item["summary"],
))
else:
if "status" in url:
raise Ex.MediaNotAvailable
else:
oc.add(VideoClipObject(
url = "http://www.youtube.com/watch?v=%s" % (y_id[0]),
title = item["title"],
summary = item["summary"],
thumb = Resource.ContentsOfURLWithFallback(url=item["thumb_url"], fallback=ICON)
))
elif URLService.ServiceIdentifierForURL(item["url"]):
oc.add(VideoClipObject(
url = item["url"],
title = item["title"],
summary = item["summary"],
thumb = Resource.ContentsOfURLWithFallback(url=item["thumb_url"], fallback=ICON)
))
else:
raise Ex.MediaNotAvailable
except Ex.HTTPError, error:
Log(str(error.code))
Log(i)
if error.code == 403:
Log("MediaNotAuthorized2")
head_msg = ("MediaNotAuthorized Error", "The selected media has been made unavailable by the author")
elif error.code == 404:
Log("MediaNotAvailable3")
head_msg = ("MediaNotAvailable Error", "The selected media has been removed by the author.")
oc.add(DirectoryObject(
key = Callback(ErrorMessage, header=head_msg[0], message=head_msg[1]),
title = item["title"],
thumb = Resource.ContentsOfURLWithFallback(url=item["thumb_url"], fallback=ICON),
summary = item["summary"],
))
except:
Log("MediaNotAvailable4")
Log(format_exc())
Log("")
Log("")
oc.add(DirectoryObject(
key = Callback(ErrorMessage, header="MediaNotAvailable Error", message="The selected media is unavailable."),
title = item["title"],
thumb = Resource.ContentsOfURLWithFallback(url=item["thumb_url"], fallback=ICON),
summary = item["summary"],
))
Screenshots of the issue:
(If you pay close attention to "order2.png" you will see that although they are out of order, their index numbers are correct which implies the loop did it job fine and something else is taking over. I can also verify that it is ONLY DirectoryObjects being moved around, all VideoClipObject's are in proper order)
Any thoughts?