Jump to content

PlaylistManager


rhodges

Recommended Posts

rhodges

I'm writing a personal server plugin and I'm trying to figure out how to create/update a playlist.

 

I want one playlist that is used by everyone. I am injecting

ILibraryManager libraryManager, IPlaylistManager playlistManager

 

into my plugin, but the methods seem very limited.

 

I can create, but I don't see how to fetch for a user. Also, I don't want to create multiple ones, just a single one if it doesn't exist and then all the users to the "shares" of it.

 

Is this not possible?

Link to comment
Share on other sites

You can play with the Shares property on the playlist, but the rule of thumb is that if you can't do it in the web UI, then it's probably not going to work just yet.

Link to comment
Share on other sites

rhodges

You can play with the Shares property on the playlist, but the rule of thumb is that if you can't do it in the web UI, then it's probably not going to work just yet.

If I have an instance of Playlist, what is the appropriate method to write changes back since it has to update the xml file and I guess that database as well?

 

Edit: I think I have it figured out. playlist.UpdateToRepository(ItemUpdateType.MetadataEdit);

 

Edit 2: Well, I can't seem to delete items from a playlist with the server api. Looking at the web api and some old source for Emby, it looks like it isn't the Internal Id, but the EntryId that I don't have using the server api (plugin).

 

I kinda hoped IPlaylistManager would be a little more robust. It has no method for checking for a playlist by name, or getting a playlist by name, or removing items by item id, etc, etc. :(

Edited by rhodges
Link to comment
Share on other sites

Sure you can find a playlist by name, that is using the regular querying methods along with specifying IncludeItemTypes Playlist.

Link to comment
Share on other sites

rhodges
        public static Playlist GetPlaylistByName(ILibraryManager libraryManager, IPlaylistManager playlistManager, string name, User user)
        {
            var playlistFolder = playlistManager.GetPlaylistsFolder(user.InternalId);
            var playlists = playlistFolder.Children.OfType<Playlist>();

            return playlists.Where(p => name.Equals(p.Name, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
        }

I did this, which seems to work. Not sure if that is the "correct" way. Of course, since playlists seem to be "shared" not sure why I need a userid.

 

My biggest hurdle is how to clear the playlist. What I'm trying to do is create a dynamic (sort of, updated by a task) playlist that contains movies that have Chinese subtitles. I can use a query like above, I can create a new playlist, and I can even add Shares to it

                playlist.Shares = _userManager.Users.Select(u => new Share {
                    UserId = u.InternalId.ToString(),
                    CanEdit = u.InternalId == listUser.InternalId
                }).ToArray();

                playlist.UpdateToRepository(ItemUpdateType.MetadataEdit);

How can I remove items from it? _playlistManager.RemoveFromPlaylist wants an EntryID (void RemoveFromPlaylist(long playlistId, long[] entryIds) ;) which seems like it is some sort of session/user specific value. I see that the REST api has PlaylistItemId but the "server" api doesn't really have a good method for pulling playlist items in a way that works well with other playlistmanager methods.

 

I guess I'll look into using the REST api inside the server plugin...

 

Edit: Closing the source has made a lot of this work harder. Before I could go look at how it was implemented to get ideas on how to solve issues myself.

 

Edit 2: I figured it out. I was looking past the property ListItemEntryId.

 

This will effectively "clear" a playlist...(at least for me since manipulation of the list is always done as a specific user). 

_playlistManager.RemoveFromPlaylist(playlist.InternalId, playlist.GetChildren(listUser).Select(c => c.ListItemEntryId).ToArray());

Overall, a bit clunky, but I think workable.

 

Leaving this all here in case someone else is looking for similar information.

Edited by rhodges
  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...