Michael Poulsen 4 Posted November 27, 2019 Share Posted November 27, 2019 I know why, the module error is because you use version 3.6 and this error is not included in 3.5.3. can someone rewrite for python 3 5 3? Link to comment Share on other sites More sharing options...
Crowley_00 1 Posted December 17, 2019 Share Posted December 17, 2019 (edited) 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 December 17, 2019 by Crowley_00 Link to comment Share on other sites More sharing options...
Thuzad 42 Posted December 19, 2019 Share Posted December 19, 2019 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 comment Share on other sites More sharing options...
jpc82 16 Posted December 19, 2019 Author Share Posted December 19, 2019 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. 1 Link to comment Share on other sites More sharing options...
Michael Poulsen 4 Posted December 22, 2019 Share Posted December 22, 2019 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 comment Share on other sites More sharing options...
Kurosh 16 Posted December 29, 2019 Share Posted December 29, 2019 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 parseModuleNotFoundError: No module named 'dateutil' Link to comment Share on other sites More sharing options...
jpc82 16 Posted December 29, 2019 Author Share Posted December 29, 2019 Take a look here: https://stackoverflow.com/questions/20853474/importerror-no-module-named-dateutil-parser You probably need to do something like: pip install python-dateutil 1 Link to comment Share on other sites More sharing options...
Michael Poulsen 4 Posted December 30, 2019 Share Posted December 30, 2019 Reolaced Debian with Ubuntu server 18.04, now it works Link to comment Share on other sites More sharing options...
Michael Poulsen 4 Posted December 30, 2019 Share Posted December 30, 2019 Replaced Link to comment Share on other sites More sharing options...
nojstevens 0 Posted January 4, 2020 Share Posted January 4, 2020 (edited) 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 January 4, 2020 by nojstevens Link to comment Share on other sites More sharing options...
Kurosh 16 Posted January 4, 2020 Share Posted January 4, 2020 (edited) 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=-1not_played_age_episode=7not_played_age_video=-1not_played_age_trailer=7remove_files=0ignore_favorites_movie=1ignore_favorites_episode=1ignore_favorites_video=1ignore_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 January 4, 2020 by Kurosh Link to comment Share on other sites More sharing options...
nojstevens 0 Posted January 4, 2020 Share Posted January 4, 2020 (edited) 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 January 4, 2020 by nojstevens Link to comment Share on other sites More sharing options...
Thuzad 42 Posted January 7, 2020 Share Posted January 7, 2020 (edited) 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. Edited January 7, 2020 by Floflobel Link to comment Share on other sites More sharing options...
jpc82 16 Posted January 7, 2020 Author Share Posted January 7, 2020 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. emby.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 comment Share on other sites More sharing options...
jpc82 16 Posted January 7, 2020 Author Share Posted January 7, 2020 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 comment Share on other sites More sharing options...
jpc82 16 Posted January 7, 2020 Author Share Posted January 7, 2020 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 comment Share on other sites More sharing options...
nojstevens 0 Posted January 7, 2020 Share Posted January 7, 2020 (edited) 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 January 7, 2020 by nojstevens Link to comment Share on other sites More sharing options...
jpc82 16 Posted January 7, 2020 Author Share Posted January 7, 2020 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 comment Share on other sites More sharing options...
nojstevens 0 Posted January 7, 2020 Share Posted January 7, 2020 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 comment Share on other sites More sharing options...
Kurosh 16 Posted January 7, 2020 Share Posted January 7, 2020 (edited) 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 January 7, 2020 by Kurosh Link to comment Share on other sites More sharing options...
Kurosh 16 Posted March 3, 2020 Share Posted March 3, 2020 (edited) 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 March 3, 2020 by Kurosh Link to comment Share on other sites More sharing options...
Kurosh 16 Posted March 3, 2020 Share Posted March 3, 2020 (edited) 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 March 3, 2020 by Kurosh Link to comment Share on other sites More sharing options...
Slugger 9 Posted March 10, 2020 Share Posted March 10, 2020 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. 1 Link to comment Share on other sites More sharing options...
MagnusL3D 1 Posted January 10, 2021 Share Posted January 10, 2021 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 comment Share on other sites More sharing options...
hieroglyph 5 Posted October 9, 2021 Share Posted October 9, 2021 (edited) Update: @jpc82 has mentioned here and on github they may have other commitments not allowing them to follow this as closely as they may want to. For a while I was helping where I could by pushing updates based on @jpc82's original script to clara-j / media_cleaner . @jpc82 let me know if/when you come back and we can merge the updates from my fork into your original repo. Several updates have been made since you last merged my changes. @MagnusL3D Were you able to get this to working? If not, try using the repo below. I have been running this with Python3.8 at least since 2021-May. @Kurosh @Slugger The script should now handle favorites correctly when the favorite is a parent item, e.g. a TV series, then all children below it, e.g. seasons and episodes, will be preserved. See repo below. @nojstevens The script should now handle when the LastPlayedDate is missing. Instead of crashing, it should now print the output for that item with the "Watched X days ago" data omitted. See repo below. Updated Repo: terrelsa13 / media_cleaner Edited October 9, 2021 by hieroglyph Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now