42minutes / go-trakt

Go wrapper for the Trakt.tv v2 API.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ID Lookup: search a show by id

varyoo opened this issue · comments

http://docs.trakt.apiary.io/#reference/search/id-lookup/get-id-lookup-results

I tried to add the feature myself, as you can see here: https://github.com/varyoo/go-trakt/blob/id-lookup/shows.go#L42, unfortunately it dosen't works well.

Take the following code:

_, res := trakt.Shows().IdLookup("tvdb", 269613)
println(res.Err.Error())

Output: json: cannot unmarshal string into Go value of type int

I'm not sure why, but I guess it's because we can't specify the type of the results for an ID Lookup (I tried to append &type=show to the URL it dosen't work), so the json parser run into other types of results. (an episode in this case).

Thanks for any help.

Hey @varyoo I added a OneOfType for shows, try this, I made the id a string as imdb ids start with stuff like tt.

showByID, err := client.Shows().OneOfType("tt2802850", "imdb")
fmt.Println(showByID)

I really need to take some time to refactor this library, it was one of my first things with golang and it really could use proper error handling etc.

Wow I wasn't expecting a solution so fast! Thanks @geoah

This is what I needed, I see we should check on showByID being nil for errors.
Also, since &type=show dosen't work, are we sure the show will always be the first result in Trakt?

A good one for a first dive into Golang, looking forward to this refactoring!