Object Sorting, Storing Settings and Metadata

Hi All,

 

Im working on some plugins for OZ Catch up TV among others and I have the need to sort a list of directory object by title see below code....

 

@route('/video/aubci/series/{category}')

def GetSeriesByCaegory(category):
 
cat = iView_Category(category)
 
oc = ObjectContainer(view_group='List', title2 = cat.title)
 
series = cat.series_list
 
for item in series:
 
oc.add(DirectoryObject(
key = Callback(GetEpisodesBySeries, series=item[0]),
title = item[1]
))
 
return oc

 

This works fine, however the DirectoryObjects are all out of order and not sort alphabetically, is there an easy way to sort these items? I have tried a few different thing I found on the forums here but none seem to work, I think they are for older versions of PMS

 

Also im building another plugin that I need to be able to save settings for (e.g. favourite sites ect ect) is there anyway to save a setting so that it can be stored and used again after the server has been restarted?

 

 

And one last thing, im looking to have this plugin display MetaData about a specific Movie or TVShow all it needs is  title, summary and a banner. This page just needs a simple button or item that will allow the user to add this show/movie as a favourite (see above) what is the best object type to do this?

 

Im only starting out with channel developing for Plex so im pretty new to this, and I have been searching for a while now with no luck...

 

Thanks :D

 

 

Sorting Lists

The trick is to sort the list before adding them to the object container. The Python docs are a brilliant place to start, take a look at http://wiki.python.org/moin/HowTo/Sorting/. I imagine something like the following is what you are after:

series = sorted(series, key=lambda item: item[1])

Take a look at the Plex Framework documentation, it's certainly worth a read and has all of the information you are after. 

Setting and accessing preferences

Create a DefaultPrefs.json file in the Contents directory.

Add the default preferences as a a JSON array, see Page 85 of the docs.

In the main menu of your application create the following object to allow the user to access it, Plex will take care of updating the user preferences.

oc.add(PrefsObject(title = "Preferences"))

And you can access the preferences in the python code via

x = Prefs[id]

Setting metadata

I'll simply point you to the docs again, Page 54

In particular you want to set the following arguments:

title
  A string specifying the movie’s title.
summary
  A string specifying the movie’s summary.
thumb
  A string specifying an image resource to use as the movie’s thumbnail.
art
  A string specifying an image resource to use as the movie’s background art.

Sorting before adding to the Object Container works well but, may not always be the best approach. It is possible to sort the contents of a Object Container by title (or pretty much any of the attributes). Like so,


oc.objects.sort(key = lambda obj: obj.title)



The last bit “obj.title” can be changed to sort based on other attributes such as obj.duration, obj.originally_available_at, obj, etc. You can also add the “reverse=True” argument if you want the list in the reverse order.

Hi All

Thanks again for the quick response!

The sorting work great! I used Mikedm139's method, but im sure the other way would have worked just fine.

I havent tried writing preferences yet, but after reading the doc'o this should be what im after.

I also found http://dev.plexapp.com/docs/api/datakit.html?highlight=dict#Dict in the doco which looks like it will do what I need as well.

As far as the MetaData goes, you might have misunderstood the question...

I need to retrieve metadata, say from TheTVDB.com or IMDB.com and display it within the plugin, I can see there are already agents for this within Plex im just not sure how to access them from within my plugin

Thanks!!!!

Sorting before adding to the Object Container works well but, may not always be the best approach. It is possible to sort the contents of a Object Container by title (or pretty much any of the attributes). Like so,
 

oc.objects.sort(key = lambda obj: obj.title)

The last bit "obj.title" can be changed to sort based on other attributes such as obj.duration, obj.originally_available_at, obj, etc. You can also add the "reverse=True" argument if you want the list in the reverse order.

The sort command seems like a good one to know and use. Just one question, where would you put the line above within your code? You say that with this approach, you would not be sorting before adding to the object container. So would you place this command outside of any loop you are using to pull data and place it between the oc.add() and the return oc commands?

need to retrieve metadata, say from TheTVDB.com or IMDB.com and display it within the plugin, I can see there are already agents for this within Plex im just not sure how to access them from within my plugin.

Metadata from agents is not exposed for use by channel plugins. It *might* be possible to hack some sort of workaround but it would definitely be unsupported and liable to break at any time.

So would you place this command outside of any loop you are using to pull data and place it between the oc.add() and the return oc commands?

That's right. You can see it used in the CBC channel code here: https://github.com/plexinc-plugins/CBC.bundle/blob/master/Contents/Code/__init__.py#L106

Thanks everyone for you help! I managed to get the sorting and adding items to favourites working and im just using the TVDB and IMDB api's to pull the data i need for banners ect ect

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.