blacktwin / JBOPS

Just a Bunch Of Plex Scripts
1.64k stars 305 forks source link

notify_added_custom fails on foreign actor names #56

Closed startrk1995 closed 6 years ago

startrk1995 commented 6 years ago

The json is decoded there are issues where it will error out when the script tries to process it. I.E.

      'data' => {
                  'actors' => [
                                'Steve Martin',
                                'Michael Caine',
                                'Glenne Headly',
                                'Anton Rodgers',
                                'Barbara Harris',
                                'Ian McDiarmid',
                                'Dana Ivey',
                                'Meagen Fay',
                                'Georges Gerrard Baffos',
                                'Cheryl Pay',
                                'Frances Conroy',
                                'Nicole Calfan',
                                'Lolly Susi',
                                'Valerie Beaufils',
                                'Xavier Maly',
                                'Louis Zorich',
                                **"Andr\x{e9} Penvern",**
                                'Hepburn Graham',
                                'Nathalie Auffret',
                                **"A\x{ef}na Walle"**
                              ],
                  'sort_title' => '',
                  'labels' => [],
                  'rating_key' => '15183',
                  'parent_media_index' => '',
                  'content_rating' => 'PG',
                  'media_type' => 'movie',
                  'duration' => '6621183',
                  'parent_thumb' => '',
                  'updated_at' => '1521426404',
                  'banner' => '',
                  'full_title' => 'Dirty Rotten Scoundrels',

This script will not finish with any actor names that have ` or other non ascii.

blacktwin commented 6 years ago

Can't error out if you're not outputting. 🤔

If you want to output the metadata for a rating_key or add additional metadata information to an email you'll need to .encode('utf-8') it.

Why are you outputting the metadata? What are you trying to do/change?

startrk1995 commented 6 years ago

I added the debug you put in the blacktwin/notify_added_lastweek.py

starbuck93 What I would do to troubleshoot is add:print(json.dumps(response, indent=4, sort_keys=True))to line 84. Make sure to add import json to the top. This will display what is being grabbed during the metadata call. If the added_at is Nonetype it could be that the call isn't grabbing anything. The json print will shed some light on whether that is true or not.

This is the output. I think it is failing on the names. Then main error is at the bottom.

Thanks!!

root@plexmediaserver_1:/var/db/plexdata/Plex Media Server/Scripts # python2.7 notify_added_custom.py -t art -u startrk1995 -d 7
Sending email(s) to startrk1995@gmail.com
{
    "response": {
        "data": {
            "actors": [
                "Steve Martin",
                "Michael Caine",
                "Glenne Headly",
                "Anton Rodgers",
                "Barbara Harris",
                "Ian McDiarmid",
                "Dana Ivey",
                "Meagen Fay",
                "Georges Gerrard Baffos",
                "Cheryl Pay",
                "Frances Conroy",
                "Nicole Calfan",
                "Lolly Susi",
                "Valerie Beaufils",
                "Xavier Maly",
                "Louis Zorich",
                "Andr\u00e9 Penvern",
                "Hepburn Graham",
                "Nathalie Auffret",
                "A\u00efna Walle"
            ],
            "added_at": "1521426387",
            "art": "/library/metadata/15183/art/1521426404",
            "audience_rating": "8.4",
            "banner": "",
            "collections": [],
            "content_rating": "PG",
            "directors": [
                "Frank Oz"
            ],
            "duration": "6621183",
            "full_title": "Dirty Rotten Scoundrels",
            "genres": [
                "Comedy",
                "Crime"
            ],
            "grandparent_rating_key": "",
            "grandparent_thumb": "",
            "grandparent_title": "",
            "guid": "com.plexapp.agents.imdb://tt0095031?lang=en",
            "labels": [],
            "last_viewed_at": "",
            "library_name": "Newly Downloaded",
            "media_index": "",
            "media_info": [
                {
                    "aspect_ratio": "1.85",
                    "audio_channel_layout": "5.1",
                    "audio_channels": "6",
                    "audio_codec": "aac",
                    "audio_profile": "he-aac",
                    "bitrate": "1891",
                    "container": "mp4",
                    "height": "688",
                    "id": "41221",
                    "optimized_version": 0,
                    "parts": [
                        {
                            "file": "/media/Movies/New/Dirty Rotten Scoundrels 1998 720p BRRip x264 AAC-RyD3R (Kingdom-Release)/Dirty Rotten Scoundrels 1998 720p BRRip x264 AAC-RyD3R (Kingdom-Release).mp4",
                            "file_size": "1564954489",
                            "id": "41223",
                            "indexes": 0,
                            "streams": [
                                {
                                    "id": "74218",
                                    "type": "1",
                                    "video_bit_depth": "8",
                                    "video_bitrate": "1667",
                                    "video_codec": "h264",
                                    "video_codec_level": "41",
                                    "video_frame_rate": "23.976",
                                    "video_height": "688",
                                    "video_language": "",
                                    "video_language_code": "",
                                    "video_profile": "high",
                                    "video_ref_frames": "3",
                                    "video_width": "1280"
                                },
                                {
                                    "audio_bitrate": "224",
                                    "audio_bitrate_mode": "",
                                    "audio_channel_layout": "5.1",
                                    "audio_channels": "6",
                                    "audio_codec": "aac",
                                    "audio_language": "",
                                    "audio_language_code": "",
                                    "audio_profile": "he-aac",
                                    "audio_sample_rate": "48000",
                                    "id": "74219",
                                    "type": "2"
                                }
                            ]
                        }
                    ],
                    "video_codec": "h264",
                    "video_framerate": "24p",
                    "video_profile": "high",
                    "video_resolution": "720",
                    "width": "1280"
                }
            ],
            "media_type": "movie",
            "originally_available_at": "1988-12-14",
            "parent_media_index": "",
            "parent_rating_key": "",
            "parent_thumb": "",
            "parent_title": "",
            "rating": "8.8",
            "rating_key": "15183",
            "section_id": "1",
            "sort_title": "",
            "studio": "Orion Pictures",
            "summary": "Two con men try to settle their rivalry by betting on who can swindle a young American heiress out of $50,000 first.",
            "tagline": "Nice guys finish last. Meet the winners.",
            "thumb": "/library/metadata/15183/thumb/1521426404",
            "title": "Dirty Rotten Scoundrels",
            "updated_at": "1521426404",
            "user_rating": "",
            "writers": [
                "Dale Launer",
                "Stanley Shapiro",
                "Paul Henning"
            ],
            "year": "1988"
        },
        "message": null,
        "result": "success"
    }
}
PlexPy API 'get_metadata' request failed: 'metadata'.Traceback (most recent call last):
  File "notify_added_custom.py", line 345, in <module>
    build_parts = [build_html(rating_key, height, width, opts.type) for rating_key in sorted(rating_keys_lst)]
  File "notify_added_custom.py", line 208, in build_html
    added = time.ctime(float(meta.added_at))
AttributeError: 'NoneType' object has no attribute 'added_at'
root@plexmediaserver_1:/var/db/plexdata/Plex Media Server/Scripts #
starbuck93 commented 6 years ago

@startrk1995 I'm not sure you meant to tag me in that.

startrk1995 commented 6 years ago

Sorry.

blacktwin commented 6 years ago

It's failing because it cannot find the attribute 'added_at' because it's looking for it in what is a 'NoneType', so nothing. Can't find 'added_at' inside nothing, which makes sense. Why are you getting nothing? That's the question. You maybe using an older version of the script. I just updated all the script that I knew had issues when running from/with Tautulli. Grab the newest version and try again, please.

startrk1995 commented 6 years ago

Just downloaded new version.

Works just fine. Thanks!! Closing.