amalakar / pyflix2

Python module for accessing Netflix APIs
http://pyflix2.readthedocs.org/en/latest/
BSD 2-Clause "Simplified" License
11 stars 8 forks source link

Question about queues #2

Open qgriffith-zz opened 12 years ago

qgriffith-zz commented 12 years ago

This is more of a question then a bug. When I pull in my queue using user.get_queues_instant() What I get back is a dictionary full of URL's which I am guessing contains data about each movie in the queue in XML format. What I can't seem to figure out is how to take the URL's returned and get to the actual movie data. For example I want to look at my instant queue and get the top 10 movies in it. I don't see any functions in Netflix.py to pull the data from the URL's. the "get_reccomendations" function does however pull in the movie and box art information for all reccomendations that I have, I am trying to figure out how to get the same data returned in get_queues_instant that get_reccomendations returns. Thanks

amalakar commented 12 years ago

Hey @qgriffith, thats a good find. Let me tell you what I have found till now:

a. In v1 netflix API (It is v1 when you get the user by calling get_user() on NetflixAPIV1) ) Calling get_queues_instant gives you a list of movies which has all the details in it (movie name, href, category, format etc...)

Try running the test case:

python -m unittest test.TestNetflixAPIV1.test_user_queues

b. On the otherhand on v2 it seems the same call returns something like the following:

{u'meta': {u'available queue': u'http://api.netflix.com/users/userid/queues/instant/available', u'etag': u'93900394233', u'queue_length': 71, u'request_id': u'646d837e-b384-4059-95ce-775197fd22a1-118603', u'saved queue': u'http://api.netflix.com/users/userid/queues/instant/saved'}, u'queue': [{u'id': u'http://api.netflix.com/users/userid/queues/instant/available/1/70075470'}, {u'id': u'http://api.netflix.com/users/userid/queues/instant/available/2/70138768'}, ...

And then when trying to fetch the list of ids(http://api.netflix.com/users/userid/queues/instant/available/2/70138768 etc) it returns the same response for all the ids, which looks more like a bug. (I have added a method get_resource() in User which can be used to fetch these ids).

I checked the 2.0 release notes: http://developer.netflix.com/page/Netflix_API_20_Release_Notes it says:

......, expand was used to retrieve extra details about the title links which were included in search results or a queue.....

So I concluded that probably the queues api support expand parameter too. And I added the expand parameter to the various queue methods. Now whenever I pass something as expand parameter the netflix api returns additional information irrespective of what I pass as expand parameter (be it @title, @box_art)

i.e. queues_instant = self.user.get_queues_instant(expand="@title", sort_order="alphabetical", start_index=0, max_results=10)

Try the testcase python -m unittest test.TestNetflixAPIV2.test_user_queues

The v2 behavior seems buggy. We probably may have to clarify this in netflix forum. I would love to know what you observe. See the test cases test_user_queues in test.py and you should be able to play around with these.

Thanks, Arup

qgriffith-zz commented 12 years ago

Thanks so much for the info I was losing my mind on how to get the titles of movies. I will give what you suggested a try later on today and report back. If it looks like a bug with the Netflix API I can post it on the forum.

amalakar commented 12 years ago

It would be great if you can post in the netflix forum. If you report the forum url back, I can keep an eye on the netflix discussion too.

Thanks, Arup

qgriffith-zz commented 12 years ago

Once I removed an extra space from the end of my access_token in the .pyflix.cfg file I got the test to work. The URL was adding %20 to the end of the access_token.

API V1 Test looks great

python -m unittest test.TestNetflixAPIV1.test_user_queues Instant Queue Movies: Arrested Development Battle Royale Black Death Centurion Colin & Brad: Two Man Group Die Hard 2: Die Harder Doctor Who Doctor Who: The End of Time Dr. Horrible's Sing-Along Blog Eddie Izzard: Circle

.

Ran 1 test in 2.238s

OK

APIV2 gives a lot more details but it is showing a lot more then i saw last night

u'genres': [{u'id': 83, u'name': u'TV Shows'}, {u'id': 10375, u'name': u'TV Comedies', u'parent': []}, {u'id': 1372, u'name': u'TV Sci-Fi & Fantasy', u'parent': []}], u'id': u'http://api.netflix.com/catalog/titles/movies/70114900', u'maturity_level': 130, u'release_year': u'1999', u'tiny_url': u'http://movi.es/BVmei', u'title': {u'regular': u'Mystery Science Theater 3000: Soultaker', u'title_short': u'MST3K: Soultaker'}, u'web_page': u'http://www.netflix.com/Movie/Mystery_Science_Theater_3000_Soultaker/70114900'}}, {u'item': {u'average_rating': 3.7, u'box_art': {u'110pix_w': u'http://cdn-0.nflximg.com/en_us/boxshots/large/443326.jpg', u'124pix_w': u'http://cdn-0.nflximg.com/en_us/boxshots/124/443326.jpg', u'150pix_w': u'http://cdn-0.nflximg.com/en_us/boxshots/150/443326.jpg', u'166pix_w': u'http://cdn-0.nflximg.com/en_us/boxshots/166/443326.jpg', u'197pix_w': u'http://cdn-0.nflximg.com/en_us/boxshots/197/443326.jpg', u'210pix_w': u'http://cdn-0.nflximg.com/en_us/boxshots/gsd/443326.jpg', u'284pix_w': u'http://cdn-0.nflximg.com/en_us/boxshots/ghd/443326.jpg', u'38pix_w': u'http://cdn-0.nflximg.com/en_us/boxshots/tiny/443326.jpg', u'64pix_w': u'http://cdn-0.nflximg.com/en_us/boxshots/small/443326.jpg', u'88pix_w': u'http://cdn-0.nflximg.com/en_us/boxshots/88/443326.jpg'},

qgriffith-zz commented 12 years ago

I think the expands fixed the issue more or less, prior to the expands I would get this for my queue

 pprint.pprint(qu)

{u'meta': {u'available queue': u'http://api.netflix.com/users/T1p2KMu_0K7aoPAWzUFJFk.MtSoND7CcUi.Lg2ZKQfk1U-/queues/instant/available', u'etag': u'140655698226', u'queue_length': 90, u'request_id': u'c36bc9c3-e862-4d1a-9631-5b799a60f0d6-287500', u'saved queue': u'http://api.netflix.com/users/T1p2KMu_0K7aoPAWzUFJFk.MtSoND7CcUi.Lg2ZKQfk1U-/queues/instant/saved'}, u'queue': [{u'id': u'http://api.netflix.com/users/T1p2KMu_0K7aoPAWzUFJFk.MtSoND7CcUi.Lg2ZKQfk1U-/queues/instant/available/1/70051669'}, {u'id': u'http://api.netflix.com/users/T1p2KMu_0K7aoPAWzUFJFk.MtSoND7CcUi.Lg2ZKQfk1U-/queues/instant/available/2/70048309'}, {u'id': u'http://api.netflix.com/users/T1p2KMu_0K7aoPAWzUFJFk.MtSoND7CcUi.Lg2ZKQfk1U-/queues/instant/available/3/70119196'}, {u'id': u'http://api.netflix.com/users/T1p2KMu_0K7aoPAWzUFJFk.MtSoND7CcUi.Lg2ZKQfk1U-/queues/instant/available/4/70138618'}, {u'id': u'http://api.netflix.com/users/T1p2KMu_0K7aoPAWzUFJFk.MtSoND7CcUi.Lg2ZKQfk1U-/queues/instant/available/5/70202589'}, {u'id': u'http://api.netflix.com/users/T1p2KMu_0K7aoPAWzUFJFk.MtSoND7CcUi.Lg2ZKQfk1U-/queues/instant/available/6/70173043'}, {u'id': u'http://api.netflix.com/users/T1p2KMu_0K7aoPAWzUFJFk.MtSoND7CcUi.Lg2ZKQfk1U-/queues/instant/available/7/70122631'}, {u'id': u'http://api.netflix.com/users/T1p2KMu_0K7aoPAWzUFJFk.MtSoND7CcUi.Lg2ZKQfk1U-/queues/instant/available/8/60026028'}, {u'id': u'http://api.netflix.com/users/T1p2KMu_0K7aoPAWzUFJFk.MtSoND7CcUi.Lg2ZKQfk1U-/queues/instant/available/9/70012819'}, {u'id': u'http://api.netflix.com/users/T1p2KMu_0K7aoPAWzUFJFk.MtSoND7CcUi.Lg2ZKQfk1U-/queues/instant/available/10/60035790'}, {u'id': u'http://api.netflix.com/users/T1p2KMu_0K7aoPAWzUFJFk.MtSoND7CcUi.Lg2ZKQfk1U-/queues/instant/available/11/70012823'}, {u'id': u'http://api.netflix.com/users/T1p2KMu_0K7aoPAWzUFJFk.MtSoND7CcUi.Lg2ZKQfk1U-/queues/instant/available/12/70140458'}, {u'id': u'http://api.netflix.com/users/T1p2KMu_0K7aoPAWzUFJFk.MtSoND7CcUi.Lg2ZKQfk1U-/queues/instant/available/13/70142441'}, {u'id': u'http://api.netflix.com/users/T1p2KMu_0K7aoPAWzUFJFk.MtSoND7CcUi.Lg2ZKQfk1U-/queues/instant/available/14/70153394'}, {u'id': u'http://api.netflix.com/users/T1p2KMu_0K7aoPAWzUFJFk.MtSoND7CcUi.Lg2ZKQfk1U-/queues/instant/available/15/70117698'}, {u'id': u'http://api.netflix.com/users/T1p2KMu_0K7aoPAWzUFJFk.MtSoND7CcUi.Lg2ZKQfk1U-/queues/instant/available/16/70201121'}, {u'id': u'http://api.netflix.com/users/T1p2KMu_0K7aoPAWzUFJFk.MtSoND7CcUi.Lg2ZKQfk1U-/queues/instant/available/17/70221573'}, {u'id': u'http://api.netflix.com/users/T1p2KMu_0K7aoPAWzUFJFk.MtSoND7CcUi.Lg2ZKQfk1U-/queues/instant/available/18/70043018'}, {u'id': u'http://api.netflix.com/users/T1p2KMu_0K7aoPAWzUFJFk.MtSoND7CcUi.Lg2ZKQfk1U-/queues/instant/available/19/70143824'}, {u'id': u'http://api.netflix.com/users/T1p2KMu_0K7aoPAWzUFJFk.MtSoND7CcUi.Lg2ZKQfk1U-/queues/instant/available/20/70114900'}, {u'id': u'http://api.netflix.com/users/T1p2KMu_0K7aoPAWzUFJFk.MtSoND7CcUi.Lg2ZKQfk1U-/queues/instant/available/21/443326'}, {u'id': u'http://api.netflix.com/users/T1p2KMu_0K7aoPAWzUFJFk.MtSoND7CcUi.Lg2ZKQfk1U-/queues/instant/available/22/70012821'}, {u'id': u'http://api.netflix.com/users/T1p2KMu_0K7aoPAWzUFJFk.MtSoND7CcUi.Lg2ZKQfk1U-/queues/instant/available/23/70153380'}, {u'id': u'http://api.netflix.com/users/T1p2KMu_0K7aoPAWzUFJFk.MtSoND7CcUi.Lg2ZKQfk1U-/queues/instant/available/24/70140457'}, {u'id': u'http://api.netflix.com/users/T1p2KMu_0K7aoPAWzUFJFk.MtSoND7CcUi.Lg2ZKQfk1U-/queues/instant/available/25/70117577'}], u'track_id': 5711246, u'track_url': u'http://api.netflix.com/catalog?track_id=5711246'}

amalakar commented 12 years ago

Expands seem to have fixed the issue. I anyway have put up the question in netflix forum. http://developer.netflix.com/forum/read/156820 Lets see what do they have to say without this.

I guess I should trim the access_token etc when I read it from the file or probably add the trim in the constructor of NetflixAPIV1/V2 and User itself. I will think about it will try to fix the code when I am home tonight.

Thanks for running the test. This is useful information.

Thanks, Arup

qgriffith-zz commented 12 years ago

I wonder if putting the trim in the library is the correct place, doing so could cause other issues if people wanted to present the access code in different methods instead of using the flat configuration file. Maybe having the trim during reading the configuration file in the example.py would be a better place, just to show that it is needed if you use the configuration file as the method to store the tokens.

amalakar commented 12 years ago

I have added trim in both test.py and example.py

My thought on having the whitespace trim on the constructor was that if the user provides strings having whitespace in the end or starting, the library can recover from this error successfully. Because even if the input comes from other sources (be it from a GUI input textbox) there are chances that their could be whitespace in the end. The issue is whitespaces are difficult for users to notice and they will have to debug like you to figure that there was an unwanted space at the end. If the library trims on its own(only whitespaces of course) then we can recover easily from such errors and can successfully function.

Thanks, Arup

amalakar commented 12 years ago

I don't know why but my earlier netflix forum post (http://developer.netflix.com/forum/read/156820) was removed. I have created a new post http://developer.netflix.com/forum/read/156827 hoping it wont get removed and we would get my answer this time.

Arup

qgriffith-zz commented 12 years ago

Your thinking does make sense now that you explained, so I think you are correct the constructor would be a good place for it. I may run into that very issue once I create a GUI for your library.