INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: MCWS curl > file - inconsistent, anyone have any ideas?  (Read 380 times)

Striker

  • World Citizen
  • ***
  • Posts: 161
MCWS curl > file - inconsistent, anyone have any ideas?
« on: March 02, 2024, 09:58:01 am »

Any insight anyone can provide would be appreciated.

I'm using UNIX ksh for these tests.

Below I have three curl/MCWS commands.  The first correctly redirects the curl output to a file.  The 2nd and 3rd output to the terminal and the out2 and out3 files are empty.

This works and the output is in the out1.txt file using MCWS:Playback/Info

Quote
curl  --connect-timeout 1 --no-progress-meter -m 10 http://localhost:52199/MCWS/v1/Playback/Info?Zone=-1 > out1.txt

The next two, using MCWS:File/GetInfo outputs to the terminal and nothing in the out2.txt and out3.txt file.

Quote
curl  --connect-timeout 1 --no-progress-meter -m 10 http://localhost:52199/MCWS/v1/File/GetInfo?File=34608833&Action=json > out2.txt

curl  --connect-timeout 1 --no-progress-meter -m 10 http://localhost:52199/MCWS/v1/File/GetInfo?File=34608833&Action=json 2> out3.txt

It's like the MCWS:File/GetInfo is writing to the terminal without using stdout or stderr ?
Logged

Hendrik

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 10814
Re: MCWS curl > file - inconsistent, anyone have any ideas?
« Reply #1 on: March 02, 2024, 11:17:19 am »

Its probably the & in the URL, you should quote the URL.
Logged
~ nevcairiel
~ Author of LAV Filters

mattkhan

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4021
Re: MCWS curl > file - inconsistent, anyone have any ideas?
« Reply #2 on: March 02, 2024, 11:18:15 am »

you can also use -o to write the output to a file
Logged

Striker

  • World Citizen
  • ***
  • Posts: 161
Re: MCWS curl > file - inconsistent, anyone have any ideas?
« Reply #3 on: March 02, 2024, 12:35:20 pm »

Its probably the & in the URL, you should quote the URL.

you can also use -o to write the output to a file

Thank you to both of you.

When quoting the url with a > redirect, the output file now has info, but there are no newlines, so one long string.
When quoting the url and using the -o outputfile option, same thing, the out file has data but there are no newlines.

Even stranger... not quoting the url AND using the -o option write to the -o file has data and each data line has the newlines.

Thanks for the help... so much I don't understand, but I can at least get the output I want by using the -o option and not quoting the url.
Logged

mattkhan

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4021
Re: MCWS curl > file - inconsistent, anyone have any ideas?
« Reply #4 on: March 02, 2024, 12:43:05 pm »

Why do you need newlines? Just parse it as json, eg using https://jqlang.github.io/jq/
Logged

Striker

  • World Citizen
  • ***
  • Posts: 161
Re: MCWS curl > file - inconsistent, anyone have any ideas?
« Reply #5 on: March 02, 2024, 01:01:54 pm »

Why do you need newlines? Just parse it as json, eg using https://jqlang.github.io/jq/

Thanks, I looked at it and it sounds complicated from the examples and the manual.  Although it does look easy to convert a single line json file to a prettied up output.

I just ultimately want a list of lines with

name="value"

and I can do that easily in unix shell or C++;
Logged

Hendrik

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 10814
Re: MCWS curl > file - inconsistent, anyone have any ideas?
« Reply #6 on: March 02, 2024, 01:21:09 pm »

MCWS output is not necessarily formatted for human readability. Its in a specified formatting markup, for this particular call, either XML (in the MPL type, default), or JSON.

If you want a format with one entry per line, just running it through jq without parameters will do that, as its default mode is return a human-readable formatting.
Or you can use jq to specifically extract the value(s) you want.

Or just make it output the keys/value in a format you want (its not perfect when the value contains new lines)
Code: [Select]
curl http://localhost:52199/MCWS/v1/File/GetInfo?File=34608833&Action=json | jq -r '.[0] | to_entries[] | "\(.key)=\(.value)"'
Logged
~ nevcairiel
~ Author of LAV Filters

Striker

  • World Citizen
  • ***
  • Posts: 161
Re: MCWS curl > file - inconsistent, anyone have any ideas?
« Reply #7 on: March 02, 2024, 01:35:34 pm »

MCWS output is not necessarily formatted for human readability. Its in a specified formatting markup, for this particular call, either XML (in the MPL type, default), or JSON.

If you want a format with one entry per line, just running it through jq without parameters will do that, as its default mode is return a human-readable formatting.
Or you can use jq to specifically extract the value(s) you want.

Thanks.  In my quest to find an alternative to the PlayingNow plugin, which I only use to get a file of data on track change and then call another program to update all the monitor/TV's with the current MC track/next info.

I've tried Zybec's McMonitor in C++ and got overwhelmed with notifications that I didn't need.  For example on a natural track change, a few seconds before the actual track change I'd get a notification with the current track info but with the playcount and lastPlayed data updated.  I worked around that one, but others showed up and my code got ugly.  McMonitor was really cool and the fault is my coding, not McMonitor.

Then I tried polling MCWS from a C++ program and sometimes, I cannot duplicate it at will, I would get data from MCWS that did not change on a track change (must be my code somehow though, not blaming MCWS).  When I see that, it's usually well over an hour of playing MC and my program running in a continuous 1 second sleep loop.

I've even considered using UNIX shell to do what I need.

I'm really trying, but I feel like I'm somehow in over my head.  I have forgot so much since I retired from software 12 years ago.
Logged
Pages: [1]   Go Up