mickle026 404 Posted December 20, 2021 Share Posted December 20, 2021 I get the albums like this var AllAlbum = libraryManager.GetInternalItemIds(new InternalItemsQuery { IncludeItemTypes = new[] { "MusicAlbum" } }); Then iterate through the albums churning out the tracks foreach (var SingleAlbum in AllAlbum) { var mAlbum = libraryManager.GetItemById(SingleAlbum); var AlbumName = mAlbum.Name.Replace(" ,", " ").Trim(); var Tracklist = libraryManager.GetItemIds(new InternalItemsQuery { AlbumIds = new[] { SingleAlbum } }); foreach (var Entry in Tracklist) { var trackid = libraryManager.GetItemById(Entry).InternalId; var TrackName = libraryManager.GetItemById(Entry).Name; but how to get the artist of a track ? I can get all the artists on the album but not for the track by itself. var TrackArtists = libraryManager.GetAllArtists(mAlbum); or var TrackArtists = libraryManager.GetArtists(mAlbum); to avoid the album artist However this array is not in the same order. ie Tracklist[0] and TrackArtists[0] do not correspond with each other, they are in a different order I have all the tracks and all the artists but they dont match up, there must be a simple way to do this, any ideas? Link to comment Share on other sites More sharing options...
ebr 14959 Posted December 21, 2021 Share Posted December 21, 2021 Hi. The return from GetItemById will be an item with all the properties of that item (e.g. Artists). Peek at it in the debugger and you can see all the properties. Also, you can grab that once into a local and not have to run through the search/get/database operation multiple times on each track... Link to comment Share on other sites More sharing options...
mickle026 404 Posted December 21, 2021 Author Share Posted December 21, 2021 Thank you for taking the time to reply, I can see the properties but I dont see anything thats obvious for getting the artist for the track neither on GetItemById for the Album or GetItemById for the track I see GetImageInfo etc but nothing for Artist or ArtistInfo Link to comment Share on other sites More sharing options...
Luke 37253 Posted December 21, 2021 Share Posted December 21, 2021 You have to cast it to (Audio) and then you'll get more properties available. Link to comment Share on other sites More sharing options...
mickle026 404 Posted December 21, 2021 Author Share Posted December 21, 2021 (edited) 57 minutes ago, Luke said: You have to cast it to (Audio) and then you'll get more properties available. mmm, im not that good yet, I dont know how to do that , I'll give it a go and wonder if there is a much easier way than what i am doing - lol Tried This and it looks like it should work but get InvalidCast Exception, MusicAlbum to Audioo doesnt work (Amateur at play here ) var mArtist = (Audio)mAlbum; var mArtistNames= mArtist.Artists; foreach (var newname in mArtistNames) { logger.Info($"Artist: {newname} ", null); } OK so I think Ive got it.... Cast the track to Audio (TrackImage in my code) foreach (var Entry in Tracklist) { var trackid = libraryManager.GetItemById(Entry).InternalId; var TrackName = libraryManager.GetItemById(Entry).Name; var TrackImage = libraryManager.GetItemById(Entry); var mArtist = (Audio)TrackImage; string[] mArtistNames = mArtist.Artists; foreach (var newname in mArtistNames) { logger.Info($"Artist: {newname} ", null); } Edited December 21, 2021 by mickle026 Link to comment Share on other sites More sharing options...
mickle026 404 Posted December 21, 2021 Author Share Posted December 21, 2021 I Just want to say Thank You! This has now opened the Plugin coding up for me 1 Link to comment Share on other sites More sharing options...
BillOatman 502 Posted December 21, 2021 Share Posted December 21, 2021 (edited) Instead of this var trackid = libraryManager.GetItemById(Entry).InternalId; var TrackName = libraryManager.GetItemById(Entry).Name; var TrackImage = libraryManager.GetItemById(Entry); Maybe try this, calling the GetItemById once instead of multiple times. var TrackImage = libraryManager.GetItemById(Entry); var trackid = TrackImage.InternalId; var TrackName = TrackImage.Name; Edited December 21, 2021 by BillOatman Link to comment Share on other sites More sharing options...
mickle026 404 Posted December 22, 2021 Author Share Posted December 22, 2021 (edited) 10 hours ago, BillOatman said: Instead of this var trackid = libraryManager.GetItemById(Entry).InternalId; var TrackName = libraryManager.GetItemById(Entry).Name; var TrackImage = libraryManager.GetItemById(Entry); Maybe try this, calling the GetItemById once instead of multiple times. var TrackImage = libraryManager.GetItemById(Entry); var trackid = TrackImage.InternalId; var TrackName = TrackImage.Name; Thanks #BillOatman, makes sense. I am self taught with c#, and only learned what bit I know because I wanted to write a plugin, im getting better but still have big gaps in my knowledge, helpful pointers and improvements are always welcome Edited December 22, 2021 by mickle026 Link to comment Share on other sites More sharing options...
ebr 14959 Posted December 22, 2021 Share Posted December 22, 2021 20 hours ago, BillOatman said: Maybe try this, calling the GetItemById once instead of multiple times. var TrackImage = libraryManager.GetItemById(Entry); var trackid = TrackImage.InternalId; var TrackName = TrackImage.Name; Then modify that first one to: Audio track = (Audio)libraryManager.GetItemById(Entry); 1 Link to comment Share on other sites More sharing options...
BillOatman 502 Posted December 22, 2021 Share Posted December 22, 2021 1 hour ago, ebr said: Then modify that first one to: Audio track = (Audio)libraryManager.GetItemById(Entry); True, I was assuming he might be using track id and name for something later Link to comment Share on other sites More sharing options...
mickle026 404 Posted December 22, 2021 Author Share Posted December 22, 2021 I am using all the parts. Well trying to. However I am confused, not with this code above but why as a part of my other code I am having problems with provider keys string mTrack_id = mTrack.GetProviderId(MetadataProviders.MusicBrainzTrack); string mAlbum_id = mTrack.GetProviderId(MetadataProviders.AudioDbAlbum); No matter how I add this within Emby when in the c# code MusicBrainzTrack is always Empty/Null, is there something wrong with that provider key? - The other seem to work fine so far in my tests. Link to comment Share on other sites More sharing options...
Luke 37253 Posted December 23, 2021 Share Posted December 23, 2021 Are you able to get other provider id values? Link to comment Share on other sites More sharing options...
mickle026 404 Posted December 23, 2021 Author Share Posted December 23, 2021 1 hour ago, Luke said: Are you able to get other provider id values? Yes without any problems, this one though is always empty. Link to comment Share on other sites More sharing options...
Luke 37253 Posted December 24, 2021 Share Posted December 24, 2021 I really don't know. Maybe that specific track doesn't actually have the value? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now