Jump to content

Get list of Library Names and Ids with Plugins


Recommended Posts

Posted (edited)

I can't believe I'm asking this... I should know this already but stumped....

 

I'm finding it hard to find how to get a list top tier library names and Ids. ex. "Movies" "TV Series", "Collections" etc.

 

I can see it in the LibraryService in the Swagger, but unsure what to request in the core plugin module.

 

I think it is ILibraryManager, but then I'm stuck.

Edited by chef
Posted (edited)

Might be GetVirtualFolders

 

EDIT: Yep! something like this... geesh!

public string GetMovieLibraryId()
        {

            var results = LibraryManager.GetVirtualFolders();
            foreach(var item in results)
            {
                if(item.Name == "Movies")
                {
                    return item.ItemId;
                }
            }
            return string.Empty;
        }
Edited by chef
  • 3 weeks later...
pünktchen
Posted

Any idea how to get those library names as a checkbox list within a plugin configuration page and then return their ids as a string list to the plugin?

Posted

Doesn't the trakt plugin config screen have something similar?

pünktchen
Posted

Doesn't the trakt plugin config screen have something similar?

Thanks! Not exactly what i've asked but a good starting point.

  • 3 years later...
bakes82
Posted

@pünktchen Do you have example of this on github some place?  I need show a list of libraries on the config page too, and dont want to reinvent the wheel.

pünktchen
Posted

No, not publicy visible. I'll paste some code here later.

Posted
49 minutes ago, bakes82 said:

@pünktchen Do you have example of this on github some place?  I need show a list of libraries on the config page too, and dont want to reinvent the wheel.

Not sure how close it is to what you're looking for, but here's how I generate the library dropdown in Iconic:
 

define(
    async function ()
    {
        return {
            displayLibrarySelector: async function(librarySelectorElement) {
                const libraries = await getLibraries();
                let availableLibraries = [];
                Object.keys(libraries.Items).forEach(function(key) {
                    let library = libraries.Items[key];
                    if (library.CollectionType == 'movies' || library.CollectionType == 'boxsets'|| library.CollectionType == 'tvshows') {
                        availableLibraries.push(library);
                    }
                });
        
                let librarySelectHtml = '<select id="librarySelector" class="library-selector" name="librarySelector" label="Select a Library" is="emby-select">';
                availableLibraries.forEach(function (library) {
                    librarySelectHtml += '<option data-type="'+library.CollectionType+'" value="'+library.Id+'">'+library.Name+'</option>';
                });
                librarySelectHtml += '</select>';
                librarySelectorElement.innerHTML = librarySelectHtml;
            
            }
        }

        async function getLibraries() {
            return ApiClient.getVirtualFolders();
        };
});

This is loaded as a separate module by my main javascript file, but you can skip that and just grab the guts if they fit your needs.

  • Like 1

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...