Jump to content

Emby Media Clean - Delete Watched Video


jpc82

Recommended Posts

Hi, I created a python script that will look for all watched content for a specific user. If the last played date is past the cut off date it will delete the file.

I built this for myself and it works good enough for me, but I have only tested it on my system (ubuntu 18.04) with my server. So no guarantee it will work for everyone, and since it can delete files have a backup to be safe. By default it does not delete files until you modify the config file to be safer.

It first lists all the files, then will list the files that will be deleted.

On first run it will ask you some questions to generate the config file, or you can create it manually

Here is the script if anyone else is interested in trying it out: https://github.com/clara-j/media_cleaner

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

Kurosh asked for the ability to treat TV vs Movies different.

 

For my use case I don't care and delete all files the same.  But I will try to add the ability to configure if you want Episodes, Movies or Videos to be deleted or ignored.

  • Like 1
Link to comment
Share on other sites

I have pushed the new version.  Config file will need to be re-generated.  You can now have the following three options

 

video_action='delete'
movie_action='delete'
episode_action='delete'

 

Anything other then delete will ignore that content type.

  • Like 1
Link to comment
Share on other sites

mastrmind11

@@Luke, what is the timeframe to get something like this bundled w/ Emby?  I know it's been a FR for quite some time (2 years now?).  The ability to remove watched episodes at the series level is the most basic DVR feature out there.

Link to comment
Share on other sites

I have pushed the new version.  Config file will need to be re-generated.  You can now have the following three options

 

video_action='delete'

movie_action='delete'

episode_action='delete'

 

Anything other then delete will ignore that content type.

Thanks for this, so "movie_action" = movies and "episode_action" = TV shows. Therefore what is "video_action"?

Link to comment
Share on other sites

This exact script isn't getting bundled. We would just do our feature for it.

Any idea on a timeframe for this feature though? The feature was initially requested in June 2014 :)

Edited by Kurosh
Link to comment
Share on other sites

Thanks for this, so "movie_action" = movies and "episode_action" = TV shows. Therefore what is "video_action"?

 

video is for things in the home video or other video category.  I use that for random videos I download off the internet like youtube videos where I don't have metadata for.

Link to comment
Share on other sites

  • 1 month later...

I have pushed a couple of new updates.  Some users were getting error depending on the results their servers were returning.  That should all be fixed now, if anyone is still getting errors let me know.

 

I also added a new option to ignore favorite files so they don't get deleted.

Link to comment
Share on other sites

  • 2 weeks later...
Michael Poulsen

excactly what i have been looking for, but it trows me this error in debian stretch (openmediavault)

 

i have both python 2.7 ant python 3 an have tried running with python3 command (Anyone that can help me)

 

 Traceback (most recent call last):
  File "./media_cleaner.py", line 154, in <module>
    import media_cleaner_config as cfg
ImportError: No module named 'media_cleaner_config'
 
During handling of the above exception, another exception occurred:
 
Traceback (most recent call last):
  File "./media_cleaner.py", line 162, in <module>
    except (AttributeError, ModuleNotFoundError):
NameError: name 'ModuleNotFoundError' is not defined
Link to comment
Share on other sites

Can you try downloading the latest version from git and trying again.  I can't seem to re-create this issue.

 

Also, can you let me know what version of python3 you are using with the following: python3 --version

Link to comment
Share on other sites

Michael Poulsen

python 3.5.3

this is the exact error

 

python3 /srv/dev-disk-by-label-Data/Scripts/media_cleaner.py
Traceback (most recent call last):
  File "/srv/dev-disk-by-label-Data/Scripts/media_cleaner.py", line 154, in <module>
    import media_cleaner_config as cfg
ImportError: No module named 'media_cleaner_config'
 
During handling of the above exception, another exception occurred:
 
Traceback (most recent call last):
  File "/srv/dev-disk-by-label-Data/Scripts/media_cleaner.py", line 162, in <module>
    except (AttributeError, ModuleNotFoundError):
NameError: name 'ModuleNotFoundError' is not defined
Link to comment
Share on other sites

Crowley_00

Thank you for this, just what I needed. One thing I think would be useful is logging to a file with an indicator how many days ago a file was watched. The current date format in the output when running the script is kind of hard to read.

Link to comment
Share on other sites

@@Michael sorry but I can't seem to re-create the issue your having.  Are you using Windows, Linux or Mac?

 

@@Crowley_00 I can look into creating a log file.  So your looking for a log file that just appends the file name, date watched for any file deleted.  I assume you would want the log file to append between runs.

Link to comment
Share on other sites

Crowley_00
I like to automate everything and logs help me check what the scripts have been doing.

 

I think it would be useful to list all the watched files, and separate deleted. Something like:

 

Time ran

 

Watched:

 

Series X S01E01 (7 days ago)

Series X S01E02 (6 days ago)

Series X S01E03 (5 days ago)

 

Deleted: 

 

Series X S01E01 (7 day setting in the config file)

 

Append would be fine, I could always delete the log if it gets too big. So pretty similar what the script outputs now but a little easier to read. Right now it does not seem to show series name and the date format could be simpler.

 

But this is all just wishful thinking, the script is working fine for me as is. Thanks again!

Edited by Crowley_00
Link to comment
Share on other sites

Ok, so your not looking for a actual log from what your saying.  Your looking for better/cleaner output.  Let me work on that first.  This version still has a fair bit of debug info just as part of my testing.  I can move that into the actual debug option so it is better to view for normal runs.

Link to comment
Share on other sites

Here is what I have working right now for a cleaned up output.  Let me know if this is more what you are looking for:

<VIDEO NAME> (<VIDEO TYPE>)
    Last Played: 10/23/2019
    Days ago: 28
    Favorite: Yes
    Result: Keep

<VIDEO NAME> (<VIDEO TYPE>)
    Last Played: 11/15/2019
    Days ago: 5
    Favorite: No
    Result: Keep

<VIDEO NAME> (<VIDEO TYPE>)
    Last Played: 11/07/2019
    Days ago: 13
    Favorite: No
    Result: Delete


Items to be deleted
    - <VIDEO NAME> - 11/07/2019 (Days ago 13)
  • Like 1
Link to comment
Share on other sites

Michael Poulsen

@@Michael sorry but I can't seem to re-create the issue your having.  Are you using Windows, Linux or Mac?

 

@@Crowley_00 I can look into creating a log file.  So your looking for a log file that just appends the file name, date watched for any file deleted.  I assume you would want the log file to append between runs.

im using debian stretch and still same error

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...