ginjaninja 537 Posted April 29, 2020 Share Posted April 29, 2020 Is there a field on /items that returns library name /Items/{Id}/Ancestors doesnt seem to show library either... any suggestions on best way to return library name for an ID.. thanks Link to comment Share on other sites More sharing options...
PenkethBoy 2063 Posted April 29, 2020 Share Posted April 29, 2020 Dont think so episodes return the series ID - that can be used to get Series ParentID which would be Id of Library to get name Not very elegant but is one way to get it Or simpler get episodes by library - then you already know the library name or..... Link to comment Share on other sites More sharing options...
ginjaninja 537 Posted April 29, 2020 Author Share Posted April 29, 2020 @@PenkethBoy is there an elegant way in powershell by using something like/such as a 'Where' command on an array (the api's json response converted) to extract the path value where IsFolder=True and Type=Folder ie "J:\TV21" ie search an array for a matching object and return a subvalue of the match thankyou i can do checks against each row of the array using $Array.IsFolder and $Array.Type inside a for each loop, but was wondering if i can use 'where' to pluck the answer out on a oneliner... [there are four unnamed top level objects in the array] MyJson which is converted into array is [ { "Name": "Season 1", "ServerId": "fccaa6f897f140dbb689938224ae1938", "Id": "313372", "Etag": "69b8c4ab7ab11aaebfdb4bf0be8f717a", "DateCreated": "2020-04-20T15:18:21+01:00", "CanDelete": true, "CanDownload": false, "PresentationUniqueKey": "353764-en-6c2a057148b4d7c20a207c789aba6d07-001", "SortName": "0001", "PremiereDate": "2019-02-15T00:00:00+00:00", "ExternalUrls": [], "Path": "J:\\TV21\\The Umbrella Academy\\Season 01", "Taglines": [], "Genres": [], "ProductionYear": 2019, "IndexNumber": 1, "RemoteTrailers": [], "ProviderIds": { "Tvdb": "353764" }, "IsFolder": true, "ParentId": "313371", "Type": "Season", "People": [], "Studios": [], "GenreItems": [], "TagItems": [], "ParentLogoItemId": "313371", "ParentBackdropItemId": "313371", "ParentBackdropImageTags": [ "0403931a00ddb7e6f86748d30c888a0e" ], "SeriesName": "The Umbrella Academy", "SeriesId": "313371", "DisplayPreferencesId": "dfd065f5787fb957a750d76dcf835aad", "Tags": [], "PrimaryImageAspectRatio": 0.6666666666666666, "SeriesPrimaryImageTag": "6fda512bfc7f25bb6093d8cec7b70fef", "ImageTags": { "Primary": "176c236912f08199e344d52f154bb42f" }, "BackdropImageTags": [], "ParentLogoImageTag": "72c6a64c3e567cd3a178ad8dc567e151", "ParentThumbItemId": "313371", "ParentThumbImageTag": "1406c312273e0c3c9ac502d036fb6303", "LockedFields": [], "LockData": false }, { "Name": "The Umbrella Academy", "OriginalTitle": "The Umbrella Academy", "ServerId": "fccaa6f897f140dbb689938224ae1938", "Id": "313371", "Etag": "69b8c4ab7ab11aaebfdb4bf0be8f717a", "DateCreated": "2020-04-20T15:18:21+01:00", "CanDelete": true, "CanDownload": false, "PresentationUniqueKey": "353764-en-6c2a057148b4d7c20a207c789aba6d07", "SortName": "umbrella academy", "PremiereDate": "2019-02-15T00:00:00+00:00", "ExternalUrls": [ { "Name": "IMDb", "Url": "https://www.imdb.com/title/tt1312171" }, { "Name": "TheMovieDb", "Url": "https://www.themoviedb.org/tv/75006" }, { "Name": "TheTVDB", "Url": "https://thetvdb.com/?tab=series&id=353764" }, { "Name": "Trakt", "Url": "https://trakt.tv/shows/tt1312171" } ], "Path": "J:\\TV21\\The Umbrella Academy", "OfficialRating": "TV-14", "Overview": "Reunited by their father's death, estranged siblings with extraordinary powers uncover shocking family secrets—and a looming threat to humanity.", "Taglines": [], "Genres": [ "Drama", "Action", "Suspense" ], "CommunityRating": 8, "RunTimeTicks": 36000000000, "ProductionYear": 2019, "RemoteTrailers": [ { "Url": "http://www.youtube.com/watch?v=0DAmWHxeoKw" } ], "ProviderIds": { "Tvdb": "353764", "Imdb": "tt1312171", "Tmdb": "75006" }, "IsFolder": true, "ParentId": "293258", "Type": "Series", "People": [ { "Name": "Colm Feore", "Id": "133158", "Role": "Sir Reginald Hargreeves", "Type": "Actor", "PrimaryImageTag": "396a9c58834dd4f2a290c7b6d65040f8" }, { "Name": "Cameron Britton", "Id": "174075", "Role": "Hazel", "Type": "Actor", "PrimaryImageTag": "fe23cd7508e879f7d89a4b5e83e8919a" }, { "Name": "Mary J. Blige", "Id": "151332", "Role": "Cha-Cha", "Type": "Actor", "PrimaryImageTag": "15ff2960b3efcc5fb7fb967f56de3a55" }, { "Name": "Kate Walsh", "Id": "129291", "Role": "The Handler", "Type": "Actor", "PrimaryImageTag": "1275710520837861d5a0ce5e8cf4ce94" }, { "Name": "Tom Hopper", "Id": "153652", "Role": "Luther Hargreeves", "Type": "Actor", "PrimaryImageTag": "c8eacf48985bd0d011581dfe81f48d29" }, { "Name": "Ellen Page", "Id": "115073", "Role": "Vanya Hargreeves", "Type": "Actor", "PrimaryImageTag": "6884e810457c3f814353581f026ff9f7" }, { "Name": "Jordan Claire Robbins", "Id": "215863", "Role": "Grace", "Type": "Actor", "PrimaryImageTag": "528f0d956b8a0a70d80c8b70258d5a42" }, { "Name": "David Castañeda", "Id": "112591", "Role": "Diego Hargreeves", "Type": "Actor", "PrimaryImageTag": "6bf4d486e0b8a810c3e63a5a8b6ed4f2" }, { "Name": "Aidan Gallagher", "Id": "313383", "Role": "Number Five", "Type": "Actor", "PrimaryImageTag": "cb37d970aa6b9e1d2b0162ff58e67ec0" }, { "Name": "Sheila McCarthy", "Id": "122088", "Role": "Agnes Rofa", "Type": "Actor", "PrimaryImageTag": "b9d678dcb45dfd0f14fe5623fe8c29c7" }, { "Name": "Robert Sheehan", "Id": "168116", "Role": "Klaus Hargreeves", "Type": "Actor", "PrimaryImageTag": "5b773fb751a3d2907a91f2566d1129be" }, { "Name": "Justin H. Min", "Id": "313384", "Role": "Ben Hargreeves", "Type": "Actor", "PrimaryImageTag": "a326a07aa5239f2ffb12c8ea39546e28" }, { "Name": "Emmy Raver-Lampman", "Id": "275903", "Role": "Allison Hargreeves", "Type": "Actor", "PrimaryImageTag": "4bc7279012ed98b9d664e024c9801212" } ], "Studios": [ { "Name": "Netflix", "Id": 152841 } ], "GenreItems": [ { "Name": "Drama", "Id": 111176 }, { "Name": "Action", "Id": 111358 }, { "Name": "Suspense", "Id": 179815 } ], "TagItems": [], "LocalTrailerCount": 0, "DisplayPreferencesId": "f63033ff6886ecc7083a696cbeced1b0", "Status": "Continuing", "AirTime": "12:00 PM", "AirDays": [ "Friday" ], "Tags": [], "PrimaryImageAspectRatio": 0.6666666666666666, "DisplayOrder": "Aired", "ImageTags": { "Primary": "6fda512bfc7f25bb6093d8cec7b70fef", "Banner": "affbb862216a80d9ef116434d585e0cb", "Logo": "72c6a64c3e567cd3a178ad8dc567e151", "Thumb": "1406c312273e0c3c9ac502d036fb6303" }, "BackdropImageTags": [ "0403931a00ddb7e6f86748d30c888a0e" ], "LockedFields": [], "LockData": false }, { "Name": "TV21", "ServerId": "fccaa6f897f140dbb689938224ae1938", "Id": "293258", "Etag": "3e4c4be45013abcd83d22fd226c21aa1", "DateCreated": "2020-03-29T12:40:43+01:00", "CanDelete": false, "CanDownload": false, "PresentationUniqueKey": "4da370cf4a62a73a4f7d1026e20e61ac", "SortName": "tv0000000021", "ExternalUrls": [], "Path": "J:\\TV21", "Taglines": [], "Genres": [], "RemoteTrailers": [], "ProviderIds": {}, "IsFolder": true, "ParentId": "1", "Type": "Folder", "Studios": [], "GenreItems": [], "TagItems": [], "DisplayPreferencesId": "4da370cf4a62a73a4f7d1026e20e61ac", "Tags": [], "ImageTags": {}, "BackdropImageTags": [], "LockedFields": [], "LockData": false }, { "Name": "root", "ServerId": "fccaa6f897f140dbb689938224ae1938", "Id": "1", "Etag": "8abe4e9cf747075bf6b06ff6da1207ba", "DateCreated": "2019-04-07T10:43:46+01:00", "CanDelete": false, "CanDownload": false, "PresentationUniqueKey": "f27caa37e5142225cceded48f6553502", "SortName": "root", "ExternalUrls": [], "Path": "C:\\Users\\Nicholas Bird\\AppData\\Roaming\\Emby-Server\\programdata\\root", "Taglines": [], "Genres": [], "RemoteTrailers": [], "ProviderIds": {}, "IsFolder": true, "Type": "AggregateFolder", "Studios": [], "GenreItems": [], "TagItems": [], "DisplayPreferencesId": "ece728dc345c16a591a2a92b7f763524", "Tags": [], "ImageTags": {}, "BackdropImageTags": [], "LockedFields": [], "LockData": false } ] Link to comment Share on other sites More sharing options...
PenkethBoy 2063 Posted April 29, 2020 Share Posted April 29, 2020 Very quickly as late when the result of the call is converted from the api response e.g. $TestResult = Invoke-WebRequest -Uri $MediaUrl -Method Get $Media = $TestResult.Content | ConvertFrom-Json $Media is an collection of objects - no need to convert it to an array $Media.items gives you access to each object or $Media = $Media.Items then something like foreach ($Banana in $Media) { do something } $Result = $Media | where-object {($_.Isfolder -eq "true") -and ($_.Path -contains "J:\")} or Select-object or sort-object look at the MS help documents online for PS Link to comment Share on other sites More sharing options...
ginjaninja 537 Posted April 30, 2020 Author Share Posted April 30, 2020 $Result = $Media | where-object {($_.Isfolder -eq "true") -and ($_.Path -contains "J:\")} thanks i was close and reading up on where-object but my testing was unsuccessful as i was using $_.Isfolder="true" and not sure what level i was in the collection...need to watch that syntax more closely. also doesnt help that Visual Studio Code requires me to run code twice after i change code within a function (changes dont come into effect until 2nd run).. Link to comment Share on other sites More sharing options...
PenkethBoy 2063 Posted April 30, 2020 Share Posted April 30, 2020 something wrong with you setup/code if you have to run it twice Link to comment Share on other sites More sharing options...
ginjaninja 537 Posted April 30, 2020 Author Share Posted April 30, 2020 (edited) thanks for help, will look into double run. this is my library getter, needs a bit more testing to make sure it works for all IDs / all object types. ReturnLibraryForID -ID $ID function ReturnLibraryForID{ #Returns the library for a given emby item ID [CmdletBinding()] Param( [Parameter(Mandatory=$true)] [String]$ID ) #get the ancestors for id and then get the top media folder $AncestorsForID=Fetch-Api -ApiEndpoint "/Items/$ID/Ancestors?" -ApiFields "" -embyapikey $embyapikey $MediaFolderForID = $AncestorsForID | where-object { ($_.Isfolder -eq "true") -and ($_.Type -eq "Folder") } | Select-Object -Last 1 #return all media folders for all libraries for a match with the ID's media folder $LibraryFolders=Fetch-Api -ApiEndpoint "/Library/VirtualFolders?" -ApiFields "" -embyapikey $embyapikey $LibraryForID = $LibraryFolders | Where-Object {($_.Locations) -contains $MediaFolderForID.path} return $LibraryForID.Name } function Fetch-Api { #Returns a collection for a given api request [CmdletBinding()] Param( [Parameter(Mandatory=$true)] [String]$ApiEndpoint, [Parameter(Mandatory=$false)] [String]$ApiFields, [Parameter(Mandatory=$True)] [String]$EmbyApikey ) $ApiURL = $embyServerUrl + $ApiEndpoint + $ApiFields +"Api_key=" + $embyapikey #Write-Host "ApiURL: "$ApiURL $ApiResult = Invoke-WebRequest -Uri $ApiUrl -Method Get $ApiResponse = $ApiResult.Content | ConvertFrom-Json return $ApiResponse } Edited May 19, 2020 by ginjaninja Link to comment Share on other sites More sharing options...
PenkethBoy 2063 Posted April 30, 2020 Share Posted April 30, 2020 From a quick test - /Ancestors - gives you the name of the library without having to do the second call Just picked an Episode to test ran the ancestors end point get 4 items back of Type - Season,Series,Folder(the library) and aggregatefolder (root) so name of third item is name of library so a filter by folder - gives you the name in one go Not tried with all file types but would simplify what you are doing - if it works for all types and configs Also as it walks up the ancestor tree the second to last item return will always be the library and the last will be root - if thats consistent - another way to find the library name Link to comment Share on other sites More sharing options...
ginjaninja 537 Posted April 30, 2020 Author Share Posted April 30, 2020 From a quick test - /Ancestors - gives you the name of the library without having to do the second call Just picked an Episode to test ran the ancestors end point get 4 items back of Type - Season,Series,Folder(the library) and aggregatefolder (root) so name of third item is name of library so a filter by folder - gives you the name in one go Not tried with all file types but would simplify what you are doing - if it works for all types and configs Also as it walks up the ancestor tree the second to last item return will always be the library and the last will be root - if thats consistent - another way to find the library name in the example above, the name of the object is TV21 but this is not the name of the library, i think this is because my libraries are made up of multiple folders. Link to comment Share on other sites More sharing options...
PenkethBoy 2063 Posted April 30, 2020 Share Posted April 30, 2020 Ah yes you are correct its the name of the folder - hmm i only have one folder for tv and its the same Link to comment Share on other sites More sharing options...
PenkethBoy 2063 Posted April 30, 2020 Share Posted April 30, 2020 Ok - using the /Library/SelectableMediaFolders end point gives me a list of all libraries and any subfolders Maybe load that first - filter out what you dont need - then compare the folder id's for your ancestor query and dont need to do the Library folder query every time ...{ "Name": "TV Shows", "Id": "767bffe4f11c93ef34b805451a696a4e", "SubFolders": [ { "Name": "TVTesting", "Id": "1768", "Path": "F:\\EmbyTest\\TVTesting" }.... and ancestors gives me ...{ "Name": "TVTesting", "ServerId": "393d783c30484015a24645f7844060b4", "Id": "1768", "Etag": "50a6368cec461ef1c435df94cac0af01", "DateCreated": "2020-03-21T22:09:46.0000000+00:00", "CanDelete": false, "CanDownload": false, "PresentationUniqueKey": "8440dbf351f32ad4c2501e01d1e5e789", "SortName": "tvtesting", "ExternalUrls": [], "Path": "F:\\EmbyTest\\TVTesting", "Taglines": [], "Genres": [], "RemoteTrailers": [], "ProviderIds": {}, "IsFolder": true, "ParentId": "1", "Type": "Folder", "Studios": [], "GenreItems": [], "TagItems": [], "DisplayPreferencesId": "8440dbf351f32ad4c2501e01d1e5e789", "Tags": [], "ImageTags": {}, "BackdropImageTags": [], "LockedFields": [], "LockData": false }.... subfolder id matches ancestor (folder) ID would be another way to do it Maybe quicker - not tested it 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