Powdor 0 Posted April 27, 2022 Share Posted April 27, 2022 Hello, The idea sounds simple. I would like to have the system automatically marks items for deletion (and possibly delete them in a second stage) if they are not used and have been present for a long time. This is of course a little more complex because "not used" means any activity on a TV serie should treat the entire serie as active. Line of thinking so far: Rules that would make the files eligible for deletion using cutoff time in number of days: Based on the timestamp the item was added to the library (DateCreated) Exclude those items, collections and related items where user activity was found in the same time period Was it marked as favorite (exclude from deletion) There is no filter available for MaxDateCreated on libraryManager.GetItemList. But filtering later is okay (don't know yet how it will behave with big collections). I could not find / understand how to get the user activity rolled up so I can process it. This is where I hope someone can give me some hints. I have been looking at IActivityManager and UserDataManager. But both use some linking that is not obvious to me. ps. I have started the work over here: Powdor/EmbyMediaCleaner: Plugin to automatically clean your local media library of watched, old files (github.com) Link to comment Share on other sites More sharing options...
Luke 37083 Posted April 27, 2022 Share Posted April 27, 2022 Hi, I would probably suggest a scheduled task with filters to figure out what to delete. I wouldn't really use IActivityManager as you can't really sort and filter on that data. If you need new filters added then let me know. Thanks. Link to comment Share on other sites More sharing options...
Powdor 0 Posted April 28, 2022 Author Share Posted April 28, 2022 @luke yes I think a filter MaxDateCreated would be welcome to be able to filter the initial list down significanlty. But how do I get to the data about the last played date for a specific item or even beter for a TV show or Season. Which API should I be looking into? Link to comment Share on other sites More sharing options...
bakes82 90 Posted May 3, 2022 Share Posted May 3, 2022 If youre doing the sched task way its the libraryManager. var mediaItems = libraryManager.GetItemList(new InternalItemsQuery { IncludeItemTypes = new[] { nameof(Movie) }, IsVirtualItem = false, OrderBy = new[] { new ValueTuple<string, SortOrder>(ItemSortBy.PremiereDate, SortOrder.Descending), new ValueTuple<string, SortOrder>(ItemSortBy.SeriesSortNameOrSortName, SortOrder.Ascending) } }) .ToList(); Then loop/filter the movies again, here a quick loop Link to comment Share on other sites More sharing options...
Luke 37083 Posted May 3, 2022 Share Posted May 3, 2022 OK I can add a MaxDateCreated filter param. Link to comment Share on other sites More sharing options...
Powdor 0 Posted May 18, 2022 Author Share Posted May 18, 2022 (edited) I was playing around a bit to understand the data structure.. I figured it out from db perspective but I am not sure how things ar mapped into the librarymanager items exactly.. But more importantly I cannot get back LastPlayedDate or PlayCount to be anything but null? I think I must be missing something .. I do see the fact that it was played by a user tracked here: Edited May 18, 2022 by Powdor Link to comment Share on other sites More sharing options...
Powdor 0 Posted May 20, 2022 Author Share Posted May 20, 2022 I am looking to implement this kind of filtering.. Any thoughts on this? select count(m.Id) Count, sum(m.size)/1024/1024/1024 SizeInGb from MediaItems m where m.Size > 0 and m.DateModified < StrfTime('%s', Date('now', '-365 day')) AND m.Id not in (SELECT m.Id FROM UserDatas u LEFT OUTER JOIN MediaItems m on u.UserDataKeyId = m.UserDataKeyId WHERE m.MediaType = 1 and LastPlayedDateInt > StrfTime('%s', Date('now', '-365 day'))) and (m.SeriesId is null or m.SeriesId not in (SELECT distinct m.SeriesId SeriesId FROM UserDatas u LEFT OUTER JOIN MediaItems m on u.UserDataKeyId = m.UserDataKeyId WHERE not (m.SeriesId is null) and LastPlayedDateInt > StrfTime('%s', Date('now', '-365 day'))) ) Link to comment Share on other sites More sharing options...
Luke 37083 Posted May 21, 2022 Share Posted May 21, 2022 On 5/20/2022 at 5:44 AM, Powdor said: I am looking to implement this kind of filtering.. Any thoughts on this? select count(m.Id) Count, sum(m.size)/1024/1024/1024 SizeInGb from MediaItems m where m.Size > 0 and m.DateModified < StrfTime('%s', Date('now', '-365 day')) AND m.Id not in (SELECT m.Id FROM UserDatas u LEFT OUTER JOIN MediaItems m on u.UserDataKeyId = m.UserDataKeyId WHERE m.MediaType = 1 and LastPlayedDateInt > StrfTime('%s', Date('now', '-365 day'))) and (m.SeriesId is null or m.SeriesId not in (SELECT distinct m.SeriesId SeriesId FROM UserDatas u LEFT OUTER JOIN MediaItems m on u.UserDataKeyId = m.UserDataKeyId WHERE not (m.SeriesId is null) and LastPlayedDateInt > StrfTime('%s', Date('now', '-365 day'))) ) what is the result? Link to comment Share on other sites More sharing options...
Powdor 0 Posted June 6, 2022 Author Share Posted June 6, 2022 The first part is just counting the number of items. But I would like to take a list of items that I then try to delete. The main filter is just selecting all that is older than 365 days m.DateModified < StrfTime('%s', Date('now', '-365 day')) This sub select removes items from the result list that have been watched/played in the past 365 days (ie. items of interest) AND m.Id not in (SELECT m.Id FROM UserDatas u LEFT OUTER JOIN MediaItems m on u.UserDataKeyId = m.UserDataKeyId WHERE m.MediaType = 1 and LastPlayedDateInt > StrfTime('%s', Date('now', '-365 day'))) The next sub select removes items from the result list that are part of a tv series / show of which had items that have been watched/played in the past 365 days and (m.SeriesId is null or m.SeriesId not in (SELECT distinct m.SeriesId SeriesId FROM UserDatas u LEFT OUTER JOIN MediaItems m on u.UserDataKeyId = m.UserDataKeyId WHERE not (m.SeriesId is null) and LastPlayedDateInt > StrfTime('%s', Date('now', '-365 day'))) ) Is there a way to use these queries directly or do you think this can be accomplished with existing filters / query facilities? 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