clara-j / media_cleaner

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

Add feature to keep favourite TVshows and seasons #9

Closed zilexa closed 4 years ago

zilexa commented 4 years ago

Currently, favourite tv shows and/or seasons are being deleted because the favourite tag is only checked on episode level.

terrelsa13 commented 4 years ago

@zilexa I am not seeing where Emby or Jellyfin provide an option to check if the season or show are marked as favourites. All it appears they provide is a check at the episode level.

Emby - Season set as favortie, show marked as watched {"Name":"Freakshow","ServerId":"0123456789abcdefghijklmnopqrstuv","Id":"1968","RunTimeTicks":25518830000,"IndexNumber":2,"ParentIndexNumber":3,"IsFolder":false,"Type":"Episode","ParentLogoItemId":"1529","ParentBackdropItemId":"1529","ParentBackdropImageTags":["d200e1c730d4bf612239df7374be9efc"],"UserData":{"PlaybackPositionTicks":0,"PlayCount":1,"IsFavorite":false,"LastPlayedDate":"2020-10-08T02:36:48.0000000+00:00","Played":true},"SeriesName":"DC's Legends of Tomorrow","SeriesId":"1529","SeasonId":"1966","SeriesPrimaryImageTag":"30f9385f133105f5fa7f80127ce3836c","SeasonName":"Season 3","ImageTags":{"Primary":"6f721dac1c352cef8ba5d97a082b496e"},"BackdropImageTags":[],"ParentLogoImageTag":"11aff033d12576c057c402fc89212531","ParentThumbItemId":"1529","ParentThumbImageTag":"07c406263fc4d16dc2e31e4938350f81","MediaType":"Video"}

Jellyfin - Same season set as favortie, same show marked as watched {"Name":"Freakshow","ServerId":"0123456789abcdefghijklmnopqrstuv","Id":"ed52208333a1afae8004b28a533ec650","HasSubtitles":true,"Container":"mkv,webm","PremiereDate":"2017-10-17T04:00:00.0000000Z","CommunityRating":7.2,"RunTimeTicks":25518829568,"ProductionYear":2017,"IndexNumber":2,"ParentIndexNumber":3,"IsFolder":false,"Type":"Episode","ParentLogoItemId":"3dada9ca1abbdb95b5dde70ced1a1b12","ParentBackdropItemId":"3dada9ca1abbdb95b5dde70ced1a1b12","ParentBackdropImageTags":["05dae8c7bc0347eeb395b55298b89ce3"],"UserData":{"PlaybackPositionTicks":0,"PlayCount":1,"IsFavorite":false,"LastPlayedDate":"2020-10-07T18:40:13.0000000-04:00","Played":true,"Key":"295760003002"},"SeriesName":"DC's Legends of Tomorrow","SeriesId":"3dada9ca1abbdb95b5dde70ced1a1b12","SeasonId":"058467f6f52524a103040fbd61c84756","SeriesPrimaryImageTag":"386c2f9dbd19c9d89a28bba5e4aa6389","SeasonName":"Season 3","VideoType":"VideoFile","ImageTags":{"Primary":"20f0223579cce50e45b67f054328bfdb"},"BackdropImageTags":[],"ParentLogoImageTag":"ed6f52e4169083630c488d3862a23da1","ImageBlurHashes":{"Primary":{"20f0223579cce50e45b67f054328bfdb":"WAEoi90NEM?H-q_2Ha-:XRt7r[Mx-;IUNGNIs8V@Fxfk%1WERjbv","386c2f9dbd19c9d89a28bba5e4aa6389":"dTIXBZ^uc??b:k=G]4$fqtrx+HrX}qt3tlv~quWFrsv}"},"Logo":{"ed6f52e4169083630c488d3862a23da1":"O#G[{5s:oJoft7oft7xuofjYfQkCj[j[~qazWVayayfkay"},"Backdrop":{"05dae8c7bc0347eeb395b55298b89ce3":"WSFPHY-p%2-WIUr?~V-TxWxtw[ou%Ms;oztRt8tRx]xatQj[V@Rj"}},"LocationType":"FileSystem","MediaType":"Video"},

This appears to be something emby and jellyfin will need to add into the API or the will need to propagate down to each episode when a higher level season or show are set to favourite.

terrelsa13 commented 4 years ago

@zilexa I stand corrected. It appears we are getting data at the episode level in the data I show above. In order to get it at the show and season level a couple more API calls will need to be added. Then checks to see if the show or season parent have their IsFavorite=true.

zilexa commented 4 years ago

OK sorry I didn't know it was missing in the API, not familiar with the Jellyfin API. If it can be done with multiple API calls instead of one, awesome! If I could code I would do it myself, sorry.

terrelsa13 commented 4 years ago

@zilexa Np. Try this out. See if it does what you want it to do.

zilexa commented 4 years ago

That was quick :) It seems to work as expected, the only TVshow I favourited is now kept. However when I turn on debug logging, for every episode it says this:

:[KEEPING] - Episode - Star Trek: Voyager - s01.e16 - Learning Curve - Watched 35 days ago - Favorite: True - EpisodeID: 469f81439dec97d188cddb21457a5a17
Episode is favorite: False
 Season is favorite: False
 Series is favorite: False

It says on the first line Favorite = True, but then it shows it is false on all levels. I expected to see Series is favorite: True. Seems like a minor typo issue perhaps?

Also, this series/season/ep is not favorited on any level, first line shows correctly Favorite: False and it is correctly being deleted. But the 3 levels show wrong info:

:*[DELETE] - Episode - NCIS - s17.e11 - In The Wind - Watched 35 days ago - Favorite: False - EpisodeID: 4686140a64395d474de319d8a3d751b7
Episode is favorite: False
 Season is favorite: True
 Series is favorite: True

I think the 'issue' is only in the logging, the actual code is working as expected :+1:

BTW I think you should open a topic on the JellyFin forum to make users and their dev team aware of this amazing script you wrote!

terrelsa13 commented 4 years ago

Cool. Glad it works the way you expect.

Yeah, I put the "favorite" lines in to help me see if what I was doing was actually working. Unless you are planning on making code changes, you should set DEBUG=0 in your config file. That will hide those x3 "favortie" lines.

This gets me confused sometimes too. I always have to check twice. But the x3 "favorite" lines are for the episode below, not above. So you want to look at it like this:

Episode is favorite: False Season is favorite: False Series is favorite: False 2020-09-27 16:06:54 :*[DELETE] - Episode - The Simpsons - s31.e18 - The Incredible Lightness of Being a Baby - Watched 11 days ago - Favorite: False - EpisodeID: 102008

I cannot take credit. @clara-j made the initial script. I have just been making improvements along the way. But you are right. I will put a plug in for this script in the Jellyfin forums. Thanks for the suggestion.

If your issue is solved, go ahead and close this when you get a chance.