ZeroQI / Lambda.bundle

Local Media Export, a reverse Plex 'Local Media Assets' agent to export metadata locally
GNU General Public License v3.0
134 stars 18 forks source link

Exception: "Argument must be bytes or unicode, got 'NoneType'" #29

Closed Fribb closed 3 years ago

Fribb commented 3 years ago

I'm trying to set up the Agent mainly to export the Metadata in plex to a local location. The Agent creates the NFO file as well as the fanart.jpg and poster.jpg files.

Even though the Agent loads the Actors from the Media Container it is unable to add them in the NFO file. The Agent throws an exception NoneType

2021-03-29 09:18:30,043 (1538e0908700) : INFO (init:142) - SaveFile("Emily Blunt", "/media/real/test2/A Quiet Place (2018)", "movies_nfo", "movie.nfo"...) xml_field: "{'actor': {'role': {'text': 'Evelyn Abbott'}, 'name': {'text': 'Emily Blunt'}, 'thumb': None}}" 2021-03-29 09:18:30,043 (1538e0908700) : INFO (init:210) - [?] plex_value: "Emily Blunt", type: "<type 'str'>" 2021-03-29 09:18:30,044 (1538e0908700) : INFO (init:210) - [?] local_value: "None", type: "<type 'NoneType'>" 2021-03-29 09:18:30,044 (1538e0908700) : INFO (init:210) - [@] Local update movies_nfo: /media/real/test2/A Quiet Place (2018)/movie.nfo, ratingKey: 2021-03-29 09:18:30,044 (1538e0908700) : INFO (init:124) - [X] tag: "actor" created with attributes: "{'thumb': None}" 2021-03-29 09:18:30,044 (1538e0908700) : INFO (init:695) - PLEX_URL_MOVIES - Exception: "Argument must be bytes or unicode, got 'NoneType'", e.message: Argument must be bytes or unicode, got 'NoneType', e.args: (u"Argument must be bytes or unicode, got 'NoneType'",)

Full log com.plexapp.agents.lambda.log (also contains Agent Settings)

I tested this with the TheMovieDB Agent but also with the Plex Movie (Legacy) Agent just to make sure it isn't an issue with the Main Metadata Provider. The Agents add the actors correctly but they are not saved locally.

ZeroQI commented 3 years ago

Weird, none of the line number match latest source code (init:line_number) " created with attributes: " line 113 part of xml_import() seem like it tries string conversion on None variable... Exception thrown handled line 418, with actors loop line 405, possible fix by replacing line 405 with: for tag in xml.iterdescendants('Role' ): SaveFile(tag.get('tag'), path, 'movies_nfo', nfo_xml=nfo_xml, xml_field={'actor': {'role': {'text': tag.get('role')}, 'name': {'text': tag.get('tag')}, 'thumb': {'text': tag.get('thumb')} if 'thumb' in tag else ""}}, multi='actor', tag_multi='name'); roles.append(tag.get('tag'))

Fribb commented 3 years ago

Weird, none of the line number match latest source code (init:line_number)

I downloaded it yesterday Morning as the GitHub zip file so that is the current version in the Repository, unless there is some weird thing going on packaging the resources into a zip file.

Exception thrown handled line 418, with actors loop line 405, possible fix by replacing line 405 with:

I replaced the line 405 with the code you suggested and now the cast is added to the movie.nfo file. Unfortunately, the thumb attribute is not filled and I don't see any log output that the thumb is being downloaded or written to the local folder.

com.plexapp.agents.lambda.log

ZeroQI commented 3 years ago

OK, that picture URL is in the XML

<Role id="2806" filter="actor=2806" tag="Emily Blunt" role="Evelyn Abbott" thumb="http://image.tmdb.org/t/p/original/jqlqq3knztTnty5rcMg5evqZRCa.jpg"/>
<Role id="2807" filter="actor=2807" tag="John Krasinski" role="Lee Abbott" thumb="http://image.tmdb.org/t/p/original/870Q2fbqnmcKuQL80KNdTPOVyhn.jpg"/>
<Role id="2808" filter="actor=2808" tag="Millicent Simmonds" role="Regan Abbott" thumb="http://image.tmdb.org/t/p/original/vn7hejb0IRFvSrZxpxqY9RbBxMe.jpg"/>
<Role id="2809" filter="actor=2809" tag="Noah Jupe" role="Marcus Abbott" thumb="http://image.tmdb.org/t/p/original/jWjCdGnx9UiNXhVprQ92wtqfEAy.jpg"/>
<Role id="2810" filter="actor=2810" tag="Cade Woodward" role="Beau Abbott" thumb="http://image.tmdb.org/t/p/original/6tXfrNe9ilHeAby6Eg5tNvq5MGY.jpg"/>
<Role id="2811" filter="actor=2811" tag="Leon Russom" role="Man in the Woods" thumb="http://image.tmdb.org/t/p/original/AsUwlDzw4Clrutw8Y0bRplCwIAw.jpg"/>

'thumb' in tag test should work as tag is a dict but apparently not, and 'get' does not generate key errors so removing the thumb test, please test and report and if working will update line 472 too for series: for tag in xml.iterdescendants('Role' ): SaveFile(tag.get('tag'), path, 'movies_nfo', nfo_xml=nfo_xml, xml_field={'actor': {'role': {'text': tag.get('role')}, 'name': {'text': tag.get('tag')}, 'thumb': {'text': tag.get('thumb', '')}}}, multi='actor', tag_multi='role'); roles.append(tag.get('tag'))

Fribb commented 3 years ago

Okay, I replaced the line 405 and 471-473 with the new line.

The Cast is now added to the movie.nfo file as thumb, I have not tested it with a TV Show though. But I only get the fanart.jpg, poster.jpg and movie.nfo files next to the movie. Is that intended or is there still something missing?

com.plexapp.agents.lambda.log

ZeroQI commented 3 years ago

Hi, it looks like the fix worked For actor pics, a URL in the agent is added to the meta for actors and the URL is got back from the metadata, it is not saved as posters are with the url thumbnail as key, alongside with the image and URL, and i get this URL thumb back from the meta so acting as designed