Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(nodejq): add more request options and powerful jq commands #2

Merged
merged 19 commits into from
Mar 3, 2021
Merged

Conversation

qistoph
Copy link
Contributor

@qistoph qistoph commented Feb 5, 2021

This PR adds:

  • transparent parameters for request (e.g. method: "POST")
  • jq processing of incoming data
  • multiple MMM-json instances support

This allows me, and others of course, to do really powerful JSON conversions.

I will be using it to display next episodes per TV show available on my Kodi. Example below.

NOTE: The sample provided in the README is dependent on my PR for node-jq.

Kodi example

{
  module: "MMM-json",
  position: "bottom_left",
  header: "TV Shows",
  config: {
    url: "http://user:password@kodi/jsonrpc",
    request: {
      method: "POST",
      json: {
        "jsonrpc":"2.0",
        "method": "VideoLibrary.GetEpisodes",
        "id": "neweps",
        "params": {
          "properties": [
            "title",
            "playcount",
            "showtitle",
            "season",
            "episode"
          ],
          "filter": {
            "field": "playcount",
            "operator": "is",
            "value": "0"
          },
          "sort": {
            "order": "ascending",
            "method": "tvshowtitle",
            "ignorearticle": true
          }
        }
      }
    }
    jq: ".result.episodes | [group_by(.showtitle)[] | {(.[0].showtitle): .[0].label}] | add"
  }
}

This uses the Kodi JSON-RPC to search for unwatched episodes. The result (see below) is converted using a jq command to select only the last episode per show and convert it to a JSON object. Which I don't think would be possible with JSONPath.

{
  "id": "neweps",
  "jsonrpc": "2.0",
  "result": {
    "episodes": [
      {
        "episode": 1,
        "episodeid": 3715,
        "label": "9x01. Episode 1",
        "playcount": 0,
        "season": 9,
        "showtitle": "Call the Midwife",
        "title": "Episode 1"
      },
      {
        "episode": 2,
        ...
        "showtitle": "Call the Midwife",
        ...
      }
      ...
      {
        "episode": 8,
        "episodeid": 3890,
        "label": "3x08. Crisis Theory",
        "playcount": 0,
        "season": 3,
        "showtitle": "Westworld",
        "title": "Crisis Theory"
      }
    ],
    "limits": {
      "end": 100,
      "start": 0,
      "total": 100
    }
  }
}
{
  "Call the Midwife": "9x01. Episode 1",
  "Westworld": "2x01. Journey into Night"
}

@DanielHabenicht
Copy link
Owner

Nice! I will have a look in the evening.

@qistoph
Copy link
Contributor Author

qistoph commented Feb 5, 2021

Had been testing this on a VM and just now found out there is no jq readily available for ARM. Which makes node-jq not work on a Pi...

So this is going to take some more work.

I'll keep you posted

@DanielHabenicht
Copy link
Owner

Maybe use https://github.com/FGRibreau/jq.node ?

@qistoph
Copy link
Contributor Author

qistoph commented Feb 5, 2021

jq.node is indeed quite a nice alternative.
I wasn't familiar with it, but it seems to integrate into NodeJS a lot better than jq.

PR updated to use jq.node.

@DanielHabenicht DanielHabenicht changed the title More request options and powerful jq commands feat(nodejq): add more request options and powerful jq commands Mar 3, 2021
@DanielHabenicht DanielHabenicht merged commit 4f2bf55 into DanielHabenicht:main Mar 3, 2021
@github-actions
Copy link

github-actions bot commented Mar 3, 2021

🎉 This PR is included in version 1.1.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants