clara-j / media_cleaner

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

problem jellyfin docker #5

Open spupuz opened 4 years ago

spupuz commented 4 years ago

not working for me Jellyfin is inside a docker image:

root@openmediavault:~# ./media_cleaner.py


Start...

Cleaning media for server at: http://192.168.1.xxx:8096



Get List Of Watched Media


Traceback (most recent call last):

File "./media_cleaner.py", line 436, in

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

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

item_details=item['Type'] + ' - ' + item['SeriesName'] + ' - ' + item['Name'] + ' - ' + get_days_since_watched(item['UserData']['LastPlayedDate']) + ' - Favorite: ' + str(item['UserData']['IsFavorite']) + ' - ' + 'EpisodeID: ' + item['Id']

File "./media_cleaner.py", line 167, in get_days_since_watched

date_time_last_watched = datetime.strptime(date_last_played, '%Y-%m-%dT%H:%M:%S.0000000+00:00')

File "/usr/lib/python3.7/_strptime.py", line 577, in _strptime_datetime

tt, fraction, gmtoff_fraction = _strptime(data_string, format)

File "/usr/lib/python3.7/_strptime.py", line 359, in _strptime

(data_string, format))

ValueError: time data '2020-03-24T06:52:14.1311383Z' does not match format '%Y-%m-%dT%H:%M:%S.0000000+00:00'

root@openmediavault:~#

terrelsa13 commented 4 years ago

I do not run Jellyfin, so I cannot say for sure. But it looks like the way the date_last_played time formatting returned for jellyfin may be different from how it is returned for emby.

Emby: '2020-03-24T06:52:14.1311383+00:00' Jelly: '2020-03-24T06:52:14.1311383Z'

This is the line with the formatting: date_time_last_watched = datetime.strptime(date_last_played, '%Y-%m-%dT%H:%M:%S.0000000+00:00') Would likely need to allow both formats as valid for this to work for Jelly.

spupuz commented 4 years ago

how can i do that?

terrelsa13 commented 4 years ago

You will have to do a few steps:

Edit x2 Idk why I was making this more difficult than it needs to be. Let me try this again...

  1. In the media_cleaner_config.py file set remove_files=0
  2. In the media_cleaner_config.py file set DEBUG=1
  3. Make sure at least one episode or movie is set as watched by the jellyfin user you entered when you first ran this script.

Now run media_cleaner.

After it has run, if you look in the /path/to/your/media_cleaner, a file called media_cleaner.debug will be there. Open that file. In it you should see lines that start with "LastPlayedDate": following the colon you should see the date-time format jellyfin uses.

For emby it looks like this: "LastPlayedDate": "2020-03-24T06:52:14.1311383+00:00" hence the formatting I mentioned above. This is used in the _get_days_sincewatched() function in media_cleaner.py to show how many days ago something was watched.

spupuz commented 4 years ago

debug log file is not present also if debug set to 1

terrelsa13 commented 4 years ago

Ok. Set the config file to have remove_files=0 and DEBUG=1 like we did above. Then we will simplify the _get_days_sincewatched() function so it just returns a zero. We will see how far that gets us.

Open the media_cleaner.py script and make the changes shown below.

Change this:

To this:

spupuz commented 4 years ago

Start... Cleaning media for server at: http://xxxxxxxxxxxxxxxxxxx:8096


Get List Of Watched Media

http://xxxxxxxxxxxx:8096/emby/Users/xxxxxxxxxxxxxxxxxxxxxxxxxxxxx/Items?Recursive=true&IsPlayed=true&api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx :[DELETE] - Episode - The IT Crowd - Fifty-fifty - 0 - Favorite: False - EpisodeID: 02f9d0bd1f9d542b7b7b8d2a1e1fddef :[KEEPING UNKNOWN MEDIA TYPE] - Audio - Undisclosed Desires - 0 - Favorite: False - AudioID: 070e6cd3184627fa33eac341ccb8f21b :[DELETE] - Episode - La casa di carta - Episodio 7 - 0 - Favorite: False - EpisodeID: 0af4b9a89735d1802c340cd10c8aa47a :[KEEPING UNKNOWN MEDIA TYPE] - Audio - Viva! - 0 - Favorite: False - AudioID: 0b90c914a1d23db60253315683f6bd77 :[KEEPING UNKNOWN MEDIA TYPE] - Audio - Stuck With Me - 0 - Favorite: False - AudioID: 0bef5e28aa0ea1a880e612a8676c20dd :[KEEPING UNKNOWN MEDIA TYPE] - Audio - Like Suicide (Rehearsal Version) - 0 - Favorite: False - AudioID: 108e179fce787a41014f99f57cca3e19 :[KEEPING UNKNOWN MEDIA TYPE] - Audio - Medley: I Still Haven’t Found What I’m Looking For / Exodus (live) - 0 - Favorite: False - AudioID: 1804601771680697c62414ad71137720 :[KEEPING UNKNOWN MEDIA TYPE] - Audio - Picnic all'inferno - 0 - Favorite: False - AudioID: 18509262b24ca8b764bf602a050100e7 :[DELETE] - Episode - La casa di carta - Episodio 1 - 0 - Favorite: False - EpisodeID: 1a7ba7f8fadd777fda83c781c283b8bc :[DELETE] - Episode - The Good Doctor - Heartbreak - 0 - Favorite: False - EpisodeID: 1b096e11d8fdd3f919f0c6fdd45d2be9 :[DELETE] - Episode - La casa di carta - Il matrimonio di Berlino - 0 - Favorite: False - EpisodeID: 1cb681dfc93497b9548554ee99a8066b :[KEEPING] - Movie - Loving Vincent - 0 - Favorite: False - MovieID: 1ec0b45e1d56130beed25f8e992a6c3e :[KEEPING UNKNOWN MEDIA TYPE] - Audio - Under It All - 0 - Favorite: False - AudioID: 2265fd14a04625830719b846d0694159 :[DELETE] - Episode - The Good Doctor - I Love You - 0 - Favorite: False - EpisodeID: 235a31c769b9b420036a46f65a5ee9b5 :[KEEPING UNKNOWN MEDIA TYPE] - Audio - Spirito - 0 - Favorite: False - AudioID: 242a2758547d4e16b95dafbba57b3767 :[DELETE] - Episode - The Good Doctor - Unsaid - 0 - Favorite: False - EpisodeID: 25ae1d09f6e3f10e9a8c1dbbd6fd3345 :[DELETE] - Episode - La casa di carta - Il matrimonio di Berlino - 0 - Favorite: False - EpisodeID: 2691480684a6fbe1d427c349f23dfd87 :[DELETE] - Episode - Outlander - Mercy Shall Follow Me - 0 - Favorite: False - EpisodeID: 26fccd74db65bc4729cb926e6b4dea98 :[KEEPING UNKNOWN MEDIA TYPE] - Audio - Divine - 0 - Favorite: False - AudioID: 3189a30ad26183e9577d1e756b9ff30e :[DELETE] - Episode - La casa di carta - Episodio 8 - 0 - Favorite: False - EpisodeID: 33cb1e73397e827183b93fb21b4d3388 :[KEEPING UNKNOWN MEDIA TYPE] - Audio - St. John - 0 - Favorite: False - AudioID: 35c1a5bb9bd5631eb33681ce32fdc8d5 :[KEEPING UNKNOWN MEDIA TYPE] - Audio - Oh, Pretty Woman - 0 - Favorite: False - AudioID: 3a3eee21d34fa275102b9bb06df9a3b9 :[DELETE] - Episode - Outlander - Monsters and Heroes - 0 - Favorite: False - EpisodeID: 456faed5a633441c96d4be4272acb905 :[DELETE] - Episode - La casa di carta - Episodio 13 - 0 - Favorite: False - EpisodeID: 45c302aa670ff1a28fdd3504f53d4b6a :[DELETE] - Episode - The Good Doctor - Autopsy - 0 - Favorite: False - EpisodeID: 46c2f51c40da60c8e839052e56fd1e96 :[DELETE] - Episode - Young Sheldon - A Broom Closet and Satan's Monopoly Board - 0 - Favorite: False - EpisodeID: 4855ea565f88fb5816b01d86317c6829 :[KEEPING UNKNOWN MEDIA TYPE] - Audio - The Other Side - 0 - Favorite: False - AudioID: 4956a0673d32c8175361f1e25881d673 :[DELETE] - Episode - La casa di carta - Episodio 3 - 0 - Favorite: False - EpisodeID: 4ce1c4a6ff44bb6dfe94ba69ae55c639 :[KEEPING] - Episode - La casa di carta - Episodio 12 - 0 - Favorite: False - EpisodeID: 4f51ad2c25380296dcd5ec5a7aa6db26 :[KEEPING UNKNOWN MEDIA TYPE] - Audio - Ferro caldo - 0 - Favorite: False - AudioID: 50c2012c342ee55071130de302530e89 :[DELETE] - Episode - La casa di carta - Episodio 4 - 0 - Favorite: False - EpisodeID: 52a3649cd0296c1885543aa007382f9f :[DELETE] - Episode - La casa di carta - Episodio 5 - 0 - Favorite: False - EpisodeID: 54fc76ee1465e2e9538eb29da9034eba :[KEEPING UNKNOWN MEDIA TYPE] - Audio - Smells Like Teen Spirit - 0 - Favorite: False - AudioID: 5bf479cc2bb502553221db72521575df :[DELETE] - Episode - Young Sheldon - Quirky Eggheads and Texas Snow Globes - 0 - Favorite: False - EpisodeID: 5d22c88dcaeb61e01bbe5abfcde3897c :[DELETE] - Episode - The Good Doctor - L'influencer - 0 - Favorite: False - EpisodeID: 5f4efea20c52820342e9b9d4494b234d :[DELETE] - Episode - La casa di carta - Episodio 2 - 0 - Favorite: False - EpisodeID: 5fe20ff6ef96457dd64d79a47e0f8280 :[DELETE] - Episode - La casa di carta - Episodio 11 - 0 - Favorite: False - EpisodeID: 6a51ab692e29efb94dd9bde56fb08a7c :[KEEPING UNKNOWN MEDIA TYPE] - Audio - “40” - 0 - Favorite: False - AudioID: 6a7272ab36d85d51445528a612015742 :[DELETE] - Episode - Young Sheldon - Hobbitses, Physicses and a Ball with Zip - 0 - Favorite: False - EpisodeID: 6e4a9934b9d551f64e1ca0afe69d1570 :[KEEPING UNKNOWN MEDIA TYPE] - Audio - Bound - 0 - Favorite: True - AudioID: 738e33a10bd9ca5970384e15a2b6c92f :[DELETE] - Episode - The Good Doctor - Un cuore spezzato - 0 - Favorite: False - EpisodeID: 744857a22c22295028fcba4e44c69b62 :[DELETE] - Episode - Young Sheldon - An Entrepreneurialist and a Swat on the Bottom - 0 - Favorite: False - EpisodeID: 74c5137c6be3c4bbde4919c7c11884d8 :[DELETE] - Episode - La casa di carta - Episodio 10 - 0 - Favorite: False - EpisodeID: 75ac63eabc2515123821ad3faef507a4 :[KEEPING UNKNOWN MEDIA TYPE] - Audio - Pride (In the Name of Love) - 0 - Favorite: False - AudioID: 7bfe395c919fae3b0da91fa1240d3e37 :[KEEPING UNKNOWN MEDIA TYPE] - Audio - Taksim Blues - 0 - Favorite: False - AudioID: 8e5840a28000bc44b6ee658bad094546 :[DELETE] - Episode - La casa di carta - Episodio 2 - 0 - Favorite: False - EpisodeID: 8ffe4d4d77bf03750558597864efc3ed :[DELETE] - Episode - La casa di carta - Episodio 6 - 0 - Favorite: False - EpisodeID: 965edeb9a5fee7c503bd8d637d80236e :[DELETE] - Episode - La casa di carta - Episodio 9 - 0 - Favorite: False - EpisodeID: 9baaf05aa22eefd5c3cc0a94fedb63e5 :[KEEPING] - Movie - La fuitina sbagliata - 0 - Favorite: False - MovieID: a44f984257489b60e4dff6a24520fa5d :[DELETE] - Episode - La casa di carta - Episodio 6 - 0 - Favorite: False - EpisodeID: a6dd64d66e3561ca3b7a3077c40d8de2 :[DELETE] - Episode - La casa di carta - Episodio 3 - 0 - Favorite: False - EpisodeID: a856bc04d6051183c262e9955b43811a :[KEEPING UNKNOWN MEDIA TYPE] - Audio - The Real Life - 0 - Favorite: False - AudioID: a8deeb68b97d94f4ba6808025b1e1d32 :[DELETE] - Episode - La casa di carta - Episodio 4 - 0 - Favorite: False - EpisodeID: aa1c4010d2a01bc3a68c4d06b2c0f243 :[DELETE] - Episode - The Good Doctor - Fixation - 0 - Favorite: False - EpisodeID: aa74d5beb43588da20bedbcec9fb653f :[DELETE] - Episode - La casa di carta - Episodio 13 - 0 - Favorite: False - EpisodeID: adc3eb281959a9be6706792bf118b3a0 :[DELETE] - Episode - The IT Crowd - La porta rossa - 0 - Favorite: False - EpisodeID: ae91a279954b28782a8fa49e53792f2f :[DELETE] - Episode - La casa di carta - Episodio 9 - 0 - Favorite: False - EpisodeID: b0086b5a0869c631e4ceee893f9b6bfc :[KEEPING UNKNOWN MEDIA TYPE] - Audio - Reality TV - 0 - Favorite: False - AudioID: b0bd39ed2003dfff76b7fb4de011808c :[KEEPING UNKNOWN MEDIA TYPE] - Audio - Pugili fragili - 0 - Favorite: False - AudioID: b24172553cdddea21fb1c6cac77561ed :[DELETE] - Episode - The Good Doctor - Amore e morte - 0 - Favorite: False - EpisodeID: b3339a7766ad6c670448f7773aae216f :[KEEPING] - Episode - La casa di carta - Episodio 12 - 0 - Favorite: False - EpisodeID: b41b9f7be11f98ea60639b5ba3468ba0 :[KEEPING UNKNOWN MEDIA TYPE] - Audio - Stand Away - 0 - Favorite: False - AudioID: b7ea3b95cc55068ac2cb8565f1dbd90e :[KEEPING UNKNOWN MEDIA TYPE] - Audio - Quando canterai la tua canzone - 0 - Favorite: False - AudioID: b82e90030ff989838c5a80f6080796fa :[KEEPING UNKNOWN MEDIA TYPE] - Audio - Ci sei sempre stata - 0 - Favorite: True - AudioID: b8bb4f68abbcb81c24c53950666b54e5 :[KEEPING UNKNOWN MEDIA TYPE] - Audio - Careless Whisper - 0 - Favorite: False - AudioID: bb556bc8c5101cec29c492ce0857bec0 :[DELETE] - Episode - The Good Doctor - Mutazioni - 0 - Favorite: False - EpisodeID: bf80c182f1fcc29476ee46c0191771ec :[DELETE] - Episode - La casa di carta - Episodio 5 - 0 - Favorite: False - EpisodeID: c71a0afb3bd16c05a4d9aa3651393644 :[DELETE] - Episode - La casa di carta - Episodio 11 - 0 - Favorite: False - EpisodeID: c87914c75373b9f7c99a79f8838cc598 :[KEEPING UNKNOWN MEDIA TYPE] - Audio - Starblind - 0 - Favorite: False - AudioID: cbdd11e4819a682c7742da296b3f572f :[KEEPING UNKNOWN MEDIA TYPE] - Audio - Luna dark - 0 - Favorite: False - AudioID: cd78cd5b64b3a8084823e4aeb986a18d :[KEEPING UNKNOWN MEDIA TYPE] - Audio - Pea - 0 - Favorite: False - AudioID: cfc823b6f3681de2980ab85ba6726662 :[KEEPING UNKNOWN MEDIA TYPE] - Audio - Gigante - 0 - Favorite: False - AudioID: d3d44892c4420e8482f423e7c9e352bb :[DELETE] - Episode - La casa di carta - Episodio 7 - 0 - Favorite: False - EpisodeID: d55adc3f19a40806cc4f9983fee31b35 :[DELETE] - Episode - La casa di carta - Episodio 8 - 0 - Favorite: False - EpisodeID: dbc147f93660c1913bc965e8e6680cc1 :[DELETE] - Episode - La casa di carta - Episodio 10 - 0 - Favorite: False - EpisodeID: dbcc42e1169234a6e3411a772c4ce0c4 :[KEEPING UNKNOWN MEDIA TYPE] - Audio - Cuore matto - 0 - Favorite: False - AudioID: ddcd359cf72ca675251e7ec39ebb93d5 :[KEEPING UNKNOWN MEDIA TYPE] - Audio - Flick of the Switch - 0 - Favorite: False - AudioID: e65143efb6e75aa21ca53ffd56b55882 :[KEEPING UNKNOWN MEDIA TYPE] - Audio - Stone Cold Crazy - 0 - Favorite: False - AudioID: e6b9d8e7c05cd3cbb9746e8d68b88787 :[KEEPING UNKNOWN MEDIA TYPE] - Audio - Luna nuda - 0 - Favorite: False - AudioID: e758230519c8f608e881311ebb33a187 :[DELETE] - Episode - Young Sheldon - A Pineapple and the Bosom of Male Friendship - 0 - Favorite: False - EpisodeID: ed60d6483b378a2fd081fb6058556c17 :[KEEPING UNKNOWN MEDIA TYPE] - Audio - Apperò - 0 - Favorite: False - AudioID: f1de4165c082c2962e27876ffcb47816 :[DELETE] - Episode - The IT Crowd - Calamity Jen - 0 - Favorite: False - EpisodeID: f317d572ab87e0f757d5cb5a152a7d02 :[DELETE] - Episode - La casa di carta - Episodio 1 - 0 - Favorite: False - EpisodeID: f4c1fd9a95d75dca0651903f7a76bc69 :[KEEPING UNKNOWN MEDIA TYPE] - Audio - Built for War - 0 - Favorite: False - AudioID: f6d6908fc378de05b58990e62502ed37 :[KEEPING UNKNOWN MEDIA TYPE] - Audio - My Religion - 0 - Favorite: False - AudioID: faf012bd835cf83b65499653e7e7c607 :[DELETE] - Episode - The Good Doctor - Hurt - 0 - Favorite: False - EpisodeID: fe0428da1c9a6da9e426af739031cf26 :[KEEPING UNKNOWN MEDIA TYPE] - Audio - My Champion - 0 - Favorite: False - AudioID: fe10fac33485e302238e77ca0f5e5836 :[KEEPING UNKNOWN MEDIA TYPE] - Audio - Synchronicity II - 0 - Favorite: False - AudioID: fefd37996206c2680b145f5ee7cc6654


Summary Of Deleted Media:


Done.

terrelsa13 commented 4 years ago

We for sure know it is the time formatting that is causing the issue with jellyfin.

How about your media_cleaner.debug file? What is inside of your debug file? Specifically I am looking for lines that look like this: "LastPlayedDate": "2020-03-24T06:52:14.1311383+00:00"

I suggest you use https://pastebin.com to post the long files/logs like you have been doing above. It helps keep these posts cleaner and easier for people to read later.

Here is an example of the media_cleaner.py script in pastebin.

spupuz commented 4 years ago

there is no such file in the same folder also if i configured DEBUG=1 as suugeste.


Il giorno sab 9 mag 2020 alle ore 01:28 terrelsa13 notifications@github.com ha scritto:

We for sure know it is the time formatting that is causing the issue with jellyfin.

How about your media_cleaner.debug file? What is inside of your debug file? Specifically I am looking for lines that look like this: "LastPlayedDate": "2020-03-24T06:52:14.1311383+00:00"

I suggest you use https://pastebin.com to post the long files/logs like you have been doing above. It helps keep these posts cleaner and easier for people to read later.

Here is an example of the media_cleaner.py https://pastebin.com/sZJFwNLY script in pastebin.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/clara-j/media_cleaner/issues/5#issuecomment-626061992, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANELQC7JCH2J4UVJBFQ7QLRQSIR3ANCNFSM4MDMW4JQ .

terrelsa13 commented 4 years ago

This is my fault. I must have made the changes need to create a debug file after the last merge.

Here are the lines you will need to add to make the get_items() function create the debug file.

Original:

New:

Go ahead and run the script again with remove_files=0 and DEBUG=1. A file called _mediacleaner.debug will now be in the same folder as _mediacleaner.py.

Again, my mistake.

spupuz commented 4 years ago

can you posto the code so i can copy and paste instead to re-write? thanks.

Il giorno lun 11 mag 2020 alle ore 21:34 terrelsa13 < notifications@github.com> ha scritto:

This is my fault. I must have made the changes need to create a debug file after the last merge.

Here are the lines you will need to add to make the get_items() function create the debug file.

Original: https://imgur.com/YTXbJ9p

New: https://imgur.com/8I1EqF6

Go ahead an run the script again with remove_files=0 and DEBUG=1. A file called media_cleaner.debug will now be in the same folder as media_cleaner.py.

Again, my mistake.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/clara-j/media_cleaner/issues/5#issuecomment-626912831, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANELQHCL6ERYNPCEOOILFLRRBHNLANCNFSM4MDMW4JQ .

terrelsa13 commented 4 years ago

Link to complete script.

Link to only additional lines.

spupuz commented 4 years ago

Start... Cleaning media for server at: http://192.168.1.xxxx:8096


Get List Of Watched Media

http://192.168.1.xxx:8096/emby/Users/xxxxxxxxxxxxxxxxxxxx/Items?Recursive=true&IsPlayed=true&api_key=xxxxxxxxxxxxxxxxxxx Traceback (most recent call last): File "media_cleaner_new.py", line 444, in deleteItems=get_items(cfg.server_url, cfg.user_key, cfg.access_token) File "media_cleaner_new.py", line 200, in get_items os.chdir(script_dir) FileNotFoundError: [Errno 2] No such file or directory: ''

Il giorno mar 12 mag 2020 alle ore 16:58 terrelsa13 < notifications@github.com> ha scritto:

Link https://pastebin.com/rGxkihTT to complete script.

Link https://pastebin.com/e6bsmSe0 to only additional lines.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/clara-j/media_cleaner/issues/5#issuecomment-627398888, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANELQGYMCXIUQUQ6G6EGLTRRFP2NANCNFSM4MDMW4JQ .

terrelsa13 commented 4 years ago

The user the script is run under will will need to have read-write-execute access to the folder the script is in.

Please do a: whoami cd /path/to/your/media_cleaner/ whoami ls -al And post their outputs.

spupuz commented 4 years ago

root@openmediavault:~# pwd /root root@openmediavault:~# whoami root root@openmediavault:~# cd mediacleaner/ root@openmediavault:~/mediacleaner# whoami root root@openmediavault:~/mediacleaner# ls -lai total 60 788907 drwxrwxrwx 3 root root 4096 May 12 17:04 . 654081 drwx------ 7 root root 4096 May 12 11:49 .. 654221 -rwxrwxrwx 1 root root 384 May 5 10:43 media_cleaner_config.py 804578 -rwxrwxrwx 1 root root 0 May 12 17:01 media_cleaner.debug 804579 -rwxrwxrwx 1 root root 20597 May 12 17:02 media_cleaner_new.py 654213 -rwxrwxrwx 1 root root 20195 May 12 17:01 media_cleaner.py 788908 drwxrwxrwx 2 root root 4096 May 5 10:44 pycache root@openmediavault:~/mediacleaner# whoami root

Il giorno mar 12 mag 2020 alle ore 17:42 terrelsa13 < notifications@github.com> ha scritto:

The user the script is run under will will need to have read-write-execute access to the folder the script is in.

Please do a: whoami cd /path/to/your/media_cleaner/ whoami ls -al And post their outputs.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/clara-j/media_cleaner/issues/5#issuecomment-627425243, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANELQB26N2FBXS22BK6HOLRRFU43ANCNFSM4MDMW4JQ .

terrelsa13 commented 4 years ago

We will skip trying to write the data into a debug file and just have it print directly to the screen.

Try this: Link

Depending on the size of your library, this could be a lot of data being printed to the screen. Hopefully you are able to scroll the terminal viewer you are using.

terrelsa13 commented 4 years ago

@spupuz Any luck with getting the debug data to print directly to the screen?

spupuz commented 4 years ago

Yes but I got busy ... There are too sensitive data on the logs 😁

Il Mar 19 Mag 2020, 18:14 terrelsa13 notifications@github.com ha scritto:

@spupuz https://github.com/spupuz Any luck with getting the debug data to print directly to the screen?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/clara-j/media_cleaner/issues/5#issuecomment-630924855, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANELQD3G3UPYCACQRACT2TRSKV77ANCNFSM4MDMW4JQ .

terrelsa13 commented 4 years ago

I tried adding the JellyFin time format into this script. I hope it will parse both Emby and JellyFin formats.

When you get a chance run it with DEBUG=0 and remove_files=0. I do not run JellyFin. But let me know what happens.

spupuz commented 4 years ago

got this error:

Traceback (most recent call last): File "media_cleaner_new3.py", line 528, in deleteItems=get_items(cfg.server_url, cfg.user_key, cfg.access_token) File "media_cleaner_new3.py", line 264, in get_items os.chdir(script_dir) FileNotFoundError: [Errno 2] No such file or directory: ''

Il giorno mer 20 mag 2020 alle ore 03:51 terrelsa13 < notifications@github.com> ha scritto:

I tried adding the JellyFin time format into this script https://pastebin.com/ptfQPgw4. I hope it will parse both Emby and JellyFin formats.

When you get a chance run it with DEBUG=0 and remove_files=0. I do not run JellyFin. But let me know what happens.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/clara-j/media_cleaner/issues/5#issuecomment-631185575, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANELQBYU3XDZZ25LM6DGVDRSMZTDANCNFSM4MDMW4JQ .

spupuz commented 4 years ago

no using from the same machine but from a different client respect the jellyfin server

Il giorno mer 20 mag 2020 alle ore 07:31 Alessandro Belloni < spupuz@gmail.com> ha scritto:

got this error:

Traceback (most recent call last): File "media_cleaner_new3.py", line 528, in deleteItems=get_items(cfg.server_url, cfg.user_key, cfg.access_token) File "media_cleaner_new3.py", line 264, in get_items os.chdir(script_dir) FileNotFoundError: [Errno 2] No such file or directory: ''

Belloni Alessandro http://www.linkedin.com/in/bellonialessandro

Il giorno mer 20 mag 2020 alle ore 03:51 terrelsa13 < notifications@github.com> ha scritto:

I tried adding the JellyFin time format into this script https://pastebin.com/ptfQPgw4. I hope it will parse both Emby and JellyFin formats.

When you get a chance run it with DEBUG=0 and remove_files=0. I do not run JellyFin. But let me know what happens.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/clara-j/media_cleaner/issues/5#issuecomment-631185575, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANELQBYU3XDZZ25LM6DGVDRSMZTDANCNFSM4MDMW4JQ .

terrelsa13 commented 4 years ago

Not being able to get the directory the script is running from is a separate issue we can address later. For now please make sure you set DEBUG=0 and remove_files=0

zilexa commented 3 years ago

@terrelsa13 I would like to figure this out with you, I am not a dev but I can do proper testing.

I tried your script from a few posts back https://github.com/clara-j/media_cleaner/issues/5#issuecomment-631185575 but during the first run, when asked for the config parameters it crashes after I give my password:

./media_cleaner.py
Enter server ip or name: 192.168.88.10
Enter port (normally 8096): 8096
Enter admin username: admin
Enter admin password (plain text password used to grab access token; password will not be stored): password
Traceback (most recent call last):
  File "./media_cleaner.py", line 427, in <module>
    import media_cleaner_config as cfg
ModuleNotFoundError: 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 523, in <module>
    generate_config()
  File "./media_cleaner.py", line 62, in generate_config
    auth_key=get_auth_key(server_url, username, password, password_sha1)
  File "./media_cleaner.py", line 167, in get_auth_key
    if bool(cfg.DEBUG):
NameError: name 'cfg' is not defined
terrelsa13 commented 3 years ago

@zilexa Hey.

  1. Will you take a couple steps back for me so I understand what your original issue is before you tried the script from comment #5. (i.e. What happens when you run what is checked into GitHub?)
  2. Are you using Emby or Jellyfin?
terrelsa13 commented 3 years ago

@zilexa I see why this was failing. I was trying to use the debug variable from the config file before the config file is created.

@spupuz I think I have come up with a resolution for the Jellyfin LastPlayedDate time formatting issue.

Please try the media_cleaner.py script from my patch and let me know if that resolves your issue.

spupuz commented 3 years ago

I haven't look at it yet.

Il Dom 6 Set 2020, 01:55 terrelsa13 notifications@github.com ha scritto:

@zilexa https://github.com/zilexa I see why this was failing. I was trying to use the debug variable from the config file before the config file is created.

@spupuz https://github.com/spupuz I think I have come up with a resolution for the Jellyfin LastPlayedDate time formatting issue.

Please try the media_cleaner.py script from my patch https://github.com/terrelsa13/media_cleaner/tree/patch-1 and let me know if that resolves your issue.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/clara-j/media_cleaner/issues/5#issuecomment-687677632, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANELQERCCHGHKOJN5GQXN3SELFXRANCNFSM4MDMW4JQ .

terrelsa13 commented 3 years ago

@spupuz looks like @clara-j merged my changes. You should be able to update from the master.

spupuz commented 3 years ago

I'll check

Il Dom 6 Set 2020, 17:53 terrelsa13 notifications@github.com ha scritto:

@spupuz https://github.com/spupuz looks like @clara-j https://github.com/clara-j merged my changes. You should be able to update from the master.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/clara-j/media_cleaner/issues/5#issuecomment-687825794, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANELQDAAAA7ZQ3K5U4RZ7TSEOV6HANCNFSM4MDMW4JQ .

zilexa commented 3 years ago

I tried running the script, downloaded it today. Ran it (Jellyfin). This time there is no exit error, but for each episode in the "list of watched media" it says KEEPING and: unknown date time format
In Jellyfin, my language and country are United Kingdom. When I look at the debug file: "LastPlayedDate": "2020-09-03T20:11:40.3669579Z", Strangely, it is the same day and month for every item in the debug file. The 3rd of Sept happens to be the same day I did a clean install of my server and also clean install of Jellyfin docker.

How can I solve this? When I look at the script, this is the part that should work but does not:

     date_time_last_watched = datetime.strptime(date_last_played, '%Y-%m-%dT%H:%M:%S.0000000Z')
        except Exception:
            date_time_last_watched = 'unknown date time format'

It seems to expect 0000000Z at the end of the value. In my case there are no zeros but 7 other digits.

Seperately, there is a "bad" episode, some blooper special, it can't handle that ep:

Error encountered - Keep Episode: 

{'Name': 'black-ish - Extra Bloopish Special', 'ServerId': '37722182499041828f042853d52cbcaa', 'Id': 'fd01ab60251c6bc86e9ba0e8e9157e48', 'Container': 'mkv,webm', 'RunTimeTicks': 12106059776, 'ParentIndexNumber': 2018, 'IsFolder': False, 'Type': 'Episode', 'ParentBackdropItemId': '0c532dda279168aa2c6a9dbe7d787509', 'ParentBackdropImageTags': ['20b528b05289c80629f00e13fe374c74'], 'UserData': {'PlaybackPositionTicks': 0, 'PlayCount': 1, 'IsFavorite': False, 'LastPlayedDate': '2020-09-03T20:40:32.0184212Z', 'Played': True, 'Key': 'fd01ab60-251c-6bc8-6e9b-a0e8e9157e48'}, 'SeriesName': 'black-ish', 'SeriesId': '0c532dda279168aa2c6a9dbe7d787509', 'SeasonId': '267324a13dbd2fe121e172ba24f61dfc', 'SeriesPrimaryImageTag': '78a8ee3b07c3f49b5edfdfe992eaa797', 'SeasonName': 'Season 2018', 'VideoType': 'VideoFile', 'ImageTags': {'Primary': 'd3cb8eac558271add7f1c5b085351446'}, 'BackdropImageTags': [], 'ImageBlurHashes': {'Primary': {'d3cb8eac558271add7f1c5b085351446': 'NABC_S~W^j?G%3-;-;IVD*W.RkjI_2t7Rkt6kCt7', '78a8ee3b07c3f49b5edfdfe992eaa797': 'dABC=G?F4:o~M~%LtSOs0eNg?F,.crXMVrw_t8,Hw5BU'}, 'Backdrop': {'20b528b05289c80629f00e13fe374c74': 'WI8px?xY0gEO-U$yxGoMNbNas+xFD+WF%LxURkR:owWoWCspsDNb'}}, 'LocationType': 'FileSystem', 'MediaType': 'Video'}
terrelsa13 commented 3 years ago

As for that "bad" episode. The script stops if it does not get data it expects to get from emby(jellyfin) to build the detailed output about what media is watched and what media will and will not be deleted. I have made an update in branch to verify it works for the other issue being reported.

Dang. Thought I had that fixed. I will have to keep looking into the LastPlayedDate issue. I was hoping to avoid installing jellyfin. But I may have to in order to come up with a way for it to work for both emby and jellyfin.

zilexa commented 3 years ago

Dang. Thought I had that fixed. I will have to keep looking into the LastPlayedDate issue. I was hoping to avoid installing jellyfin. But I may have to in order to come up with a way for it to work for both emby and jellyfin.

My jellyfin is not exposed to the internet but perhaps I could give you access via VPN.. not sure if that would open a box of new issues though. I am wondering why the script falls back to it's final excepion (unknown date time format). Is it really all those zeros? I guess I could perhaps manually add a case to the script with the exact date_last_played of one of my Jellyfin files.. I might give it a try tomorrow.

zilexa commented 3 years ago

I changed your script: date_time_last_watched = datetime.strptime(date_last_played, '%Y-%m-%dT%H:%M:%S.0000000Z') to date_time_last_watched = datetime.strptime(date_last_played, '%Y-%m-%dT%H:%M:%S.%f%Z') inspiration from here: https://stackoverflow.com/questions/41684991/datetime-strptime-2017-01-12t141206-000-0500-y-m-dthms-fz

But still the same issue. Then I restored the change and only changed the word unknown

        except Exception:
            date_time_last_watched = 'unknown date time format'

to

        except Exception:
            date_time_last_watched = 'unknownnnn date time format'

But then the script actually fails, complaining about line 216 (which I did not modify).

Now I am a bit clueless..

terrelsa13 commented 3 years ago

I have been poking around the code whenever I get the time. I have found a couple things.

  1. Jellyfin appears to be putting their branding into the API. Lines like .../emby/Users/AuthenticateByName',... now need to say .../jellyfin/Users/AuthenticateByName',.... Easiest way to solve this is to force a selection of emby or jellyin the first time the script is run.

  2. My jellyfin "LastPlayedDate": "2020-09-19T11:19:52.0000000-04:00", which looks different. So I am not sure what is going on there. I am not very familiar dealing with time/timezones. I will have to learn more. Until I can come up with a solution that works for both emby and jellyfin I am going to disable the days since last watched functionality.

I will let you know when I get an updated script you can try out.

zilexa commented 3 years ago

Are you using Jellyfin via Docker? I am running Ubuntu (Budgie) 20.04.1 with Docker and Jellyfin runs via docker. I can of course test by changing my time/zone/location whatever to yours.

I guess all I need is a method to delete any non-favourite content (movie or tv show) after status is watched. I can set it to run every 3 weeks (via cron).

Would be nice if it runs daily and only deletes stuff if it has been watched xx days ago (I would go for 30 days max). But that of course requires days since last watched..

Perhaps the Jellyfin Forum can help here as the devs are quite active there.

terrelsa13 commented 3 years ago

I can see how what I said was confusing. The days since last watched I am talking about is different than the cut off date used to delete media. The days since last watch is only used to show a human readable string to help easily see how many days ago media was watched. The cut off date will still delete media according to xx days set in the config file.

zilexa commented 3 years ago

Oh wow! In that case it means your script should already be fully functional once you leave days since last watched out :+1: Ok can't wait for the update. Got some cleaning up to do :)

terrelsa13 commented 3 years ago

Ok. I have something here. This works with both my emby and my jellyfin. Fingers crossed it works for your jellyfin.

terrelsa13 commented 3 years ago

FYI - Changes were added that either require you to create a new config file or will require manual input each time the script is run if a new config file is not created.

zilexa commented 3 years ago

OK I tried this version: https://github.com/terrelsa13/media_cleaner/tree/patch-1 No more errors but just like the previous version, it says all my (watched?) episodes have been watched 17 days ago (a few 10 days ago, but these are episodes I haven't watched for over a year). This is of course incorrect. There is not enough time in a day to watch them all.

When I look at what happened 17 days ago: that is when I installed Jellyfin (full clean install from scratch, starting with my OS, after a server ram issue).

So it seems to 'know' which eps are watched, but it does not know yet when they are watched.

terrelsa13 commented 3 years ago

Will you set DEBUG=1 in the config file, run the script again, and open the "media_cleaner.debug" file. The debug file will contain the date emby/jellyfin sends back for each watched episode. Do a search for LastPlayedDate. Are you seeing dates of 10 days and 17 days ago? Or are yo seeing dates of over 1 year ago?

zilexa commented 3 years ago

I am still checking, but its always "LastPlayedDate": "2020-09-03T20:11:48.2051742Z", or slightly different seconds (20:11:37 to 20:11:48) and a few "LastPlayedDate": "2020-09-10T17:51:26.1172142Z", No other dates.. I believe I may have rebooted the server on the 10th.

Could this be a Jellyfin bug?

zilexa commented 3 years ago

OH I think I understand the issue! Since I did a clean install, Jellyfin has no way of knowing what was watched and when it was watched. Nothing had status 'watched'.

After installing Jellyfin, I used the Trakt plugin to sync my watched status history (from Trakt) to Jellyfin. Trakt plugin must have had its initial run on the 3rd of september. And perhaps I watched a few things on the 10th.

I guess I can lower the treshold to 15 days to get everything from the 3rd of sept deleted, then raise to 21-30 days or something. Going forward, your script should work for me!

terrelsa13 commented 3 years ago

Yep, that is what I suspected. And it sounds like you also understand it now. Emby/Jellyfin would have no way of knowing when the watched date was unless it happened after your clean install or you also backed up the emyb/jellyfin database (which I think is where that kind of info is stored) and restored it after the clean install.

Remember to set "remove_files=1" when you are ready to have the script actually delete these media files.

terrelsa13 commented 3 years ago

@zilexa Now that we know the updates work for emby and jellyfin, I put in a pull request for @clara-j to merge it into her main.

terrelsa13 commented 3 years ago

@spupuz if we have resolved the original problem, please close this issue when you get a chance.

Changes are in my repository until they are merged here.

spupuz commented 3 years ago

Need to test the script.

Il Mar 22 Set 2020, 01:14 terrelsa13 notifications@github.com ha scritto:

@spupuz https://github.com/spupuz if we have resolved the original problem, please close this issue when you get a chance.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/clara-j/media_cleaner/issues/5#issuecomment-696428639, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANELQD5KIJ4WVQCJP6RI5LSG7M7HANCNFSM4MDMW4JQ .

zilexa commented 3 years ago

it works successfully. Feel free to close this one.

terrelsa13 commented 2 years ago

@spupuz This has been resolved for quite some time. Please close this issue.