Jump to content


Photo

PlaylistManager


  • Please log in to reply
5 replies to this topic

#1 rhodges OFFLINE  

rhodges

    Advanced Member

  • Members
  • 164 posts
  • Local time: 11:51 PM

Posted 12 March 2019 - 09:03 PM

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?



#2 Luke OFFLINE  

Luke

    System Architect

  • Administrators
  • 124094 posts
  • Local time: 12:51 AM

Posted 13 March 2019 - 02:01 PM

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.



#3 rhodges OFFLINE  

rhodges

    Advanced Member

  • Members
  • 164 posts
  • Local time: 11:51 PM

Posted 18 March 2019 - 02:49 PM

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, 18 March 2019 - 04:17 PM.


#4 Luke OFFLINE  

Luke

    System Architect

  • Administrators
  • 124094 posts
  • Local time: 12:51 AM

Posted 18 March 2019 - 05:15 PM

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



#5 rhodges OFFLINE  

rhodges

    Advanced Member

  • Members
  • 164 posts
  • Local time: 11:51 PM

Posted 19 March 2019 - 08:07 AM

        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, 19 March 2019 - 09:51 AM.


#6 Luke OFFLINE  

Luke

    System Architect

  • Administrators
  • 124094 posts
  • Local time: 12:51 AM

Posted 19 March 2019 - 11:17 AM

Glad you figured it out.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users