locaal-ai / obs-urlsource

OBS plugin to fetch data from a URL or file, connect to an API or AI service, parse responses and display text, image or audio on scene
https://obsproject.com/forum/resources/url-api-source-fetch-live-data-and-display-it-on-screen.1756/
GNU General Public License v2.0
185 stars 24 forks source link

Please add item separator setting when there are multiple parts (or an array) #35

Closed Destroy666x closed 1 year ago

Destroy666x commented 1 year ago

Separator setting would be really handy to quickly style output for e.g. news tickers and similar things.

Currently you can, as far as I know:

royshil commented 1 year ago

i think if i use https://github.com/pantor/inja it will enable everything and more you can use loops and expressions in the {{ .. }}

Destroy666x commented 1 year ago

Sounds good

royshil commented 1 year ago

implemented inja in #39

Destroy666x commented 1 year ago

The Windows build failed for now.

royshil commented 1 year ago

The Windows build failed for now.

@Destroy666x windows build works now.

Destroy666x commented 1 year ago

It's "Output Template" that's being rendered, right? First suggestion would be to turn that into a TextEdit textbox then. As from what I see inja loops have multiline syntax.

Another thing is how things are passed into the engine - e.g. array of objects seems to be text.

royshil commented 1 year ago

i can just send the whole parsed response (in case of JSON) and you can use inja to manipulate it as you wish

Destroy666x commented 1 year ago

Not sure about parsed response and how well Inja supports getting data out of it, but whole object/array would be nice for sure.

royshil commented 1 year ago

implemented in #39

Destroy666x commented 1 year ago

Any examples of how to do it with let's say this kind of JSON:

  [
    {
      "something": "something"
    },
    {
      "something": "else"
    }
  ]

?

And format it as something | else | ...

Not too sure how it was solved in the end looking at source.

Destroy666x commented 1 year ago

Example:

I'd expect:

{% for fact in output %}
  {{fact.fact}}
{% endfor %}

to cycle it, but I can't reall get it or anything similar to work. Also with body instead of output.

Destroy666x commented 1 year ago

Ok, nvm, e.g.

{% for fact in body %}
  {{fact.fact}} |||||
{% endfor %}

is in fact working, but it's not fully stable, as I had to hide and show the source for it to be displayes, otherwise it just showed as is. Not too sure what's going on. But I think it's more of a problem with coming back to working state after inja errors out so I'll create a new bug and'll close this as finished.

Destroy666x commented 1 year ago

I guess there's one more question. With the example above, if I use:

$[*].fact

body doesn't seem to change compared to $, it's still just the whole JSON. Is there any way to access that specific JSON path as an array or object specifically, just like body? So that you could use e.g. {{ join(array, " | ") }}

Destroy666x commented 1 year ago

@royshil impossible, I assume?

royshil commented 1 year ago

@Destroy666x i'm not fully following you can you provide a worked example? e.g. with the JSON body and the desired output?

Destroy666x commented 1 year ago

@royshil example is like mentioned above:

body is for whole JSON output as the result is the same for the JSON path above and also for $ (root), even though results are different. Is there any way to have the JSON Path output as body or another variable? I don't think it's possible but I may have missed something.

I'd like to feed the result of that JSON Path to {{ join(body, " | ") }} as body

royshil commented 1 year ago

@Destroy666x let's take this to another clean issue just copy-paste plz