Jump to content

Emby Media Clean - Delete Watched Video


Recommended Posts

  • 3 weeks later...

The latest version stopped deleting files, I'm getting this in the log

 

:*[DELETE] -   Movie - 
:*[DELETE] -   Movie - 
:*[DELETE] -   Movie - 
:[KEEPING] - Episode - 
:[KEEPING] - Episode - 
:[KEEPING] - Episode -
:[KEEPING] - Episode - 
Traceback (most recent call last):
  File "C:\apps\embycleaner\media_cleaner.py", line 436, in <module>
    deleteItems=get_items(cfg.server_url, cfg.user_key, cfg.access_token)
  File "C:\apps\embycleaner\media_cleaner.py", line 224, in get_items
    (cut_off_date_episode > parse(item['UserData']['LastPlayedDate'])) and
 
 
Edit: I got it to work again, reinstalled some stuff, not sure what did it. One thing I did notice, the first time when creating a config (Windows, cmd) cmd can't be run as admin, it will fail. After the config is created it does not seem to matter.
Edited by Crowley_00
Link to post
Share on other sites

 

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

 

Hey, I have the same error with python 3.5.3

Link to post
Share on other sites

I have not yet been able to figure out a way to get this working with python 3.5.  This bug looks like it is specific to 3.5 and earlier and at the moment I only have a machines with 3.6+.  Sorry, I haven't had too much time to work on this with other commitments, but I will try to get it working once I have time.

 

As a work around can you try creating an empty file called "media_cleaner_config.py".  It should then at least get past the import and then prompt you to create the config file automatically.

  • Like 1
Link to post
Share on other sites
Michael Poulsen

I have not yet been able to figure out a way to get this working with python 3.5.  This bug looks like it is specific to 3.5 and earlier and at the moment I only have a machines with 3.6+.  Sorry, I haven't had too much time to work on this with other commitments, but I will try to get it working once I have time.

 

As a work around can you try creating an empty file called "media_cleaner_config.py".  It should then at least get past the import and then prompt you to create the config file automatically.

Almost worked, but get this error now

 

Traceback (most recent call last):
  File "./media_cleaner.py", line 435, in <module>
    deleteItems=get_items(cfg.server_url, cfg.user_key, cfg.access_token)
  File "./media_cleaner.py", line 196, in get_items
    data = json.loads(source)
  File "/usr/lib/python3.5/json/__init__.py", line 312, in loads
    s.__class__.__name__))
TypeError: the JSON object must be str, not 'bytes'
Link to post
Share on other sites

Thanks for your efforts on this glaring omission within Emby.

 

With the latest Python (v3.8.1) installed I get the following...

 

Traceback (most recent call last):
  File "D:\Kurosh\Downloads\media_cleaner-master\media_cleaner.py", line 8, in <
module>
    from dateutil.parser import parse
ModuleNotFoundError: No module named 'dateutil'

Link to post
Share on other sites
nojstevens

Hello, this script is exactly what im lookin for. I almost have it working but im getting the following error

 

I have Python 3.7.5 on Ubuntu 18.0.4. Emby is dockerized

 

Any ideas? I've tried to replace apt_pkg

 

thank you

 

Jon

 

-----------------------------------------------------------

Get List Of Watched Media

-----------------------------------------------------------

:[KEEPING] - Episode - My Mad Fat Diary - Voodoo - Watched 50 days ago - Favorite: False - EpisodeID: 10600

:[KEEPING] - Episode - The Little Drummer Girl - Episode 3 - Watched 44 days ago - Favorite: True - EpisodeID: 1657

:[KEEPING] -   Movie - 3 Women - Watched 48 days ago - Favorite: False - MovieID: 57

Traceback (most recent call last):

  File "./media-cleaner.py", line 436, in <module>

    deleteItems=get_items(cfg.server_url, cfg.user_key, cfg.access_token)

  File "./media-cleaner.py", line 224, in get_items

    (cut_off_date_episode > parse(item['UserData']['LastPlayedDate'])) and

KeyError: 'LastPlayedDate'

Error in sys.excepthook:

Traceback (most recent call last):

  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook

    from apport.fileutils import likely_packaged, get_recent_crashes

  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>

    from apport.report import Report

  File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>

    import apport.fileutils

  File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>

    from apport.packaging_impl import impl as packaging

  File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in <module>

    import apt

  File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>

    import apt_pkg

ModuleNotFoundError: No module named 'apt_pkg'

 

Original exception was:

Traceback (most recent call last):

  File "./media-cleaner.py", line 436, in <module>

    deleteItems=get_items(cfg.server_url, cfg.user_key, cfg.access_token)

  File "./media-cleaner.py", line 224, in get_items

    (cut_off_date_episode > parse(item['UserData']['LastPlayedDate'])) and

KeyError: 'LastPlayedDate'

Edited by nojstevens
Link to post
Share on other sites

Thanks, got it all working by pip install python-dateutil (and uninstalling Python 2).

 

Something isn't right though as I when doing the dry run it says it's going to DELETE episodes which it should ignore as they're favourited. I've checked everything I can think of. I've logged into Emby as the user the script is set to track and marked WHOLE SERIES as favourites, which do appear in the Emby GUI under favourites. However the script (with the config below) states it will delete some (but strangely not all) episodes within various series. According to Emby the WHOLE SERIES (and all episodes within it) are favourited however when the script looks this up, it gets a mixed result as to which episodes are favourites as in the log it says "Favorite: False" when AFAIK it should be TRUE.

 

not_played_age_movie=-1
not_played_age_episode=7
not_played_age_video=-1
not_played_age_trailer=7
remove_files=0
ignore_favorites_movie=1
ignore_favorites_episode=1
ignore_favorites_video=1
ignore_favorites_trailer=1

 

Manually setting the targeted episode individually as a favourite (instead of just the parent series) does appear to resolve this problem as then in the log it reverts to KEEPING and "Favorite: True" but it would be unfeasible to individually set each episode I didn't want it to delete and maintain that. Am I doing something wrong? It ignores movies (as desired) and most but not all required TV episodes which is my main use case.

Edited by Kurosh
Link to post
Share on other sites
nojstevens

I have emby running in a docker but I am trying to run this on the host ubuntu and i am getting the error

 

  File "./media_cleaner.py", line 436, in <module>

    deleteItems=get_items(cfg.server_url, cfg.user_key, cfg.access_token)

 

Could this be because the path to my media for Ubuntu is not the same path that Emby sees?

 

If not, i am thinking this script is not useable with Emby docker as i can't run it inside the docker and outside the media paths will not be the same.

 

Am i on the right track here? Can anyone think how i might be able to use this script with my setup

 

Thanks

 

Jon

Edited by nojstevens
Link to post
Share on other sites
Floflobel

Hello, this script is exactly what im lookin for. I almost have it working but im getting the following error

 

I have Python 3.7.5 on Ubuntu 18.0.4. Emby is dockerized

 

Any ideas? I've tried to replace apt_pkg

 

thank you

 

Jon

 

-----------------------------------------------------------

Get List Of Watched Media

-----------------------------------------------------------

:[KEEPING] - Episode - My Mad Fat Diary - Voodoo - Watched 50 days ago - Favorite: False - EpisodeID: 10600

:[KEEPING] - Episode - The Little Drummer Girl - Episode 3 - Watched 44 days ago - Favorite: True - EpisodeID: 1657

:[KEEPING] -   Movie - 3 Women - Watched 48 days ago - Favorite: False - MovieID: 57

Traceback (most recent call last):

  File "./media-cleaner.py", line 436, in <module>

    deleteItems=get_items(cfg.server_url, cfg.user_key, cfg.access_token)

  File "./media-cleaner.py", line 224, in get_items

    (cut_off_date_episode > parse(item['UserData']['LastPlayedDate'])) and

KeyError: 'LastPlayedDate'

Error in sys.excepthook:

Traceback (most recent call last):

  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook

    from apport.fileutils import likely_packaged, get_recent_crashes

  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>

    from apport.report import Report

  File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>

    import apport.fileutils

  File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>

    from apport.packaging_impl import impl as packaging

  File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in <module>

    import apt

  File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>

    import apt_pkg

ModuleNotFoundError: No module named 'apt_pkg'

 

Original exception was:

Traceback (most recent call last):

  File "./media-cleaner.py", line 436, in <module>

    deleteItems=get_items(cfg.server_url, cfg.user_key, cfg.access_token)

  File "./media-cleaner.py", line 224, in get_items

    (cut_off_date_episode > parse(item['UserData']['LastPlayedDate'])) and

KeyError: 'LastPlayedDate'

 

I've analyzed the problem a bit and it seems to come from the fact that the API doesn't give the "LastPlayedDate" parameter. I don't know why Emby didn't save this parameter.

 

post-259220-0-48603900-1578357669_thumb.png

Edited by Floflobel
Link to post
Share on other sites

I've analyzed the problem a bit and it seems to come from the fact that the API doesn't give the "LastPlayedDate" parameter. I don't know why Emby didn't save this parameter.

 

attachicon.gifemby.png

Yes that is right.  I had not seen that before where the LastPlayedDate value is not there but the play count is 1.  I will add some logic to ignore those since I won't be able to detect if it is past the cutoff.

Link to post
Share on other sites

I have emby running in a docker but I am trying to run this on the host ubuntu and i am getting the error

 

  File "./media_cleaner.py", line 436, in <module>

    deleteItems=get_items(cfg.server_url, cfg.user_key, cfg.access_token)

 

Could this be because the path to my media for Ubuntu is not the same path that Emby sees?

 

If not, i am thinking this script is not useable with Emby docker as i can't run it inside the docker and outside the media paths will not be the same.

 

Am i on the right track here? Can anyone think how i might be able to use this script with my setup

 

Thanks

 

Jon

Is there any more to the error your getting?

 

I run Emby in docker and am able to get it to delete fine.  One thing though, do you have docker setup with read and write permissions to the folder or read only?

Link to post
Share on other sites

Thanks, got it all working by pip install python-dateutil (and uninstalling Python 2).

 

Something isn't right though as I when doing the dry run it says it's going to DELETE episodes which it should ignore as they're favourited. I've checked everything I can think of. I've logged into Emby as the user the script is set to track and marked WHOLE SERIES as favourites, which do appear in the Emby GUI under favourites. However the script (with the config below) states it will delete some (but strangely not all) episodes within various series. According to Emby the WHOLE SERIES (and all episodes within it) are favourited however when the script looks this up, it gets a mixed result as to which episodes are favourites as in the log it says "Favorite: False" when AFAIK it should be TRUE.

 

not_played_age_movie=-1

not_played_age_episode=7

not_played_age_video=-1

not_played_age_trailer=7

remove_files=0

ignore_favorites_movie=1

ignore_favorites_episode=1

ignore_favorites_video=1

ignore_favorites_trailer=1

 

Manually setting the targeted episode individually as a favourite (instead of just the parent series) does appear to resolve this problem as then in the log it reverts to KEEPING and "Favorite: True" but it would be unfeasible to individually set each episode I didn't want it to delete and maintain that. Am I doing something wrong? It ignores movies (as desired) and most but not all required TV episodes which is my main use case.

Does the output as it is going through all the episodes show that the episode is a favorite or not when displaying the items?

Link to post
Share on other sites
nojstevens

Is there any more to the error your getting?

 

I run Emby in docker and am able to get it to delete fine.  One thing though, do you have docker setup with read and write permissions to the folder or read only?

 

Sorry, yes there was some more, here it is attached. The docker also has rw permssions to the share with my Movies and TV

 

Thank you for looking at this

 

Jon

 

Get List Of Watched Media

-----------------------------------------------------------

:[KEEPING] - Episode - My Mad Fat Diary - Voodoo - Watched 53 days ago - Favorite: False - EpisodeID: 10600

:[KEEPING] - Episode - The Little Drummer Girl - Episode 3 - Watched 47 days ago - Favorite: True - EpisodeID: 1657

:[KEEPING] -   Movie - 3 Women - Watched 50 days ago - Favorite: False - MovieID: 57

:[KEEPING] -   Movie - The Inbetweeners Movie - Watched <1 day ago - Favorite: False - MovieID: 318445

Traceback (most recent call last):

  File "./media_cleaner.py", line 436, in <module>

    deleteItems=get_items(cfg.server_url, cfg.user_key, cfg.access_token)

  File "./media_cleaner.py", line 224, in get_items

    (cut_off_date_episode > parse(item['UserData']['LastPlayedDate'])) and

KeyError: 'LastPlayedDate'

Edited by nojstevens
Link to post
Share on other sites

Sorry, yes there was some more, here it is attached. The docker also has rw permssions to the share with my Movies and TV

 

Thank you for looking at this

 

Jon

 

Get List Of Watched Media

-----------------------------------------------------------

:[KEEPING] - Episode - My Mad Fat Diary - Voodoo - Watched 53 days ago - Favorite: False - EpisodeID: 10600

:[KEEPING] - Episode - The Little Drummer Girl - Episode 3 - Watched 47 days ago - Favorite: True - EpisodeID: 1657

:[KEEPING] -   Movie - 3 Women - Watched 50 days ago - Favorite: False - MovieID: 57

:[KEEPING] -   Movie - The Inbetweeners Movie - Watched <1 day ago - Favorite: False - MovieID: 318445

Traceback (most recent call last):

  File "./media_cleaner.py", line 436, in <module>

    deleteItems=get_items(cfg.server_url, cfg.user_key, cfg.access_token)

  File "./media_cleaner.py", line 224, in get_items

    (cut_off_date_episode > parse(item['UserData']['LastPlayedDate'])) and

KeyError: 'LastPlayedDate'

Looks like you are having the same issue as the other person.  The item is marked as having been played, but for some reason the LastPlayedDate value is not set.  So when i try to query that value it causes it to fail.  I had not seen that before so hadn't accounted for that. 

 

I will try to push an update that fixes that as soon as I can.

Link to post
Share on other sites
nojstevens

I watch via MrMC using the Emby plugin - maybe that is why it is not recoring LastPlayedDate? it was last played in another media player, but using Emby as the server.?

 

Jon

Link to post
Share on other sites

Does the output as it is going through all the episodes show that the episode is a favorite or not when displaying the items?

It shows that it's not a favorite (favorite: false) when in fact it is a favourite in the Emby UI. It does this for many episodes within a series. Only fix I've found is to manually go to the episodes shown in the script output and individually mark those episodes as favorites. According to the script (not the Emby UI) those specific episodes don't inherit the favorites tag when I marked the whole series.

Edited by Kurosh
Link to post
Share on other sites
  • 1 month later...

It shows that it's not a favorite (favorite: false) when in fact it is a favourite in the Emby UI. It does this for many episodes within a series. Only fix I've found is to manually go to the episodes shown in the script output and individually mark those episodes as favorites. According to the script (not the Emby UI) those specific episodes don't inherit the favorites tag when I marked the whole series.

Hello,

 

Any response to this? If within the Emby UI I go to the top level an entire TV show and mark / tick that as a favourite, it doesn't show that each and every episode within that TV show is a favourite, hence in the output of your python script it says each particular episode is "favorite: false". As mentioned, only way I've found around this (which isn't fool proof as you'd have to remember to do it for each and every new episode you want to ignore) is to manually mark each episode as a favourite.

Edited by Kurosh
Link to post
Share on other sites

Cool, thanks for sharing.

Hi Luke,

 

Any idea why if within the Emby UI I go to the top level an entire TV show and mark / tick that as a favourite, it doesn't show that each and every episode within that TV show is a favourite? This is causing issues with this script which is looking at the "episode level" of whether something is a favourite or not instead of the "TV Show level".

 

Not sure if this is intentional (therefore the script should be changed to look at the TV show level) or is an Emby bug?

Edited by Kurosh
Link to post
Share on other sites

I can tell you emby does distinguish between a series being a favourite and episodes being favourites.  A series being a fav does not mark all episodes of that series as favs.  I ran into this when developing my similar tool and had to add an extra option to allow filtering by series fav as well.  With my tool, you can use the --ignore-fav-series option to prevent deleting any episodes where the series is marked as a fav regardless of whether or not the episodes themselves are marked as favs.

  • Like 1
Link to post
Share on other sites
  • 10 months later...
MagnusL3D
Traceback (most recent call last):
  File "media_cleaner.py", line 594, in <module>
    test=cfg.DEBUG
AttributeError: module 'media_cleaner_config' has no attribute 'DEBUG'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "media_cleaner.py", line 725, in <module>
    generate_config()
  File "media_cleaner.py", line 184, in generate_config
    os.chdir(script_dir)
FileNotFoundError: [Errno 2] No such file or directory: ''

Getting this error on python 3.8.2 

 

Link to post
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...