Giter VIP home page Giter VIP logo

Comments (10)

jrudio avatar jrudio commented on May 31, 2024

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.

jrudio avatar jrudio commented on May 31, 2024

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.

anatosun avatar anatosun commented on May 31, 2024

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.

jrudio avatar jrudio commented on May 31, 2024

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.

anatosun avatar anatosun commented on May 31, 2024

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.

jrudio avatar jrudio commented on May 31, 2024

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.

anatosun avatar anatosun commented on May 31, 2024

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.

anatosun avatar anatosun commented on May 31, 2024

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.

jrudio avatar jrudio commented on May 31, 2024

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.

anatosun avatar anatosun commented on May 31, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.