mickle026 401 Posted February 22, 2022 Share Posted February 22, 2022 (edited) I have an episode and its id, how do i get the series name that it belongs to? I tried casting (Series)Episode and I get invalid cast exception. I have cast to Video, but still cannot find how to get the series name. If I getParents() I get root TV <SeriesName> Season Episode.mkv it seems to me to be getting the folders from root. With this method I cannot guarantee that I have the series name each time its required. var EpisodeID = libraryManager.GetItemById(eachEpisode); var EpisodePath = libraryManager.GetItemById(eachEpisode).Path; var EpisodeName = libraryManager.GetItemById(eachEpisode).Name; var Ep = (Video)EpisodeID; // cast to video type, series type fails with invalid cast. var S = Ep.ParentIndexNumber; // Season number ie S01 will return just 1 var E = Ep.IndexNumber; // Episode number as item above var ProductionYear = Ep.ProductionYear; var SeasonName = Ep.Parent.Name; // this is the season/series folder if there is one var FolderName = Ep.Parent.Parent.Name; // this is the folder name above the season/series folder if there is one var SeasonEpisodeSE = $"S{S}E{E}"; // if they exist!! var ParentName = Ep.GetTopParent().Name; // this is the TV folder var TVshowParentName = Ep.GetParents(); // gets each folder from /root /TV /Series Name /Season / etc Is there an easier way to get this information? I only need the series name and year. Many thanks Edited February 22, 2022 by mickle026 Link to comment Share on other sites More sharing options...
pünktchen 1258 Posted February 22, 2022 Share Posted February 22, 2022 Ep.DisplayParent.DisplayParent.InternalId Works even without a season folder. Link to comment Share on other sites More sharing options...
mickle026 401 Posted February 22, 2022 Author Share Posted February 22, 2022 Thank you very much , Seems along with Ep.DisplayParent.DisplayParent.ProductionYear I can detect the correct folder now and Ep.Parent.ProductionYear will give me the year for each Season if in season folders or Ep.DisplayParent.ProductionYear even if they are not. It was DisplayParent that I needed. Many thanks! Link to comment Share on other sites More sharing options...
chef 3746 Posted February 23, 2022 Share Posted February 23, 2022 (edited) Are you casting to "Video"? You want BaseItem data Here: var seriesInternalItemQuery = new InternalItemsQuery() { Recursive = true, IncludeItemTypes = new[] { "Series" }, User = UserManager.Users.FirstOrDefault(user => user.Policy.IsAdministrator) }; var seriesQuery = LibraryManager.QueryItems(seriesInternalItemQuery); foreach(var series in seriesQuery.Items) { //"series" is the BaseItem //series.Name } This can also be done using any type in "IncludeItemTypes" "Episode", "Series", "Season" or you can put them all in and request everything var itemQuery = new InternalItemsQuery() { Recursive = true, IncludeItemTypes = new[] { "Series", "Season", "Episode }, //nameof(Series), nameof(Season), nameof(Episode) User = UserManager.Users.FirstOrDefault(user => user.Policy.IsAdministrator) }; Episode, Season, and Series are types, but they all inherit from BaseItem. let me know how to get on. Edited February 23, 2022 by chef Link to comment Share on other sites More sharing options...
chef 3746 Posted February 23, 2022 Share Posted February 23, 2022 Ops! Just realized you ask how to the series from an episode. Sorry about that. there are two ways. First get the Episode: var itemQuery = new InternalItemsQuery() { Recursive = true, IncludeItemTypes = new[] { nameof(Episode) }, User = UserManager.Users.FirstOrDefault(user => user.Policy.IsAdministrator) }; foreach(var episode in episodeQuery.Items) { if(episode.Name == "The episode I want") //or I know the episode.InternalId: (episode.InternalId == myepisodeInternalId) { //Series Name var series = episode.Parent.Parent; var seriesName = series.Name; //Or var seriesId = episode.SeriesId; var series = LibraryManager.GetItemById(seriesId); var seriesName = series.Name; } } Link to comment Share on other sites More sharing options...
mickle026 401 Posted February 23, 2022 Author Share Posted February 23, 2022 (edited) This was the method I was originally trying var series = episode.Parent.Parent; However, in some cases depending on the file structure it was giving me wrong information, it was giving me folder names. (might be as below when an episode doesnt belong to a series/unidentified) var seriesId = episode.SeriesId; var series = LibraryManager.GetItemById(seriesId); var seriesName = series.Name; This is more likey going to do it ,with the internal items query. Thankyou However , the method by pünktchen also works. var Ep = (Video)EpisodeID; Ep.DisplayParent.DisplayParent.Name; All of them throw exception when the Episode doesn't belong to a series, such as a standup comedy sketch (segment) from a tv program , that hasn't identified as belonging to a series. The excpetion being thrown was difficult to debug, because it was one of them (WTF? errors) object not set to reference but doesn't tell you anything more, but I got there with a try..catch.. try { ParentName = Ep.DisplayParent.DisplayParent.Name; } catch { // Log the error } Thanks for this, It'll help everyone now its actually in text on here. Edited February 23, 2022 by mickle026 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