clara-j / media_cleaner

Python script to delete watched content on Emby
31 stars 17 forks source link

trying to modify code without luck #15

Closed elvis0288 closed 3 years ago

elvis0288 commented 3 years ago

Hello guys, is there a way in which we can skip certain genres? lets say i do not want my kids movies or tv shows to be deleted so is there a way to not delete animated videos? maybe set paths that should not be deleted?

terrelsa13 commented 3 years ago

To do what you want you will need to verify keep_favorites_episode=1 in the media_cleaner_config.py file. Then open emby and favorite the episodes, seasons, and/or series you want to not be deleted (aka you want to keep). When the media_cleaner script runs it will ignore anything marked as a favorite.

The Hierarchy Is As Follows:

Setting keep_favorites_movie=1 will do the same for any movies you want to keep.

terrelsa13 commented 3 years ago

@elvis0288 finally got around to implementing the request to whitelist certain paths. Please check it out here.

Let me know if there is any feedback.

Edit - Forgot to add the link.

terrelsa13 commented 3 years ago

FYI - To whitelist a kids TV folder, the kids TV shows will either need to be in a second library or a separate sub-folder within a library.

A sub-folder can be added to an existing library by going to Library > Selecting the TV library > +Folders

terrelsa13 commented 3 years ago

16

elvis0288 commented 3 years ago

Nice thank you very much I will test it in a bit

elvis0288 commented 3 years ago

Hello Terrelsa so i checked on this and i found 3 issues with it

  1. looks like even if i have debug set to true, it will delete the movies/shows anyways
  2. when creating the config file, my path would be something like this: E:\Elvis' Folders\Multimedia\Movies\Animated Movies. which will fail because of the '.. so i had to go into the config myself and add the '' so it looks like E:\Elvis'' Folders\Multimedia\Movies\Animated Movies
  3. even though i have animated movies as whitelisted, it deleted those movies so it is not working.

this is how my config look DEBUG=1 not_played_age_movie=0 not_played_age_episode=0 not_played_age_video=100 not_played_age_trailer=100 remove_files=50 keep_favorites_movie=1 keep_favorites_episode=1 keep_favorites_video=1 keep_favorites_trailer=1 whitelisted_library_folders='C:\ProgramData\Jellyfin\Server\data\collections,E:\Elvis'' Folders\Multimedia\Music,E:\Elvis'' Folders\Multimedia\Movies\Animated Movies'

and this is what happen when i run it isfav: {'episode': {'bf2552444658ab9379911e1cbb6c5d49': False, '12ec6550801d01d26dd28fc9f0a11641': False, '285fbd06fd3f8d0d51d1ce0ed0652152': False, 'c18edfe9d560358357ea216be3a16d64': False, '7e4e3c72563c80ece95dd53805410043': False, '937356b4291a7a45bbc70f85e257a2b6': False, '7e8c1eca2b7d7749cacb4fafa900e8ff': False, '2f1cec53361935c26072d680a24c0998': False, '1bd286b4f78e2a07c8c986efba3d41d5': False, '06765a178928b726a33d40d85f470db6': False, '2e57809b01f26af694cdfee517bee9c0': False, 'd00ff65f0a8736ba23c60518c3131b7a': False, '5eb30317f821317c4c71f8038e023f4c': False, 'abbb5ab52f72dd2a191984634ca52599': False, 'fb00eb918fbb53b1c900f28388029af2': False, '773e8e6a286ec7bd96aa36c878b0557e': False, 'b81149c8d48fbdec2530e546a9b2c574': False, '68cced5dfe8b73358014420bc4a3bf67': False, 'c8ed5e56ab2b062533ee858112aaf5dc': False, '1b1c53977186312dcf26f7311320193c': False, '4004ef2f339e19f0ddc524fcbf302f49': False}, 'season': {'360d494b28b9494f9fcb40057dbe02fd': False, '98f34a1bfc4292cadb29c3d62c632177': False, 'b53d991023e86ba283f7548cc62cecfd': False, 'a7bc5b79464769b2e7bd67acde5ab477': False}, 'series': {'e1e775af0b08a42eec54ee3e3cbb3b24': False, '97cdf8dfcc24c3c164fa8202a9775c17': False, '12931997466f52d8389067f32a8f7b54': False, '9cfe777f42d52eaf55d532d5ac689ecd': False}}



Summary Of Deleted Media:


Done.

terrelsa13 commented 3 years ago

@elvis0288 Yesterday I fixed a bug where everything was being deleted.

Will you verify you tested the version before or after the bug fix? The lasted version can be downloaded from my fork?

elvis0288 commented 3 years ago

let me check. i just downloaded the one from the link above to give me the issue but let me try with the one you are sending me now

elvis0288 commented 3 years ago

yes it is the same issue but even before this new whitelist paths, there was an issue with the debug variable.. for some reason it does not matter if it is 1 or 0 it will always delete them for me. but i guess yeah there is 2 different things going on here.

  1. debug variable not working
  2. whitelist feature not working deleting from those path still
terrelsa13 commented 3 years ago

The DEBUG variable does not determine when an item is deleted or not. To prevent items from being deleted set remove_files=0.

For remove_files=50, did you manually change it 50 or did the script put in 50 as the value?

Let's try to figure out why this works on my end but not on your end.

First set DEBUG=0. Then open the script, go to line #334 (in the def list_library_folders(server_url, auth_key):) function and remove the #.

It will look like this: #DEBUG print2json(data)

Run the script and paste the entire output into a Pastebin entry.

elvis0288 commented 3 years ago

Hello i put the 50 there so i will delete 50 files at a time. ok so i move it back to 0 and also change debug to 0 but i do not see difference between with commenting or not commenting out the line you are telling me above.. i paste the results anyways.. if you see on the results, the adams family and alien xmas should be keep and it looks like adams family should be keep and then it do delete whilelist false which is weird https://pastebin.com/tgNXEv7p

terrelsa13 commented 3 years ago

My apologies. My instructions where not clear. Let me try again.

1) Uncomment the line shown in the images below. Here is a screenshot of what it will look like before: Here is a screenshot of what it will look like after removing the #:

2) Rename your current media_cleaner_config.py to media_cleaner_config.py.copy. 3) Run the script. (You should see the library folder debug information this time.) 4) Copy the entire output into a new pastebin. 5) Open the media_cleaner_config.py file... 6) Change DEBUG=0 to DEBUG=1. 7) Change not_played_age_movie=100 to not_played_age_movie=0 8) Change not_played_age_episode=100 to not_played_age_episode=0 9) Verify remove_files=0 (This will skip the part where the script asks emby/jellyfin to delete media.) 10) Run the script again. 11) Copy the entire output into a second new pastebin. 12) Reply with both pastebin links


The remove_file variable in the config file has to either be 0 or 1.

0 - Means run the script but do not delete anything. This is good for testing to see if it is working the way we expect it to work. 1 - Means run the script and delete media files. When we know it is working as expected set it to 1.

The DEBUG variable in the config file has to either be 0 or 1.

0 - Means do not print debug data to screen 1 - Means print debug data to screen

terrelsa13 commented 3 years ago

After trying to rename my paths to match yours as best as I can on a linux machine; I think I see what the issue is. It appears the single quote needs to be escaped so it is not seen as an ending single quote in the media_cleaner_config.py file.

Before: E:\Elvis' Folders\Multimedia\Movies\Animated Movies

After: E:\Elvis\' Folders\Multimedia\Movies\Animated Movies

I updated my fork to add an escape character.

Tomorrow I will try to figure out if I need to remove the escape character when making the decision to delete media or keep media.

elvis0288 commented 3 years ago

Hello,

that scape character fix the issue and now it is working correctly. you can see on the pastebin below https://pastebin.com/sCARWB47

now is there a way to actually ignore music? i am getting that unknown media type because it is audio so this is why it is been ignored but it would be nice to just have a way to ignore those from even showing on the list of watched media...

also are you planning on creating a plugin on jellyfin for this nice program you have?

elvis0288 commented 3 years ago

i modify your code so it is ignoring and not showing the unknown media image

i guess it was easy enough but i guess if you update something it will override my changes lol

terrelsa13 commented 3 years ago

@elvis0288 Glad adding the escape before a single quote got it working for you!

At some point I will go in and capture all media types (or at least the ones I think are major) and audio will have an option to keep, remove, favorite, and whitelist just like episodes, movies, trailers, etc... When I do that I will silence the output for types a user decides to disable and for the unknown types.

I have no immediate plans to move this into Emby or Jellyfin as a plugin. This script works well when only one user's watched status is used to decide if media can be deleted. Adding it to Emby or Jellyfin as a plugin opens the door for having to manage multiple users, watching (or not watching) multiple shows and movies. This would quickly become a nightmare.

I am able to find the time to maintain and update this simple script. Hopefully making media maintenance a little easier for a few other people. For now, this is good enough for me.

Please go ahead and close this issue if we have gotten you up and working.