celiao / tmdbsimple

A wrapper for The Movie Database API v3.
GNU General Public License v3.0
579 stars 122 forks source link

Dirty json response from tmdb #91

Closed VeNoMouS closed 1 year ago

VeNoMouS commented 1 year ago

replace response.json() with dirtyjson.loads(response.content)

 json.loads('''{"movie_results":[{"adult":false,"backdrop_path":"/fILWktCfh0ZiKWjWwyXalWzSvKX.jpg","id":758330,"title":"Good Luck to You, Leo Grande","original_language":"en","original_title":"Good Luck to You, Leo Grande","overview":"Nancy Stokes doesn’t know good sex. Whatever it may be, Nancy, a retired schoolteacher, is pretty sure she has never had it, but she is determined to finally do something about that. She even has a plan: It involves an anonymous hotel room, and a young sex worker who calls himself Leo Grande.","poster_path":"/5wQydIQYho2wz1suPOoPoNgMzCm.jpg","media_type":"movie","genre_ids":[18,35],"popularity":124.142,"release_date":"2022-06-17","video":false,"vote_average":6.993,"vote_count":139}],"person_results":[],"tv_results":[],"tv_episode_results":[],"tv_season_results":[]}
... {"adult":false,"backdrop_path":"/fILWktCfh0ZiKWjWwyXalWzSvKX.jpg","belongs_to_collection":null,"budget":0,"genres":[{"id":18,"name":"Drama"},{"id":35,"name":"Comedy"}],"homepage":"https://www.leograndefilm.co.uk/","id":758330,"imdb_id":"tt13352968","original_language":"en","original_title":"Good Luck to You, Leo Grande","overview":"Nancy Stokes doesn’t know good sex. Whatever it may be, Nancy, a retired schoolteacher, is pretty sure she has never had it, but she is determined to finally do something about that. She even has a plan: It involves an anonymous hotel room, and a young sex worker who calls himself Leo Grande.","popularity":124.142,"poster_path":"/5wQydIQYho2wz1suPOoPoNgMzCm.jpg","production_companies":[{"id":54431,"logo_path":"/v4CjB3zI2xRw1UDSYjwKA8K71gT.png","name":"Genesius Pictures","origin_country":"GB"},{"id":118715,"logo_path":"/mRCdjLcjvRvCqIMovDzOcqmRFfv.png","name":"Cornerstone Films","origin_country":"GB"},{"id":144803,"logo_path":null,"name":"Align","origin_country":"GB"}],"production_countries":[{"iso_3166_1":"GB","name":"United Kingdom"}],"release_date":"2022-06-17","revenue":0,"runtime":97,"spoken_languages":[{"english_name":"English","iso_639_1":"en","name":"English"}],"status":"Released","tagline":"It’s never too late to try something new.","title":"Good Luck to You, Leo Grande","video":false,"vote_average":6.979,"vote_count":141,"trailers":{"quicktime":[],"youtube":[{"name":"Official International Trailer","size":"HD","source":"ndkjJYOprGo","type":"Trailer"},{"name":"Official Trailer","size":"HD","source":"TJcbZoJFLTU","type":"Trailer"},{"name":"\"I've Made A List\" Clip","size":"HD","source":"pdn8UOh1-Yw","type":"Clip"},{"name":"Official Clip - 'Desires are Never Mundane'","size":"HD","source":"eorqhvkji-U","type":"Clip"},{"name":"\"Isn't It Illegal\" Clip","size":"HD","source":"EAab-nMjtK0","type":"Clip"},{"name":"\"Power of Intimacy and Pleasure\" Featurette","size":"HD","source":"u27oCIYIv1M","type":"Featurette"},{"name":"\"Fulfilling Sexual Desires\" Featurette","size":"HD","source":"9E4J1FtfFWc","type":"Featurette"},{"name":"Good Luck to You, Leo Grande | Emma Thompson plus cast & crew at Sundance","size":"HD","source":"0dJLzGYRHqk","type":"Featurette"}]}}''')
Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
  File "/usr/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.7/json/decoder.py", line 340, in decode
    raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 792)
>>>
{
   "movie_results":[
      {
         "adult":false,
         "backdrop_path":"/fILWktCfh0ZiKWjWwyXalWzSvKX.jpg",
         "id":758330,
         "title":"Good Luck to You, Leo Grande",
         "original_language":"en",
         "original_title":"Good Luck to You, Leo Grande",
         "overview":"Nancy Stokes doesn’t know good sex. Whatever it may be, Nancy, a retired schoolteacher, is pretty sure she has never had it, but she is determined to finally do something about that. She even has a plan: It involves an anonymous hotel room, and a young sex worker who calls himself Leo Grande.",
         "poster_path":"/5wQydIQYho2wz1suPOoPoNgMzCm.jpg",
         "media_type":"movie",
         "genre_ids":[
            18,
            35
         ],
         "popularity":124.142,
         "release_date":"2022-06-17",
         "video":false,
         "vote_average":6.993,
         "vote_count":139
      }
   ],
   "person_results":[

   ],
   "tv_results":[

   ],
   "tv_episode_results":[

   ],
   "tv_season_results":[

   ]
}{
   "adult":false,
   "backdrop_path":"/fILWktCfh0ZiKWjWwyXalWzSvKX.jpg",
   "belongs_to_collection":null,
   "budget":0,
   "genres":[
      {
         "id":18,
         "name":"Drama"
      },
      {
         "id":35,
         "name":"Comedy"
      }
   ],
   "homepage":"https://www.leograndefilm.co.uk/",
   "id":758330,
   "imdb_id":"tt13352968",
   "original_language":"en",
   "original_title":"Good Luck to You, Leo Grande",
   "overview":"Nancy Stokes doesn’t know good sex. Whatever it may be, Nancy, a retired schoolteacher, is pretty sure she has never had it, but she is determined to finally do something about that. She even has a plan: It involves an anonymous hotel room, and a young sex worker who calls himself Leo Grande.",
   "popularity":124.142,
   "poster_path":"/5wQydIQYho2wz1suPOoPoNgMzCm.jpg",
   "production_companies":[
      {
         "id":54431,
         "logo_path":"/v4CjB3zI2xRw1UDSYjwKA8K71gT.png",
         "name":"Genesius Pictures",
         "origin_country":"GB"
      },
      {
         "id":118715,
         "logo_path":"/mRCdjLcjvRvCqIMovDzOcqmRFfv.png",
         "name":"Cornerstone Films",
         "origin_country":"GB"
      },
      {
         "id":144803,
         "logo_path":null,
         "name":"Align",
         "origin_country":"GB"
      }
   ],
   "production_countries":[
      {
         "iso_3166_1":"GB",
         "name":"United Kingdom"
      }
   ],
   "release_date":"2022-06-17",
   "revenue":0,
   "runtime":97,
   "spoken_languages":[
      {
         "english_name":"English",
         "iso_639_1":"en",
         "name":"English"
      }
   ],
   "status":"Released",
   "tagline":"It’s never too late to try something new.",
   "title":"Good Luck to You, Leo Grande",
   "video":false,
   "vote_average":6.979,
   "vote_count":141,
   "trailers":{
      "quicktime":[

      ],
      "youtube":[
         {
            "name":"Official International Trailer",
            "size":"HD",
            "source":"ndkjJYOprGo",
            "type":"Trailer"
         },
         {
            "name":"Official Trailer",
            "size":"HD",
            "source":"TJcbZoJFLTU",
            "type":"Trailer"
         },
         {
            "name":"\"I've Made A List\" Clip",
            "size":"HD",
            "source":"pdn8UOh1-Yw",
            "type":"Clip"
         },
         {
            "name":"Official Clip - 'Desires are Never Mundane'",
            "size":"HD",
            "source":"eorqhvkji-U",
            "type":"Clip"
         },
         {
            "name":"\"Isn't It Illegal\" Clip",
            "size":"HD",
            "source":"EAab-nMjtK0",
            "type":"Clip"
         },
         {
            "name":"\"Power of Intimacy and Pleasure\" Featurette",
            "size":"HD",
            "source":"u27oCIYIv1M",
            "type":"Featurette"
         },
         {
            "name":"\"Fulfilling Sexual Desires\" Featurette",
            "size":"HD",
            "source":"9E4J1FtfFWc",
            "type":"Featurette"
         },
         {
            "name":"Good Luck to You, Leo Grande | Emma Thompson plus cast & crew at Sundance",
            "size":"HD",
            "source":"0dJLzGYRHqk",
            "type":"Featurette"
         }
      ]
   }
}

image

That said... dirtyjson wont error , but it will cut off due to the missing ,