Creating an internet radio plug in

Have some questions and issues
Hey all,

To get my feet wet in creating plug ins for Plex, I decided to start with a simple streaming radio one. I've got the basics down at the moment (Add and delete 'stations', show listing, read stations from RSS feed) but have come across a few snags.

Firstly, just wondering what the procedure is for making changes in the Framework python scripts - as to get where I am I needed to add a couple of functions to the Dict.py class to allow me to retrieve a list of keys and removal of keys. For the removal of keys I thought it best to follow the standard set by the Set function :)

Dict.py changes

<br />
####################################################################################################<br />
<br />
def Keys():<br />
  global __dict<br />
  return __dict.keys()<br />
  <br />
####################################################################################################<br />
<br />
def Delete(key, addToLog=True):<br />
  global __dict<br />
  global __saveScheduled<br />
  Thread.Lock("Framework.Dict", addToLog=False)<br />
  del __dict[key]<br />
  if not __saveScheduled:<br />
    Thread.CreateTimer(5, __save, addToLog=addToLog)<br />
    __saveScheduled = True<br />
  Thread.Unlock("Framework.Dict", addToLog=False)<br />
  <br />
####################################################################################################<br />




[s]Onto the problems I've come across. The first is probably something simple, but I can't seem to find a solution anywhere.
What I'm wanting to do is refresh/reload the current container when an item is selected for deletion. Is this currently possible?[/s]

*EDIT: Found the answer, mental note to use different keywords ([link](http://forums.plexapp.com/index.php/topic/12359-reloading-a-menu/))*

The next question is in regards to the context menu - but I think an earlier thread I read this morning might have answered it for me. I cannot add/change this can I? As it would be better to have the add/delete/edit station commands here imo than where I have them now

And finally, I'm getting some strange behavior with the icon for my plug in. It was fine after I made the first change, but now it is stuck with the old icon no matter how much I change it. And it I change the name of the file the icon disappears completely :S Is there some sort of icon cache I need to clear in order to see the correct, latest icon?

Thanks for the help :D

Hi,



About Dict: I could have sworn James changed the Dict implementation in v2 to have all the usual pyton dict methods. Are you using v2, and have you just tried the python dict methods on the Dict object?



Context menus: yes, you can add to them (and replace). The Daily Show uses context menus for changing sort order. I’m sure there’s other examples, but that’s the one sticking in my mind.



Icon cache is indeed a yes. I’m not at my Mac right now so don’t know the full path but it’s somewhere under Library/Application Support/Plex if I remember right.



Jonny

Thanks for the quick reply



I think I’m running on version 1. I started with the plug in kickstarter and do remember something about Framework 1.0. Will change over to 2.0 once I’m in front of my mac again too (currently at work :))



And thanks for the lead with the Daily show. Will look to see what they do as it just doesn’t flow right to me at the moment. I currently add the streams as TrackItems so they can play with a single click

OK - quick update on how I’m going with this:



[list]

[]By using the noCache=True argument on the MediaContainer constructor I can now delete items from the list

[
]I tried updating the framework to v2 and got a lot of strange behaviour. when it was working fine I could not call the python dict methods on the Dict class, but I think I have a better idea how to tackle this problem

[]Icon has been put on the back shelf for now, and I’ll deal with this once the main part of the plugin is running as it should

[
]I started to add the edit/add station container and got an error about ‘cerealizer.register()’ and my custom class RadioStation not able to get ‘cerealized’. Upon further investigation this is a problem in the framework at the moment for arguments?

[/list]



Other than that - as far as progress before an initial release - I just need to figure a way to be able to edit a station’s information. My current thought is do push a new media container with InputDirectoryItems to catch the inputs for the station name and URL, and somehow pass them back. Current function looks something like this:


<br />
def EditStation(sender station=None):<br />
  # If we have no station then we're probably adding a new one<br />
  if station == None:<br />
    station = RadioStation()<br />
    <br />
  # Now to fill with editing values<br />
  dir = MediaContainer(viewGroup="InfoList", noCache=True)<br />
  <br />
  dir.Append(Function(InputDirectoryItem(EditText, 'Edit Station Stream URL', "Enter Stream URL", summary='Edit where the station\'s URL stream is'), output=station.url))<br />
  dir.Append(Function(InputDirectoryItem(EditText, 'Edit Station Name', "Enter Station Name", summary='Edit the station\'s name'), output=station.name))<br />
  <br />
  return dir<br />
<br />
def EditText(sender, query=None, output=None):<br />
  return MessageContainer(<br />
        "Not implemented",<br />
        "In real life, you'll make more than one callback,
and you'll do something useful."<br />
    )<br />




EDIT: Some more searching - for the cerealizer errors, do I just need to register the class with cerealizer.register(RadioStation)? It's not a very complex class, more like a structure :)

It would be great to have a plug-in for radio stations… I have a heap of stations that i would like to add that are not a part of shoutcast



Ditto, big kudos to anyone who builds this :)