terrelsa13 / MUMC

Multi-User Media Cleaner aka MUMC (pronounced Mew-Mick) will go through movies, tv episodes, audio tracks, and audiobooks in your Emby/Jellyfin libraries deleting media items you no longer want.
GNU General Public License v3.0
92 stars 6 forks source link

KeyError: 'ExcludedSubFolders' #105

Closed Ulyssedev closed 4 months ago

Ulyssedev commented 4 months ago

Hey, I'm trying to use this tool with the latest version of Jellyfin (10.8.13) although I'm getting hit with this error when trying to blacklist 3 libraries (With option number two selected: 2 - Select libraries only. Selected libraries will be blacklisted for all users according to their access policy.)

I tried with Python 3.8, 3.11 and 3.12 and the same error is happening. When trying with a lower version of MUMC, a 404 is being returned from the Jellyfin server stating that the route SelectableMediaFolders is not found.

My main goal would be to delete any content that has not been played for the last 90 days by any user. Thanks a lot for taking the time to look at my issue, let me know if any extra information is needed.

Terminal Output:

Select one or more libraries.
Unselect a library by selecting it again.
*Use a comma or space to separate multiple selections.
Leave blank when finished: 
Traceback (most recent call last):
  File "/home/lowhigh/mumc/mumc_modules/mumc_config_import.py", line 90, in importConfig
    import mumc_config as cfg
ModuleNotFoundError: No module named 'mumc_config'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/lowhigh/mumc/mumc.py", line 110, in <module>
    MUMC()
  File "/home/lowhigh/mumc/mumc.py", line 28, in MUMC
    cfg,init_dict=importConfig(init_dict,cmdopt_dict)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lowhigh/mumc/mumc_modules/mumc_config_import.py", line 106, in importConfig
    importHasException(init_dict,cmdopt_dict)
  File "/home/lowhigh/mumc/mumc_modules/mumc_config_import.py", line 21, in importHasException
    build_configuration_file(init_dict)
  File "/home/lowhigh/mumc/mumc_modules/mumc_config_builder.py", line 137, in build_configuration_file
    the_dict['admin_settings']['users']=get_users_and_libraries(the_dict)
                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lowhigh/mumc/mumc_modules/mumc_builder_userlibrary.py", line 56, in get_users_and_libraries
    the_dict=all_users_select_libraries(the_dict)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lowhigh/mumc/mumc_modules/mumc_builder_userlibrary.py", line 143, in all_users_select_libraries
    the_dict=filter_library_data_for_selected_user(the_dict)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lowhigh/mumc/mumc_modules/mumc_builder_user.py", line 149, in filter_library_data_for_selected_user
    if (lib_id_folder_id in the_dict['all_users'][the_dict['user_selection_int']]['Policy']['ExcludedSubFolders']):
                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'ExcludedSubFolders'
terrelsa13 commented 4 months ago

@Ulyssedev You are correct. Looks like this is something Jellyfin is doing differently than Emby.

When MUMC sends an API query for user's information the script is currently expecting to see both a list of included folders and a list of excluded folders for each user. Jellyfin for some reason, has decided to not send excluded folders in the returned data.

First I will need to determine if there is a different way to get the excluded folder data for each user. If there is, the goal would be to use common code for both Emby and Jellyfin.

There are three ways this could go:

  1. A common way to determine included and excluded folders for each user is found for Emby and Jellyfin.
  2. There is no common way, Jellyfin has to have different code to determine the included and excluded folders for each user.
  3. Jellyfin has no way to determine the excluded folders for each user. If this happens, Jellyfin will be forced to only have 0 - Select users and libraries as an option.

In the meantime; you should be able to use 0 - Select users and libraries to bypass this error. When manually selecting both users and libraries the script does not need to know which libraries are not included for a specific user.

terrelsa13 commented 4 months ago

@Ulyssedev I have bad news.

Jellyfin does not support per-folder access assignments for libraries. Either a user has access to all of the library or none of the library. This seems like a feature miss on their part. Googling this and the answer given when someone asks to have this feature enabled is, "to use multiple libraries". Which is a bummer because Emby has this capability.

I have included a couple links of people asking for this feature to be added to Jellyfin in the past:

I can see on my test server for my TV library, Jellyfin in fact does not give the option to select folders within a library under Dashboard > Users > Username > Access > Library Access > Libraries:

Screenshot from 2024-04-15 20-03-07

Screenshot from 2024-04-15 20-03-40

The same setup on my Emby test server allows individual library folder access to be assigned for any given user:

Screenshot from 2024-04-15 20-04-12

Screenshot from 2024-04-15 20-05-05

Until Jellyfin enables a way to assign individual access to folders within a library (similar to Emby); Jellyfin users will no longer have 2 - Select libraries only as an option.

Jellyin users will continue to have 0 - Select users and libraries and 1 - Select users only as options.

terrelsa13 commented 4 months ago

@Ulyssedev Instead of completely removing 2 - Select libraries only as an option for Jellyfin users. MUMC will automatically select/deselect all other folders in same library.

Example:

0 - movies - Path: /media/pharaoh/xbmc/movies - NetPath: smb://172.31.14.161/movies - LibId: c8ca023cdbb96c78e4de5f023456789a
1 - tvshows - Path: /media/pharaoh/xbmc/tv - NetPath: smb://172.31.14.161/tv - LibId: 7c6b1294b30d4c722993e40123456789a
2 - tvshows - Path: /media/pharaoh/xbmc/tv2 - NetPath: None - LibId: 7c6b1294b30d4c722993e40123456789a
3 - music - Path: /media/pharaoh/xbmc/music/albums - NetPath: smb://172.31.14.161/albums - LibId: 60c6bb241c9195d4b536e0123456789a

1 is manually selected. 2 is automatically added to the selection because it shares the same library id.

Next console output will appear as shown:

0 - movies - Path: /media/pharaoh/xbmc/movies - NetPath: smb://172.31.14.161/movies - LibId: c8ca023cdbb96c78e4de5f023456789a
1 - tvshows
2 - tvshows
3 - music - Path: /media/pharaoh/xbmc/music/albums - NetPath: smb://172.31.14.161/albums - LibId: 60c6bb241c9195d4b536e0123456789a
terrelsa13 commented 4 months ago

This has been "fixed" in the v5.7.2 release. Let me know if you run into any other issues.

Keep in mind, Jellyfin does not allow assigning individual folder access to users. In Jellyfin the user either has access to all folders in a library or none of the folders in a library.