Giter Club home page Giter Club logo

json2shell's Introduction

json2shell

Parses the provided JSON file, and outputs it as equivalent shell commands to set shell variables.

It is not very sophisticated, it doesn't need to be for my purposes. I would have just used jq, but it has a few shortcomings that meant I couldn't make it work for parsing MCE Buddy files emitted by Channels DVR.

Typical usage:

eval $( json2shell <json filename> )

Use with Channels DVR

Channels DVR can optionally emit JSON files alongside recordings, in the style used by MCE Buddy. Unfortunately MCE Buddy is exclusive to Windows. The information is still valuable so I wanted to take advantage of that extra info when post-processing Channels DVR recordings.

This little tool gets the information in those simple JSON files into shell variables so I can use them easily in my scripts.

Example

Suppose I have a file Courageous Love (2017) 2021-05-13-2200.json that Channels DVR created which has the contents:

{"Description":"Alex has to choose between saving his family's company or following his heart.", 
 "Episode":0,"Genres":["Drama","Romance"],"IsMovie":true,"IsNews":false,"IsSports":false,
 "MetadataGenerator":"Channels DVR","OriginalBroadcastDateTime":"2017-03-21T00:00:00Z",
 "RecordedDateTime":"2021-05-13T22:00:00Z","Season":0,"SubTitle":"",
 "Title":"Courageous Love (2017)"}

running json2shell on that file produces:

Description="Alex has to choose between saving his family's company or following his heart."
Episode=0
Genres=( "Drama" "Romance" )
IsMovie=1
IsNews=0
IsSports=0
MetadataGenerator="Channels DVR"
OriginalBroadcastDateTime="2017-03-21T00:00:00Z"
RecordedDateTime="2021-05-13T22:00:00Z"
Season=0
SubTitle=""
Title="Courageous Love (2017)"

Noote that the Genres array in the JSON file has been converted to the bash shell syntax for array variables.

By using eval on the output of json2shell, the metadata from the JSON file will be available as equivalent shell variables in shell scripts. This can be useful to determine where to link the recording in a Plex media heirarchy, for example.

For example, my spouse enjoys a particular genre of movie, and so in my scripts, those movies are moved directly to her personal Movie folder, not the main one that the family shares.

Acknoledgements

This executable depends on the cjson library to parse JSON into something C can digest. Thank you, Dave Gamble.

json2shell's People

Contributors

paul-chambers avatar

Stargazers

 avatar

Watchers

 avatar

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.