pbrink231 / plex_top_playlists

A python script for creating playlists and collections for all server users from sources like IMDB and Trakt
110 stars 22 forks source link

different errors (AttributeError: 'str' object has no attribute 'get'`) #35

Closed Dex321x closed 4 years ago

Dex321x commented 4 years ago

I had the script working in the past, but recently i get this error after python3 ./plex_playlist_update.py run

`

Traceback (most recent call last): File "./plex_playlist_update.py", line 631, in list_updater(plex) File "./plex_playlist_update.py", line 591, in list_updater users = get_user_tokens(plex) File "./plex_playlist_update.py", line 582, in get_user_tokens users = get_all_users(plex) File "./plex_playlist_update.py", line 564, in get_all_users user_ids = {plex_user['@id']: plex_user.get('@username', plex_user.get('@title')) for plex_user in xmlData2['MediaContainer']['User']} File "./plex_playlist_update.py", line 564, in user_ids = {plex_user['@id']: plex_user.get('@username', plex_user.get('@title')) for plex_user in xmlData2['MediaContainer']['User']} AttributeError: 'str' object has no attribute 'get'`

Any idea what i could try?

mraniki commented 4 years ago

I'm getting an error as well since recently Using settings file Traceback (most recent call last): File "/opt/appdata/plex_tools/plex_top_playlists/plex_playlist_update.py", line 51, in NOT_ALLOW_SYNCED_USERS = json.loads(config.get('Plex', 'not_users')) File "/usr/lib/python3.6/json/init.py", line 354, in loads return _default_decoder.decode(s) File "/usr/lib/python3.6/json/decoder.py", line 342, in decode raise JSONDecodeError("Extra data", s, end) json.decoder.JSONDecodeError: Extra data: line 3 column 1 (char 4)

Maybe a change in plexapi that is breakiing the code ?

mraniki commented 4 years ago

My error was due to plexapi pip package issue (typo in the name update) This resolve it:

pip3 install -r requirements.txt --upgrade

Successfully uninstalled PlexAPI-3.6.0 Successfully installed plexapi-3.6.0

Dex321x commented 4 years ago

Thank you for your reply and sharing what helped you! It was working for me again for some time. Now it stopped to work again. I tried the upgrade, but I'm getting still this error. I would appreciate any help. Thanks!

`Installing collected packages: plexapi Attempting uninstall: plexapi Found existing installation: PlexAPI 4.0.0 Uninstalling PlexAPI-4.0.0: Successfully uninstalled PlexAPI-4.0.0 Successfully installed plexapi-4.0.0 /opt/appdata/plex_top_playlists# python3 ./plex_playlist_update.py run Using settings file

Traceback (most recent call last): File "./plex_playlist_update.py", line 631, in list_updater(plex) File "./plex_playlist_update.py", line 591, in list_updater users = get_user_tokens(plex) File "./plex_playlist_update.py", line 582, in get_user_tokens users = get_all_users(plex) File "./plex_playlist_update.py", line 564, in get_all_users user_ids = {plex_user['@id']: plex_user.get('@username', plex_user.get('@title')) for plex_user in xmlData2['MediaContainer']['User']} File "./plex_playlist_update.py", line 564, in user_ids = {plex_user['@id']: plex_user.get('@username', plex_user.get('@title')) for plex_user in xmlData2['MediaContainer']['User']} AttributeError: 'str' object has no attribute 'get'`

pbrink231 commented 4 years ago

I will look into this tomorrow. update the requirements. See what is going on.

Dex321x commented 4 years ago

Could you find something? I really miss the lists.

pbrink231 commented 4 years ago

@Dex321x How many users do you have?

Also can you try using the develop branch that I pushed today.

git checkout develop then run the code like normal

Dex321x commented 4 years ago

@pbrink231 I have one user. Tried the develop branch, but still getting errors :-(. i am grateful for any help.

> Using settings file
> ===================================================================
>    Automated Playlist to Plex script
> ===================================================================
> 
> Traceback (most recent call last):
>   File "./plex_playlist_update.py", line 93, in <module>
>     list_updater(PLEX)
>   File "./plex_playlist_update.py", line 36, in list_updater
>     plex_data = PlexData(plex)
>   File "/opt/appdata/plex_top_playlists/classes/plex_data.py", line 13, in __init__
>     self.shared_users_token = get_user_tokens(plex)
>   File "/opt/appdata/plex_top_playlists/functions/users.py", line 45, in get_user_tokens
>     users = get_all_users(plex)
>   File "/opt/appdata/plex_top_playlists/functions/users.py", line 26, in get_all_users
>     user_ids = {plex_user['@id']: plex_user.get('@username', plex_user.get('@title')) for plex_user in xml_data_2['MediaContainer']['User']}
>   File "/opt/appdata/plex_top_playlists/functions/users.py", line 26, in <dictcomp>
>     user_ids = {plex_user['@id']: plex_user.get('@username', plex_user.get('@title')) for plex_user in xml_data_2['MediaContainer']['User']}
> AttributeError: 'str' object has no attribute 'get'
pbrink231 commented 4 years ago

Looks like this was a xml parse issue with a single user. fixed this same issue when there was a single server before.

Newest develop commit should do it git pull while on develop branch.

You can test it works with

python plex_playlist_update.py show_users

Let me know.

Dex321x commented 4 years ago

@pbrink231 I tried again switching to the develop branch and now the script works again! Thank you! But I still have some problems:

it seems to recognize the Playlists but still creates Collections: This is the output when i run the script:

> Using settings file
> ===================================================================
>    Automated Playlist to Plex script
> ===================================================================
> 
> Retrieving a list of movies from the 'Filme' library in Plex...
> Added 1387 movies to your 'all movies' list from the 'Filme' library in Plex...
> Found 1387 movies total in 'all movies' list from Plex...
> Creating movie dictionary based on IMDB ID
> IMDB ERROR: 'NoneType' object has no attribute 'group'6.5% ...922 of 1387
> Retrieving a list of shows from the 'Serien' library in Plex...1387 of 1387
> Added 57 shows to your 'all shows' list from the 'Serien' library in Plex...
> Found 57 show total in 'all shows' list from Plex...
> Creating show dictionary based on TVDB ID
> [==================================================] 100.0% ...57 of 57
> cached plex shows
> count of trakt movies lists: 6
> PULLING LIST - Movies Top Weekly: URL: https://api.trakt.tv/movies/watched/weekly - TYPE: watched - KIND: playlist
> PULLING LIST - Movies Top Monthly: URL: https://api.trakt.tv/movies/watched/monthly - TYPE: watched - KIND: playlist
> PULLING LIST - Movies Top Yearly: URL: https://api.trakt.tv/movies/watched/yearly - TYPE: watched - KIND: playlist
> PULLING LIST - Movies Top All Time: URL: https://api.trakt.tv/movies/watched/all - TYPE: watched - KIND: playlist
> PULLING LIST - Movies Top Trending: URL: https://api.trakt.tv/movies/trending - TYPE: trending - KIND: playlist
> PULLING LIST - Movies Popular: URL: https://api.trakt.tv/movies/popular - TYPE: popular - KIND: playlist
> count of trakt shows lists: 0
> count of trakt users lists: 0
> count of imdb lists: 2
> getting imdb ids from url: https://www.imdb.com/chart/top
> getting imdb ids from url: http://www.imdb.com/search/title?groups=oscar_best_picture_winners&sort=year,desc&view=simple
> Movies Top Weekly: finding matching movies for playlist with count 80
> Movies Top Monthly: finding matching movies for playlist with count 80
> Movies Top Yearly: finding matching movies for playlist with count 80
> Movies Top All Time: finding matching movies for playlist with count 80
> WARNING: Movies Top Trending is empty so skipping
> Movies Popular: finding matching movies for playlist with count 80
> IMDB Top 250: finding matching movies for playlist with count 250
> Oscar Gewinner: finding matching movies for playlist with count 50

This is how my settings.ini looks: (I tried to add "kind":"playlist" but it doesn't seem to have a impact)

> ## Movie list
> trakt-movie-list: [
>   { "title": "Movies Top Weekly", "type":"watched", "limit": 80, "url":"https://api.trakt.tv/movies/watched/weekly", "kind":"playlist"},
>   { "title": "Movies Top Monthly", "type":"watched", "limit": 80, "url":"https://api.trakt.tv/movies/watched/monthly"},
>   { "title": "Movies Top Yearly", "type":"watched", "limit": 80, "url":"https://api.trakt.tv/movies/watched/yearly"},
>   { "title": "Movies Top All Time", "type":"watched", "limit": 80, "url":"https://api.trakt.tv/movies/watched/all"},
>   { "title": "Movies Top Trending", "type":"trending", "limit": 80, "url":"https://api.trakt.tv/movies/trending", "show_summary": "False"},
>   { "title": "Movies Popular", "type":"popular", "limit": 80, "url":"https://api.trakt.tv/movies/popular", "show_summary": "False"}
>   ]

and for imdb:

> imdb-lists: [
>   { "title":"IMDB Top 250", "type":"chart", "url":"https://www.imdb.com/chart/top"},
>   { "title":"Oscar Gewinner", "type":"search", "url":"http://www.imdb.com/search/title?groups=oscar_best_picture_winners&sort=year,desc&view=simple" }
> 
>   ]
pbrink231 commented 4 years ago

Ill check this out. Needed to do more testing on develop and this is very useful.

Error looks like the new reflex isn’t matching the agent. I’ll make the error clearer so I can fix it.

Thanks for the settings file.

On Sat, Aug 8, 2020 at 12:59 PM Dex321x notifications@github.com wrote:

@pbrink231 https://github.com/pbrink231 I tried again switching to the develop branch and now the script works again! Thank you! But I still have some problems:

  • it only creates Collections instead of Playlists
  • some imdb error in the beginning (not sure if it's important or not)
  • Trakt.tv Trending list (https://api.trakt.tv/movies/trending ) seems to have a problem and tells it's empty, but this maybe not related to the script.

it seems to regocnize the Playlists but still creates Collections: This is the output when i run the script:

Using settings file

Automated Playlist to Plex script

Retrieving a list of movies from the 'Filme' library in Plex... Added 1387 movies to your 'all movies' list from the 'Filme' library in Plex... Found 1387 movies total in 'all movies' list from Plex... Creating movie dictionary based on IMDB ID IMDB ERROR: 'NoneType' object has no attribute 'group'6.5% ...922 of 1387 Retrieving a list of shows from the 'Serien' library in Plex...1387 of 1387 Added 57 shows to your 'all shows' list from the 'Serien' library in Plex... Found 57 show total in 'all shows' list from Plex... Creating show dictionary based on TVDB ID [==================================================] 100.0% ...57 of 57 cached plex shows count of trakt movies lists: 6 PULLING LIST - Movies Top Weekly: URL: https://api.trakt.tv/movies/watched/weekly - TYPE: watched - KIND: playlist PULLING LIST - Movies Top Monthly: URL: https://api.trakt.tv/movies/watched/monthly - TYPE: watched - KIND: playlist PULLING LIST - Movies Top Yearly: URL: https://api.trakt.tv/movies/watched/yearly - TYPE: watched - KIND: playlist PULLING LIST - Movies Top All Time: URL: https://api.trakt.tv/movies/watched/all - TYPE: watched - KIND: playlist PULLING LIST - Movies Top Trending: URL: https://api.trakt.tv/movies/trending - TYPE: trending - KIND: playlist PULLING LIST - Movies Popular: URL: https://api.trakt.tv/movies/popular - TYPE: popular - KIND: playlist count of trakt shows lists: 0 count of trakt users lists: 0 count of imdb lists: 2 getting imdb ids from url: https://www.imdb.com/chart/top getting imdb ids from url: http://www.imdb.com/search/title?groups=oscar_best_picture_winners&sort=year,desc&view=simple Movies Top Weekly: finding matching movies for playlist with count 80 Movies Top Monthly: finding matching movies for playlist with count 80 Movies Top Yearly: finding matching movies for playlist with count 80 Movies Top All Time: finding matching movies for playlist with count 80 WARNING: Movies Top Trending is empty so skipping Movies Popular: finding matching movies for playlist with count 80 IMDB Top 250: finding matching movies for playlist with count 250 Oscar Gewinner: finding matching movies for playlist with count 50

This is how my settings.ini looks: (I tried to add "kind":"playlist" but it doesn't seem to have a impact)

Movie list

trakt-movie-list: [ { "title": "Movies Top Weekly", "type":"watched", "limit": 80, "url":"https://api.trakt.tv/movies/watched/weekly", "kind":"playlist"}, { "title": "Movies Top Monthly", "type":"watched", "limit": 80, "url":"https://api.trakt.tv/movies/watched/monthly"}, { "title": "Movies Top Yearly", "type":"watched", "limit": 80, "url":"https://api.trakt.tv/movies/watched/yearly"}, { "title": "Movies Top All Time", "type":"watched", "limit": 80, "url":"https://api.trakt.tv/movies/watched/all"}, { "title": "Movies Top Trending", "type":"trending", "limit": 80, "url":"https://api.trakt.tv/movies/trending", "show_summary": "False"}, { "title": "Movies Popular", "type":"popular", "limit": 80, "url":"https://api.trakt.tv/movies/popular", "show_summary": "False"} ]

and for imdb:

imdb-lists: [ { "title":"IMDB Top 250", "type":"chart", "url":"https://www.imdb.com/chart/top"}, { "title":"Oscar Gewinner", "type":"search", "url":"http://www.imdb.com/search/title?groups=oscar_best_picture_winners&sort=year,desc&view=simple" }

]

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/pbrink231/plex_top_playlists/issues/35#issuecomment-670950739, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6X6MFJDVZJ4ZDYMUUYLOLR7V76LANCNFSM4MQMVTTA .

pbrink231 commented 4 years ago

Added a couple new updates that should fix these problems. let me know if you run into any problems. git pull

Also on that error can you send it again. should have the guid now

Dex321x commented 4 years ago

@pbrink231 Thank you, the playlists are now generated! I still have the imdb error in the beginning, but it doesn't seem to have an impact on me:

> Creating movie dictionary based on IMDB ID
> IMDB ERROR: 'NoneType' object has no attribute 'group'6.5% ...925 of 1391

I also played around with the new trakt user lists feature which don't work for me (not so important for me, as I'm not planning to use them). But still it maybe interesting for you:

The error:

> count of trakt users lists: 2
> PULLING LIST - Disney: URL: https://api.trakt.tv/users/lish408/lists/disney-animated-films/items - TYPE: None - KIND: playlist
> Traceback (most recent call last):
>   File "./plex_playlist_update.py", line 93, in <module>
>     list_updater(PLEX)
>   File "./plex_playlist_update.py", line 42, in list_updater
>     film_lists = film_lists + trakt_list_loop()
>   File "/opt/appdata/plex_top_playlists/functions/sources/trakt.py", line 12, in trakt_list_loop
>     all_trakt_film_lists += trakt_user_list_loop()
>   File "/opt/appdata/plex_top_playlists/functions/sources/trakt.py", line 88, in trakt_user_list_loop
>     trakt_list_items = trakt_user_list_items(trakt_shows_data)
>   File "/opt/appdata/plex_top_playlists/functions/sources/trakt.py", line 146, in trakt_user_list_items
>     movie['movie']['title']
> NameError: name 'movie' is not defined

settings.ini for trakt users lists:

> trakt-users-list: [
>   { "title": "Disney", "limit": 80, "url":"https://api.trakt.tv/users/lish408/lists/disney-animated-films/items"},
>   { "title": "Pixar", "limit": 80, "url":"https://api.trakt.tv/users/draackje/lists/pixar-feature-films/items"}
>   ]

Thanks again for your help. I am very happy that the lists are working again.

pbrink231 commented 4 years ago

Hey @Dex321x I fixed up the trakt user list. And cleaned up the trakt source overall to make it clearer and easier to add more end points.

If you try again can you give me that IMDB ERROR: 'NoneType' object Error. This time it should have the agent in the error code I was looking for.

Dex321x commented 4 years ago

@pbrink231 Thank you for looking into it. I updated to your latest pull.

> count of trakt movies lists: 0
> count of trakt shows lists: 0
> count of trakt users lists: 0
> count of imdb lists: 2
> 
pbrink231 commented 4 years ago

@Dex321x, Should be good now. Let me know if you run into any problems

Dex321x commented 4 years ago

@pbrink231 I'm sorry to bother you again. Now the script won't run at all

> python3 ./plex_playlist_update.py run
>   File "./plex_playlist_update.py", line 121
>     remove_shared_playlist(PLEX, USERS = get_all_users(PLEX), sys.argv[2])
>                                                              ^
> SyntaxError: positional argument follows keyword argument
> 
pbrink231 commented 4 years ago

@Dex321x sorry that was a fix right before pushing. Should be good now

Dex321x commented 4 years ago

@pbrink231 script runs again, but still don't regognize the trakt movies:

count of trakt movies lists: 0 count of trakt shows lists: 0 count of trakt users lists: 0

pbrink231 commented 4 years ago

@Dex321x I believe it is probably because of a missing comma in the settings file. Can you check. I will make an error show when the settings file is messed up. Right now it just ignores the list. Noticed this weekend.

pbrink231 commented 4 years ago

Put in a message now that shows above the starting banner if there are issues with the settings.ini file format.

Dex321x commented 4 years ago

yes, maybe i had some typo in the settings.ini. Now it runs nicely and also pulls the trakt user lists :-)!

I use the following entries in settings.ini (just for info, if someone has a similar problem in the future)

trakt-movie-list: [
  { "title": "Movies Top Weekly", "type":"watched", "limit": 80, "url":"https://api.trakt.tv/movies/watched/weekly"},
  { "title": "Movies Top Monthly", "type":"watched", "limit": 80, "url":"https://api.trakt.tv/movies/watched/monthly"},
  { "title": "Movies Top Yearly", "type":"watched", "limit": 80, "url":"https://api.trakt.tv/movies/watched/yearly"},
  { "title": "Movies Top All Time", "type":"watched", "limit": 80, "url":"https://api.trakt.tv/movies/watched/all"},
  { "title": "Movies Top Trending", "type":"trending", "limit": 80, "url":"https://api.trakt.tv/movies/trending"},
  { "title": "Movies Popular", "type":"popular", "limit": 80, "url":"https://api.trakt.tv/movies/popular", "show_summary": "False"}
  ]

## Show list
trakt-tv-list: [
  { "title": "Show Top Weekly", "type":"watched", "limit": 20, "url":"https://api.trakt.tv/shows/watched/weekly"},
  { "title": "Show Popular", "type":"popular", "limit": 20, "url":"https://api.trakt.tv/shows/popular", "show_summary": "False"}
  ]

## Users list
# The URL has an add '/items' at the end.  Please be aware of that when copying the url from the website
# Also when copying a url from web add the 'api' before trakt.tv

trakt-users-list: [
  { "title": "Disney", "limit": 80, "url":"https://api.trakt.tv/users/lish408/lists/disney-animated-films/items"},
  { "title": "Pixar", "limit": 80, "url":"https://api.trakt.tv/users/draackje/lists/pixar-feature-films/items"}
  ]
pbrink231 commented 4 years ago

@Dex321x Thank you for all the help testing out develop branch. I have pulled the develop branch into master now so you can go back to that branch and update it git checkout master git pull