dawoudt / JustWatchAPI

Python 3 JustWatch.com API - https://justwatch.com
MIT License
319 stars 45 forks source link

Has anything recently changed in the API #32

Open NYBOYATL opened 5 years ago

NYBOYATL commented 5 years ago

I have had a python program that has worked for months, but now it doesn't. I get the following error using a slimmed down version of original code. I would appreciate any help. Thank you!

Traceback (most recent call last): File "Load - Copy2.py", line 50, in results = jw.search_for_item(providers='amp',content_types['movie'],page=1,monetization_types=["flatrate"]) File "\Load - Copy2.py", line 44, in search_for_item return r.json() File "C:\Users\arosner\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\models.py", line 896, in json return complexjson.loads(self.text, **kwargs) File "C:\Users\arosner\AppData\Local\Programs\Python\Python37-32\lib\json__init__.py", line 348, in loads return _default_decoder.decode(s) File "C:\Users\arosner\AppData\Local\Programs\Python\Python37-32\lib\json\decoder.py", line 340, in decode raise JSONDecodeError("Extra data", s, end) json.decoder.JSONDecodeError: Extra data: line 1 column 5 (char 4)

Slimmed down code:

jw=JustWatch(country='US')

import pdb; pdb.set_trace()

results = jw.search_for_item(providers='amp',content_types=['movie'],page=1,monetization_types=["flatrate"]) print('Done')

lufinkey commented 5 years ago

There's a PR (#31) out to update the search endpoint. JustWatch recently changed it

NYBOYATL commented 5 years ago

Thank you! Did they get rid of total_pages? Is there any other way to ensure you do not pull back too many records?

Thanks

NYBOYATL commented 5 years ago

Never mind. You guys are great! Thank you!

NYBOYATL commented 5 years ago

Sorry to be a pain, but I actually I take that back. "total_pages" no longer seems to be recognized. I want to perform an operation similar to #5 where I only want to loop through the # of pages that I pull back.

Thanks!

draogn commented 5 years ago

Not sure if it's a change, looks like total_pages is only available if you set the page size up front. You do always get total_results back, and you can keep requesting more pages until you get nothing returned. Or you can work out the number of pages from the total_results and the size of the first return. In example below there's 284 results and a default page size of 30. Page 10 has 14 results and Page 11 is empty

jw = JustWatch(country='GB')
just_watch = JustWatch(country='GB')
results = just_watch.search_for_item(query="mission",content_types=['movie'],page=1,page_size=4)
print(results['total_pages'])
print(results.keys())
71
dict_keys(['page', 'page_size', 'total_pages', 'total_results', 'items'])
results2 = just_watch.search_for_item(query="mission",content_types=['movie'])
print(results2.keys())
print(len(results2['items']))
print(results2['total_results'])
print(results2['items'][0]['title'])
dict_keys(['total_results', 'items'])
30
284
Mission: Impossible - Fallout
results2 = just_watch.search_for_item(query="mission",content_types=['movie'],page=2)
print(len(results2['items']))
print(results2['items'][0]['title'])
30
Nazi Overlord
results2 = just_watch.search_for_item(query="mission",content_types=['movie'],page=10)
print(len(results2['items']))
results2 = just_watch.search_for_item(query="mission",content_types=['movie'],page=11)
print(len(results2['items']))
14
0