Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem jellyfin docker #5

Open
spupuz opened this issue Apr 7, 2020 · 47 comments
Open

problem jellyfin docker #5

spupuz opened this issue Apr 7, 2020 · 47 comments

Comments

@spupuz
Copy link

spupuz commented Apr 7, 2020

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
Copy link
Contributor

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
Copy link
Author

spupuz commented Apr 30, 2020

how can i do that?

@terrelsa13
Copy link
Contributor

terrelsa13 commented May 2, 2020

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_since_watched() function in media_cleaner.py to show how many days ago something was watched.

@spupuz
Copy link
Author

spupuz commented May 5, 2020

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

@terrelsa13
Copy link
Contributor

Ok. Set the config file to have remove_files=0 and DEBUG=1 like we did above. Then we will simplify the get_days_since_watched() 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
Copy link
Author

spupuz commented May 8, 2020


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:

  • Trial Run *
  • remove_files=0 *
  • No Media Deleted *

[DELETED] Episode - The IT Crowd - Fifty-fifty - 02f9d0bd1f9d542b7b7b8d2a1e1fddef
[DELETED] Episode - La casa di carta - Episodio 7 - 0af4b9a89735d1802c340cd10c8aa47a
[DELETED] Episode - La casa di carta - Episodio 1 - 1a7ba7f8fadd777fda83c781c283b8bc
[DELETED] Episode - The Good Doctor - Heartbreak - 1b096e11d8fdd3f919f0c6fdd45d2be9
[DELETED] Episode - La casa di carta - Il matrimonio di Berlino - 1cb681dfc93497b9548554ee99a8066b
[DELETED] Episode - The Good Doctor - I Love You - 235a31c769b9b420036a46f65a5ee9b5
[DELETED] Episode - The Good Doctor - Unsaid - 25ae1d09f6e3f10e9a8c1dbbd6fd3345
[DELETED] Episode - La casa di carta - Il matrimonio di Berlino - 2691480684a6fbe1d427c349f23dfd87
[DELETED] Episode - Outlander - Mercy Shall Follow Me - 26fccd74db65bc4729cb926e6b4dea98
[DELETED] Episode - La casa di carta - Episodio 8 - 33cb1e73397e827183b93fb21b4d3388
[DELETED] Episode - Outlander - Monsters and Heroes - 456faed5a633441c96d4be4272acb905
[DELETED] Episode - La casa di carta - Episodio 13 - 45c302aa670ff1a28fdd3504f53d4b6a
[DELETED] Episode - The Good Doctor - Autopsy - 46c2f51c40da60c8e839052e56fd1e96
[DELETED] Episode - Young Sheldon - A Broom Closet and Satan's Monopoly Board - 4855ea565f88fb5816b01d86317c6829
[DELETED] Episode - La casa di carta - Episodio 3 - 4ce1c4a6ff44bb6dfe94ba69ae55c639
[DELETED] Episode - La casa di carta - Episodio 4 - 52a3649cd0296c1885543aa007382f9f
[DELETED] Episode - La casa di carta - Episodio 5 - 54fc76ee1465e2e9538eb29da9034eba
[DELETED] Episode - Young Sheldon - Quirky Eggheads and Texas Snow Globes - 5d22c88dcaeb61e01bbe5abfcde3897c
[DELETED] Episode - The Good Doctor - L'influencer - 5f4efea20c52820342e9b9d4494b234d
[DELETED] Episode - La casa di carta - Episodio 2 - 5fe20ff6ef96457dd64d79a47e0f8280
[DELETED] Episode - La casa di carta - Episodio 11 - 6a51ab692e29efb94dd9bde56fb08a7c
[DELETED] Episode - Young Sheldon - Hobbitses, Physicses and a Ball with Zip - 6e4a9934b9d551f64e1ca0afe69d1570
[DELETED] Episode - The Good Doctor - Un cuore spezzato - 744857a22c22295028fcba4e44c69b62
[DELETED] Episode - Young Sheldon - An Entrepreneurialist and a Swat on the Bottom - 74c5137c6be3c4bbde4919c7c11884d8
[DELETED] Episode - La casa di carta - Episodio 10 - 75ac63eabc2515123821ad3faef507a4
[DELETED] Episode - La casa di carta - Episodio 2 - 8ffe4d4d77bf03750558597864efc3ed
[DELETED] Episode - La casa di carta - Episodio 6 - 965edeb9a5fee7c503bd8d637d80236e
[DELETED] Episode - La casa di carta - Episodio 9 - 9baaf05aa22eefd5c3cc0a94fedb63e5
[DELETED] Episode - La casa di carta - Episodio 6 - a6dd64d66e3561ca3b7a3077c40d8de2
[DELETED] Episode - La casa di carta - Episodio 3 - a856bc04d6051183c262e9955b43811a
[DELETED] Episode - La casa di carta - Episodio 4 - aa1c4010d2a01bc3a68c4d06b2c0f243
[DELETED] Episode - The Good Doctor - Fixation - aa74d5beb43588da20bedbcec9fb653f
[DELETED] Episode - La casa di carta - Episodio 13 - adc3eb281959a9be6706792bf118b3a0
[DELETED] Episode - The IT Crowd - La porta rossa - ae91a279954b28782a8fa49e53792f2f
[DELETED] Episode - La casa di carta - Episodio 9 - b0086b5a0869c631e4ceee893f9b6bfc
[DELETED] Episode - The Good Doctor - Amore e morte - b3339a7766ad6c670448f7773aae216f
[DELETED] Episode - The Good Doctor - Mutazioni - bf80c182f1fcc29476ee46c0191771ec
[DELETED] Episode - La casa di carta - Episodio 5 - c71a0afb3bd16c05a4d9aa3651393644
[DELETED] Episode - La casa di carta - Episodio 11 - c87914c75373b9f7c99a79f8838cc598
[DELETED] Episode - La casa di carta - Episodio 7 - d55adc3f19a40806cc4f9983fee31b35
[DELETED] Episode - La casa di carta - Episodio 8 - dbc147f93660c1913bc965e8e6680cc1
[DELETED] Episode - La casa di carta - Episodio 10 - dbcc42e1169234a6e3411a772c4ce0c4
[DELETED] Episode - Young Sheldon - A Pineapple and the Bosom of Male Friendship - ed60d6483b378a2fd081fb6058556c17
[DELETED] Episode - The IT Crowd - Calamity Jen - f317d572ab87e0f757d5cb5a152a7d02
[DELETED] Episode - La casa di carta - Episodio 1 - f4c1fd9a95d75dca0651903f7a76bc69
[DELETED] Episode - The Good Doctor - Hurt - fe0428da1c9a6da9e426af739031cf26


Done.

@terrelsa13
Copy link
Contributor

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
Copy link
Author

spupuz commented May 11, 2020 via email

@terrelsa13
Copy link
Contributor

terrelsa13 commented May 11, 2020

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 media_cleaner.debug will now be in the same folder as media_cleaner.py.

Again, my mistake.

@spupuz
Copy link
Author

spupuz commented May 12, 2020 via email

@terrelsa13
Copy link
Contributor

Link to complete script.

Link to only additional lines.

@spupuz
Copy link
Author

spupuz commented May 12, 2020 via email

@terrelsa13
Copy link
Contributor

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
Copy link
Author

spupuz commented May 12, 2020 via email

@terrelsa13
Copy link
Contributor

terrelsa13 commented May 12, 2020

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
Copy link
Contributor

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

@spupuz
Copy link
Author

spupuz commented May 19, 2020 via email

@terrelsa13
Copy link
Contributor

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
Copy link
Author

spupuz commented May 20, 2020 via email

@spupuz
Copy link
Author

spupuz commented May 20, 2020 via email

@terrelsa13
Copy link
Contributor

terrelsa13 commented May 20, 2020

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
Copy link

zilexa commented Sep 4, 2020

@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 #5 (comment)
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
Copy link
Contributor

@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 problem jellyfin docker #5. (i.e. What happens when you run what is checked into GitHub?)
  2. Are you using Emby or Jellyfin?

@terrelsa13
Copy link
Contributor

@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
Copy link
Author

spupuz commented Sep 6, 2020 via email

@terrelsa13
Copy link
Contributor

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

@spupuz
Copy link
Author

spupuz commented Sep 6, 2020 via email

@zilexa
Copy link

zilexa commented Sep 14, 2020

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
Copy link
Contributor

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
Copy link

zilexa commented Sep 17, 2020

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
Copy link

zilexa commented Sep 18, 2020

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
Copy link
Contributor

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
Copy link

zilexa commented Sep 19, 2020

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
Copy link
Contributor

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
Copy link

zilexa commented Sep 20, 2020

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

@terrelsa13
Copy link
Contributor

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

@terrelsa13
Copy link
Contributor

terrelsa13 commented Sep 20, 2020

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
Copy link

zilexa commented Sep 21, 2020

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
Copy link
Contributor

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
Copy link

zilexa commented Sep 21, 2020

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
Copy link

zilexa commented Sep 21, 2020

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
Copy link
Contributor

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
Copy link
Contributor

@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
Copy link
Contributor

terrelsa13 commented Sep 21, 2020

@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
Copy link
Author

spupuz commented Sep 22, 2020 via email

@zilexa
Copy link

zilexa commented Oct 6, 2020

it works successfully. Feel free to close this one.

clara-j pushed a commit that referenced this issue Oct 18, 2020
Update to state hashed password stored
clara-j added a commit that referenced this issue Oct 18, 2020
Resolve Issue #5 and Resolve Issue #6
@terrelsa13
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants