Comments (10)
The whole Metadata
struct is is getting this error when I run GetPlaylist(int)
Changing RatingCount
to int
now gives me:
"json: cannot unmarshal number into Go struct field Metadata.MediaContainer.Metadata.librarySectionID of type string"
I change librarySectionID
to int
now I get "json: cannot unmarshal number into Go struct field Media.MediaContainer.Metadata.Media.id of type string"
I change that to int and now I get:
"json: cannot unmarshal number into Go struct field Part.MediaContainer.Metadata.Media.Part.id of type string"
I change that now I get "json: cannot unmarshal number into Go struct field Media.MediaContainer.Metadata.Media.optimizedForStreaming of type bool"
I change that to int and it works, but breaks GetSessions()
😅
In #35 I changed the following to satisfy the returned types in GetSessions()
:
librarySectionID
-> int
.Metadata.Media.id
-> int
.Metadata.Media.Part.id
-> int
Media.optimizedForStreaming
-> int
Are you able to test this on your server? Maybe it's just me?
Edit: RatingCount
still works under GetSessions()
, so yes, you are right, that needs to be changed.
from go-plex-client.
For clarity, the following two functions (and more) share the same Metadata
struct when decoding the response body as json from PMS api:
GetSessions()
needs:
Part.ID
-> string
Metadata.LibrarySectionID
-> string
Media.OptimizedForStreaming
-> bool
Media.ID
-> string
GetPlaylist(int)
needs:
Part.ID
-> int
Metadata.LibrarySectionID
-> int
Media.OptimizedForStreaming
-> int
Media.ID
-> int
from go-plex-client.
We should try this solution first: https://stackoverflow.com/questions/49097385/how-to-decode-json-with-type-convert-from-string-to-integer-in-golang-for-non-lo.
Or maybe we should come up with a custom Unmarshaler by implementing the interface json.Unmarshaler
and doing some type conversion when necessary.
I haven't had the chance to test it on my side. My PMS server version is 1.24.5.5173 by the way.
from go-plex-client.
After changing the appropriate properties to use json.Number
, sessions and playlist work fine
The only one that I can't handle is OptimizedForStreaming
, which is either:
- a boolean when fetching a playlist (
GetPlaylist()
) - or an int (0 or 1) when fetching episode metadata (
GetEpisode
)
Custom Unmarshaler may be the best route for this
from go-plex-client.
I found this solution that could resolve our issue here. I may test it in the future. What should I do to reproduce the issue?
from go-plex-client.
Good find! This commit did something similar take care of it, but there are possibly some edge cases that are not well thought out with my commit.
To reproduce the issue I was using the commands: ../plex-client playlist <playlist-id>
which uses GetPlaylist()
and ./plex-client episode <episode-id>
which uses GetEpisode()
from the cli
Edit: ./plex-client metadata <id>
and ./plex-client playlist <id>
should return 0 or 1
./plex-client sessions
should return boolean
// plex can return int (GetMetadata(), GetPlaylist()) or boolean (GetSessions())
Not sure if having different media would affect the output of boolean or int on OptimizedForStreaming
.
Looking forward to your thoughts or suggestions.
from go-plex-client.
I've just tested the fix. While the fix itself works for the field OptimizedForStreaming
, other issues are unfortunately raised with strings being number, int being float and vice versa. Here is a non exhaustive list of some errors I managed to fix by replacing the type in question with json.Number
:
json: cannot unmarshal number into Go struct field Metadata.MediaContainer.Metadata.librarySectionID of type string
json: cannot unmarshal number into Go struct field Media.MediaContainer.Metadata.Media.id of type string
json: cannot unmarshal number into Go struct field Part.MediaContainer.Metadata.Media.Part.id of type string
json: cannot unmarshal number into Go struct field Stream.MediaContainer.Metadata.Media.Part.Stream.id of type string
.
I will work on a separate branch to fix those different issues. I propose to replace very float/int (and some string) fields with json.Number to avoid further issues.
from go-plex-client.
I came up with a working solution. I still have to make some test to make a PR but it fixes the aforementioned issues. Take a look at my branch type-fix
on my profile.
from go-plex-client.
Really great work! Looked it over and I love the naming conventions the dynamic types. I think your PR will nullify #35, so I am looking forward to that.
I am curious about some of the Size
fields that have xml tags but json.Number types as I don't know how it works. Do those still unmarshal as XML, but with json.Number?
Some Size
fields still have type string, is that intended?
Good stuff!
from go-plex-client.
I am curious about some of the Size fields that have xml tags but json.Number types as I don't know how it works. Do those still unmarshal as XML, but with json.Number?
No, it is a mistake on my side. json.Number
will only work when unmarshalling json as far as I know.
Some Size fields still have type string, is that intended?
I'm still working on it and making some tests to see what's the best solution. Of course, it's way more sensible to use an integer type for Size
.
from go-plex-client.
Related Issues (20)
- Implement GetFromLibrary HOT 2
- Make timeout configurable for all HTTP calls HOT 2
- fail to build cli HOT 3
- Unable to parse JSON response from sessions endpoint HOT 8
- convert message to json failed: json: cannot unmarshal string into Go struct field TranscodeSession.progress of type float64
- convert message to json failed: json: cannot unmarshal number into Go struct field Setting.default of type string
- Is this project abandoned? HOT 2
- 406 status code when trying to sign in
- "Cannot unmarshal object into Go value..." when displaying webhooks via cli
- GetSessions() - Fix metadata types HOT 1
- Fix error messages HOT 1
- Use Cloud Build to continually test the client against multiple Plex Media Server versions
- Downloads implementation HOT 5
- Ability to download with folder hierarchy HOT 4
- getLibraries returns nothing HOT 3
- json: cannot unmarshal object into Go struct field SignInResponse.pastSubscriptions of type string HOT 1
- Add functions to wrap GET, DELETE /api/invites/requested APIs
- Clarification on usage of `SignIn`
- Is field "userRating" available ? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-plex-client.