Any way to populate these fields?

I’ve been putting the finishing touches on a Firefly Media Server plugin and I’ve come across (what I believe to be) something missing.



Here’s a picture of the Plex Music Library (in Album view):



Notice how the Artist is listed below the Album name?

Here's a picture of my plugin (in Album view):



I can't for the life of me figure out a way to populate that Artist field. Looking at the definition structure for DirectoryItem() lends me to believe that's it's just not possible. Am I right, or just missing something? If it's just an omission, would it be possible to get that hook location added in an update (and hopefully one for the ALBUM YEAR field in Songs view).

I have to admit, coming from never having done much in Python (although, I am a programmer by trade), I've found the Plex plugin system pretty easy to stumble through. Great job guys!

You could try setting the album and artist after creating the object. ie



item = DirectoryItem(…)



item.artist = “…”

item.album = “…”



This works for me to add a ‘summary’ to a TrackItem which doesn’t have an explicit summary option. Since all of them just subclass XMLObject hopefully it’ll work just fine, I’ve not tested it though.



Yea, I had hoped it would be that easy. Unfortunately, I tried that earlier.. and it's not. I did some digging around the XML output on port 32400 and saw that the iTunes plugin uses it's own XML output -- like an AlbumItem(). I tried to emulate it to no avail. I can define whatever arguments I want, as they get passed through as **kwargs to the XMLObject class anyway -- and they do show up in the XML output. They're just ignored.

I had hoped I was making headway, but I’m not quite there yet.



What I did was kind of traceback the DirectoryItem() class in Objects.py which led me to PlexDirectory.cpp. I looked at the PlexMediaDirectory class to see how DirectoryItem() was passing data. So, I figured I could create an AlbumItem() wrapper in Objects.py to pass data to the PlexMediaAlbum class in PlexDirectory.cpp:



class AlbumItem(XMLObject):<br />
  def __init__(self, key, label, album=None, artist=None, genre=None, year=None, **kwargs):<br />
	XMLObject.__init__(self, key=key, label=label, album=album, artist=artist, genre=genre, year=year, **kwargs)<br />
	self.tagName = "Album"



I'm calling AlbumItem() in place of DirectoryItem() where I need it in my plugin:


				dir.Append(Function(AlbumItem(GetXML, label="Label", album="Album", artist="Artist", genre="Genre", year="2005"), type="Songs", url="/rsp/db/1?type=browse&query=(artist%3D%22" + q_artist + "%22)%20and%20(album%3D%22" + q_album + "%22)"))



When I check the XML output via port 32400, everything looks fine:

<MediaContainer viewGroup="Albums" noHistory="0" content="Albums" title1="Firefly Media Server" title2="Albums" replaceParent="0" count="4" viewmode="131123" contenttype="items"><br />
  <Album album="Album" key="/music/firefly/:/function/GetXML/KGRwMApTJ3VybCcKcDEKUycvcnNwL2RiLzE@dHlwZT1icm93c2UmcXVlcnk9KGFydGlzdCUzRCUyMkEl<br />
MjBQZXJmZWN0JTIwQ2lyY2xlJTIyKSUyMGFuZCUyMChhbGJ1bSUzRCUyMk1lciUyMGRlJTIwTm9tcyUy<br />
M<br />
iknCnAyCnNTJ3R5cGUnCnAzClMnU29uZ3MnCnA0CnNTJ3NlbmRlcicKcDUKKGlQTVMuT2JqZWN0cwpJd<br />
G<br />
VtSW5mb1JlY29yZApwNgooZHA3ClMnaXRlbVRpdGxlJwpwOApOc1MndGl0bGUxJwpwOQpTJ0ZpcmVmbH<br />
k<br />
gTWVkaWEgU2VydmVyJwpwMTAKc1MndGl0bGUyJwpwMTEKUydBbGJ1bXMnCnAxMgpzUydhcnQnCnAxMwp<br />
O<br />
c2JzLg==" artist="Artist" label="Label" year="2005" genre="Genre"/><br />
</MediaContainer>



However, when I try it via the Plex UI, nothing happens. I see no errors in the log for my plugin, however, there is an error tossed up in plex.log:


So this is where I'm at.. I get the feeling I'm on the right track, but I'm missing something mundane. Any help would be greatly appreciated!

Ok, I figured it out… it was staring at me the whole time.



In PlexDirectory.cpp:


class PlexMediaAlbum : public PlexMediaNode<br />
{<br />
  virtual void DoBuildFileItem(CFileItemPtr& pItem, const string& parentPath, TiXmlElement& el) <br />
  {<br />
	CAlbum album;<br />
	<br />
	album.strLabel = GetLabel(el);<br />
	album.idAlbum = boost::lexical_cast<int>(el.Attribute("key"));<br />
	album.strAlbum = el.Attribute("album");<br />
	album.strArtist = el.Attribute("artist");<br />
	album.strGenre = el.Attribute("genre");<br />
	album.iYear = boost::lexical_cast<int>(el.Attribute("year"));<br />
		<br />
	CFileItemPtr newItem(new CFileItem(pItem->m_strPath, album));<br />
	pItem = newItem;<br />
  }<br />
};



I overlooked it before; apparently *key* is expected to be an integer, thus setting it as the function output like I do on DirectoryItem() doesn't work. So, apparently, it looks like I can't use a wrapper for PlexMediaAlbum() (at least not yet *hint, hint*)

Ah, thanks for tracking this down. I’ll fix for the next version!



Awesome, thanks! If it wouldn't be too much to ask, would it be possible to have PlexMediaAlbum display like the Library view?
In Library view:
Album
Artist

With PlexMediaAlbum():
Album
Year

Forcing me to append the artist to the album:
Artist - Album
Year

Ideally, it would be awesome to display the year in the same field as "duration" -- justified off to the right and vertically centered, like in PlexMediaTrack() so it would look like:
Album __________ Year
Artist

It's not critical, just inconsistent -- but if it would break things to change/fix it (such as iTunes), I understand.

You can do some of that right now, with some undocumented stuff :slight_smile:



dir = MediaContainer(filelabel='%T')



You can specify filelabel (for files) and dirlabel (for directories) attributes here, that correspond to to the XBMC labels. We'll be adding more support for this sort of thing (and more control of the area to the right) as time goes on.


 *  %N - Track Number<br />
 *  %S - Disc Number<br />
 *  %A - Artist<br />
 *  %T - Title<br />
 *  %B - Album<br />
 *  %G - Genre<br />
 *  %Y - Year<br />
 *  %F - FileName<br />
 *  %L - existing Label<br />
 *  %D - Duration<br />
 *  %I - Size<br />
 *  %J - Date<br />
 *  %R - Movie rating<br />
 *  %C - Programs count<br />
 *  %K - Movie/Game title<br />
 *  %M - number of episodes<br />
 *  %E - episode number<br />
 *  %P - production code<br />
 *  %H - season*100+episode<br />
 *  %Z - tvshow title<br />
 *  %O - mpaa rating<br />
 *  %Q - file time<br />
 *  %U - studio

Frickin’ sweet! Thanks elan!



Hrm.. call me a bit thick, but I can't seem to get these labels to work -- let alone do anything. When defining them, they simply show up as XML tags (ie. dirlabel="%N") and have no effect on the formatting. Am I missing something?


	dir = MediaContainer(title2=type, viewGroup=type, filelabel="%N", dirlabel="%T")

Hmm… is this only available for a non-DirectoryItem() perhaps? I’ve tried every which way and still can’t get those tags to work…

Sorry for not replying sooner!



Adam Carolla, Boing Boing, and NPR use those labels, and they use them with MediaContainers. In other words, they’re set on the container and then apply to all the items.



Hope that helps :slight_smile:



Yea, I checked those out and saw they were using filelabel (none are using dirlabel) -- and I can't for the life of me see where it does anything at all. Either way, it's not important.. I'll hold out for the fixed AlbumItem() in the next Plex release.


Unless I'm on crack, those filelabel specifiers make it display the duration of each item on the right hand side.

In any event, I will fix that AlbumItem issue for the next release for sure :)


I'm not using the filelabel specifiers, and I see durations in my plugin just fine. Plus, in those apps they have filelabel set to '%T' which is Title, not duration. I thought the same thing too, originally... but after digging, I'm still convinced they're not doing anything. :)


See, I knew I was on crack!

You're right, what I use them for is so that only the Title is displayed, and not the default Artist - Title. It made a nice difference in NPR and Adam Carolla.

Drats. This doesn’t appear to have been fixed in 0.8.2. idAlbum is still explicity defined as an integer. :frowning:



Unless I'm missing something?

It may be defined as an integer in the Plex source in some places (otherwise it'd break the legacy XBMC code), but albums returned from Plex plug-ins can use any string you like.


Currently there is no AlbumItem() wrapper in the Python framework so albums have to be returned as a DirectoryItem(). I tried to create an AlbumItem() wrapper for PlexMediaAlbum as documented in the first post, except the key value is explicitly defined as an integer. This is not the case for ArtistItem or DirectoryItem. Elan seemed to agree with this assessment, and as stated in the 0.8.2 changelog, it had been fixed.

So, unless I'm missing something.. there's still no way to return a TRUE AlbumItem via a Plugin. It's entirely possibly that there may be a new function with a wrapper in the 'soon-to-be-released' framework update that I haven't caught yet, but I have no way of knowing that. :)

Anyone?