[mythtv-users] command line argument processing help

Stephen Worthington stephen_agent at jsw.gen.nz
Wed Mar 21 02:41:16 UTC 2018


On Tue, 20 Mar 2018 22:21:35 -0400, you wrote:

> Hi everyone,
>
>Having a bit of an issue with command line argument processing for my
>custom transcode script.  The transcode command I have set in mythtv is:
>
>/mythtv/bin/transcoderep.sh "%FILE%" "%DESCRIPTION%" "%EPISODE%" "%SEASON%"
>"%TITLE%" "%SUBTITLE%" "%ORIGINALAIRDATE%" "%STARTTIME%" "%ENDTIME%"
>"%STARTTIMEUTC%" "%JOBID%"
>
>In my script I'm parsing the commandline arguments, IE filename="$1",
>description="$2", etc.
>
>Here's the problem:  I've run into a problem with a few shows where the
>description has contained a double quote, causing the obvious problem of it
>thinking the field has ended and bumping all the rest of the arguments down
>the line. I thought about changing the IFS, setting a multi character
>string between each statement and processing it as one long string using
>awk printf against $@, etc.  I'm rather curious how others have handled
>this though as all my ideas have seemed sub-optimal.  Seems like there
>should be a better way and I'm just not aware of it.  Or are those ideas
>how it's supposed to be handled?
>
>
>Thanks!
>
>Scot

I do not think there are any really good ways of handling multi-level
quoting issues.  In this case, I think the first thing to do is to
just move the "%DESCRIPTION%" to be the last argument in the list.
Then you can make your script check for further arguments and see if
you can make it work out how to join up the description bits again
properly.  You can use the bash "shift" command in a loop to process
extra arguments.  If that is insufficient, I think I would try adding
markers that you do not ever expect to find in the description text.
So you could do something like this:

"####!!####" "%DESCRIPTION%" "####==####"

Then your script would look for the markers and use them to say that
everything in between was the description text, and work out how to
put it back together properly.

An alternative to consider is to not pass the "%DESCRIPTION%" at all,
but instead use the "%CHANID%" and "%STARTTIME%" information to do a
lookup of the database recorded table and get the description data
that way.  I think there is an API call to get things from the
recorded database you could use for that.  You would need to add
"%CHANID%" to your arguments for the script.  As I have some code
already to do that sort of database access, I think that is the way I
would do it.


More information about the mythtv-users mailing list