Jump to content

Script to unmonitor from *Arr apps and Delete Watched items


amateurgod

Recommended Posts

amateurgod

Hey everyone I have finished a script I've been working on. The script will get a user's watched items from emby and then unmonitor them in the relative *Arr app before deleting them from your emby library and filesystem if it has been more than 14 days from the episodes air date (the time limit isn't in place for movies only episodes). 

You can also blacklist movies and tv shows for the script to ignore

feel free to check it out over on GitHub 

Github - EmbyArrSync

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

amateurgod

I've made a lot of changes and improvements to the above script over the past week and am now on V-1.1.0
 

What's Changed
- Moved Blacklists to /config/blacklists.json
- Moved env variables to /config/EmbyArrSync.env
- Improved error handling
- added more env variables for customisation
- created requirements.txt
- Lots of optimisations and improvements to the script

- Added a function to delete episode files from Sonarr/Radarr Directly
- Added the option to disable deleting items directly in Emby library for those that use the Sonarr/Radarr Emby connection for library updates
- improved Print statements to show identifiable info in a human-readable format such as episode name and series name or movie name instead of item/tmbd/tvdb ids etc
- specified a limit for the number of activities pulled from Emby watch history api to grab more set the new default limit to the highest number that I found that didn't result in errors, also made this an env variable so it can be altered based on users needs

Edited by amateurgod
Link to comment
Share on other sites

  • 2 weeks later...
artstar

Not sure if this is because I'm running it on Emby 4.8.3 (just installed your tool after I performed this upgrade) but seems like Emby doesn't like the API call, returning the following response:

500 Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)

Perhaps one of the Emby devs can explain what is causing this?

I tried performing the API call manually in my browser using the following URL (cut down from what you have in your Python script, to start from as bare bones as possible): http://[redacted]:8096/Users/[redacted]/Items/Latest?IsFolder=false&IsPlayed=true&GroupItems=false&api_key=[redacted]

Link to comment
Share on other sites

Hi, please attach the server log. Thanks.

Link to comment
Share on other sites

artstar

Apologies, I knew I was missing a detail somewhere! This is what gets logged as a result of the API call. If you want the full log file, I'll happily send that on.

2024-03-03 14:34:42.018 Debug Server: http/1.1 GET http://‌‍‍[redacted]:8096/Users/[redacted]/Items?IsFolder=false&IsPlayed=true&GroupItems=false&EnableImages=false&EnableUserData=false&Limit=100000&api_
key=‌[redacted‌]. UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
2024-03-03 14:34:42.019 Error Server: Error processing request
        *** Error Report ***
        Version: 4.8.3.0
        Command line: /opt/emby-server/system/EmbyServer.dll -programdata /var/lib/emby -ffdetect /opt/emby-server/bin/ffdetect -ffmpeg /opt/emby-server/bin/ffmpeg -ffprobe /opt/emby-server/bin/ffprobe -
restartexitcode 3 -updatepackage emby-server-deb_{version}_amd64.deb
        Operating system: Linux version 5.15.0-97-generic (buildd@lcy02-amd64-033) (gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, GNU ld (GNU Binutils for Ubuntu) 2.38) #107-Ubunt
        Framework: .NET 6.0.25
        OS/Process: x64/x64
        Runtime: opt/emby-server/system/System.Private.CoreLib.dll
        Processor count: 2
        Data path: /var/lib/emby
        Application path: /opt/emby-server/system
        System.FormatException: System.FormatException: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
           at System.Guid.GuidResult.SetFailure(Boolean overflow, String failureMessageID)
           at System.Guid.TryParseExactN(ReadOnlySpan`1 guidString, GuidResult& result)
           at System.Guid.TryParseGuid(ReadOnlySpan`1 guidString, GuidResult& result)
           at System.Guid.Parse(ReadOnlySpan`1 input)
           at System.Guid.Parse(String input)
           at Emby.Server.Implementations.Services.ValueParser.ParseGuid(String value)
           at Emby.Server.Implementations.Services.StringMapTypeDeserializer.PopulateFromMap(Object instance, IDictionary`2 keyValuePairs)
           at Emby.Server.Implementations.Services.RestPath.CreateRequest(String pathInfo, Dictionary`2 queryStringAndFormData, Object fromInstance)
           at Emby.Server.Implementations.Services.ServiceHandler.CreateRequest(IRequest httpReq, RestPath restPath, Dictionary`2 requestParams, Object requestDto)
           at Emby.Server.Implementations.Services.ServiceHandler.CreateRequest(HttpListenerHost host, IRequest httpReq, RestPath restPath)
           at Emby.Server.Implementations.Services.ServiceHandler.ProcessRequestAsync(HttpListenerHost httpHost, IServerApplicationHost appHost, IRequest httpReq, IResponse httpRes, IStreamHelper streamH
elper, RestPath restPath, String responseContentType, CancellationToken cancellationToken)
           at Emby.Server.Implementations.HttpServer.HttpListenerHost.RequestHandler(IRequest httpReq, ReadOnlyMemory`1 urlString, ReadOnlyMemory`1 localPath, CancellationToken cancellationToken)
        Source: System.Private.CoreLib
        TargetSite: Void SetFailure(Boolean, System.String)

2024-03-03 14:34:42.019 Info Server: http/1.1 Response 500 to ‌‍‍[laptop redacted]. Time: 1ms. GET http://‌‍‍[redacted]:8096/Users/[redacted]/Items?IsFolder=false&IsPlayed=true&GroupItems=false&EnableImages=false&EnableUserData=false&Limit=100000&api_key=‌[redacted]

 

Link to comment
Share on other sites

amateurgod
47 minutes ago, artstar said:

Not sure if this is because I'm running it on Emby 4.8.3 (just installed your tool after I performed this upgrade) but seems like Emby doesn't like the API call, returning the following response:

500 Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)

Perhaps one of the Emby devs can explain what is causing this?

I tried performing the API call manually in my browser using the following URL (cut down from what you have in your Python script, to start from as bare bones as possible): http://[redacted]:8096/Users/[redacted]/Items/Latest?IsFolder=false&IsPlayed=true&GroupItems=false&api_key=[redacted]

How did you get your user ID? Did you copy it from  the userId= part of the URL when you select a user in the users section? 

 

Also can you post the contents of your .Env file with sensitive information removed?

 

I don't think userID is sensitive information but luke can correct me on that if I'm wrong 

Link to comment
Share on other sites

artstar

Oh!!! I'm meant to use that GUID and not my actual user name!

That's my idiotic move for the day. Alrighty, I'll fetch my UID instead of user name. :) Thanks!

Link to comment
Share on other sites

amateurgod
2 minutes ago, artstar said:

Oh!!! I'm meant to use that GUID and not my actual user name!

That's my idiotic move for the day. Alrighty, I'll fetch my UID instead of user name. :) Thanks!

No problem, I'll add some instructions to the readme and again in the env file on how to get the User ID when I wake up and am at my PC. 

If you have any more issues or questions, feel free to ask me here or on GitHub, I'm active on both :)

Link to comment
Share on other sites

artstar

No problem and thanks! I gave it the maiden run after modifying the script to not perform deletes based on another environment variable I introduced into the config file, as I only want it to unmonitor what is on my remote seedbox based on what I have viewed in my local Emby server. rutorrent maintains the deletions for me based on totally different rules.

Works a treat!

Link to comment
Share on other sites

amateurgod

Glad to hear its all working for you, that and some other customisability features are things I plan on adding to V2 of the script 

Link to comment
Share on other sites

amateurgod

Version 2 has been released with more customisability 

What's Changed


Adds the following ENV variables

- "HANDLE_TV" This allows users to enable or disable the TV functionality of the script
- "HANDLE_MOVIES" This allows users to enable or disable the Movies functionality of the script
- "TV_DELETE" This allows users to enable or disable the deletion of TV shows so that the script only unmonitors them
- "MOVIE_DELETE" This allows users to enable or disable the deletion of Movies so that the script only unmonitors them

Added the Following Blacklist

- "BLACKLISTED_PATHS" This enables user to blacklist specific paths to be ignored by the Script

Updated documentation to add details on how to get USER ID for Emby

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
amateurgod

Currently handling it to check if series/episodes are marked as favourite and if the series is marked as favourite to append the path to blacklisted paths, this is only on a per script run, or would people prefer it to edit the actual blacklists.json file with the blacklisted paths (this shouldnt be needed because as long as they are marked as favourite in emby then the path will be add to the blacklist for that run)

  • Like 1
Link to comment
Share on other sites

amateurgod

Minor update to V2

I bring you V2.1.0

What's Changed

- Added checks to the script to check if Series, Episodes, or movies are marked as favourite in Emby, if they are it will skip running the script on them.

https://github.com/Amateur-God/EmbyArrSync/releases/tag/v2.1.0

if people want me to change it to make the blacklisting of favourite series paths to edit the blacklists.json making it semi-permanent (you would have to open the blacklists file and remove the paths) or change it to put the series name into the blacklists i shall do this via a hotfix.

Link to comment
Share on other sites

Stroudy

I've been searching for something similar to this for Emby but nothing quite hits my requirements.
I'm sure like many others, deleting from Emby only allows the Arrs to re-download them once they figure out the files are missing.

I also don't want to delete everything that's been watched. Sometimes I like to revisit the good content.
I'm sure there are also users that have personal content mixed into their libraries also.

I'm not sure what there currently is in Emby to indicate unwanted content other than moving content into a specific playlist or collection which I'm sure is available on all platforms. (Although I suspect that collections will disappear one there is no content left)
How much time and effort would it be for you to build a feature that will only delete the content from a specific playlist?
So the scenario would typically be:

Watch the content > Don't like it > Move into the "Unwanted" playlist > Script deletes the files + Unmonitors on Arrs

Link to comment
Share on other sites

jaycedk

Arr's already have this funktion

Sonarr

image.png.0fc756566155f117c75f30c469a5d86c.png

Radarr

image.png.201521529f00bc602bc65b6dd967deb8.png

Readarr

image.png.98e5caeb78f1cdbdb61f79a4bff7e5bf.png

Lidarr does not to my knowledge. 

  • Agree 1
Link to comment
Share on other sites

Stroudy
16 minutes ago, jaycedk said:

Arr's already have this funktion

Sonarr

image.png.0fc756566155f117c75f30c469a5d86c.png

Radarr

image.png.201521529f00bc602bc65b6dd967deb8.png

Readarr

image.png.98e5caeb78f1cdbdb61f79a4bff7e5bf.png

Lidarr does not to my knowledge. 

Well I'm an idiot...

Been using the Arrs for years, how did I ever miss this.
I guess with the media management, I set it up when I installed the app and never needed to revisit that page...

So in theory.. Delete from Emby and Arrs will auto unmonitor...

I just tried my theory, works perfectly, dam I've spent so many months searching for the solution when it was right in my face all this time..

Edited by Stroudy
Update
Link to comment
Share on other sites

amateurgod
44 minutes ago, Stroudy said:

I've been searching for something similar to this for Emby but nothing quite hits my requirements.
I'm sure like many others, deleting from Emby only allows the Arrs to re-download them once they figure out the files are missing.

I also don't want to delete everything that's been watched. Sometimes I like to revisit the good content.
I'm sure there are also users that have personal content mixed into their libraries also.

I'm not sure what there currently is in Emby to indicate unwanted content other than moving content into a specific playlist or collection which I'm sure is available on all platforms. (Although I suspect that collections will disappear one there is no content left)
How much time and effort would it be for you to build a feature that will only delete the content from a specific playlist?
So the scenario would typically be:

Watch the content > Don't like it > Move into the "Unwanted" playlist > Script deletes the files + Unmonitors on Arrs

This would be possible by just favouriting what you want to keep in emby,

however this script is more for those who like me have personal content not in sonarr and not in a folder managed by sonarr so you can just blacklist the path to the personal files or turn emby delete to false and then it can only delete the content thats in sonarr.

the script is more for people with limited storage capabilities who want to automate the deletion and unmonitoring of watched shows to clear up disk space 

  • Like 1
Link to comment
Share on other sites

amateurgod
Posted (edited)

Minor update to V2

I bring you V2.2.0

https://github.com/Amateur-God/EmbyArrSync/releases/tag/v2.2.0

What's Changed

Improved functionality of the Favourite handling, it now handles TV shows and movies separately and it now adds the series name to blacklisted TV Shows and movie Name to blacklisted movies along with the path to blacklisted paths for both, this wasn't necessary but was added as a fallback.

Added IGNORE_FAVOURITES as an env variable so people can set this to false if they want to disable the script ignoring/blacklisting favourites (Default behaviour is true)

Improved the functions to get TVDB and TMDBID which are used by sonarr/radarr functions to find the correct show/movie, it will now check the items path for tvdbid-Number and tmdbid-Number which if you are following the recommended naming guides and are using sonarr/radarr to rename them then these should be found in the path, however if these aren't found in the path it will fallback to calling the TVDB and TMDB APIs to query them for the ID.

This was done to limit the possibility of getting the wrong ID and to limit the number of API calls made to TVDB and TMDB

Edited by amateurgod
added new link
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...