Preparation for using the Radiotray-NG Bookmarks file
Just setting up a single web radio is of course stupid. But that was only at the beginning, when I started to realize my vision. Of course, the remote controlled web radio should offer exactly the same and the multitude of web radio stations as the PC.
One preparation for this was to resolve the bookmarks from Radiotray-NG so that I can include them in a web form. Of course I wanted to do that with jq. First time I really needed to delve into jq syntax. I was successful in the end so I want to post my results. There was a threshold to overcome that wasn’t given in such detail to write down in the documentaries I found.
The key to the goal was to describe the form of the json file in your own words:
bookmarks.json is a single array with the related “group” and “stations” records. A “group”/folder name includes “stations” with arrays of “name” and “url”, and “image”.
If you want to test the command lines below, but don’t have a radiotray-ng installation, you can download the bookmark.json from here.
Output folder names:
jq -r '.[].group' .config/radiotray-ng/bookmarks.json
Output stations:
jq '.[].stations' .config/radiotray-ng/bookmarks.json
The count of folders and stations can easily be determined by appending a pipe and “wc -l” to get the sum of lines.
Output number of folders:
jq -r '.[].group' .config/radiotray-ng/bookmarks.json | wc -l
Output number of stations:
jq '.[].stations[].name' .config/radiotray-ng/bookmarks.json | wc -l
Note that jq starts counting at 0.
Output the first folder:
jq -r '.[0].group' .config/radiotray-ng/bookmarks.json
To print the stations of the first folder, in records with name and url, without image:
jq '.[0].stations' .config/radiotray-ng/bookmarks.json | jq '.[] |{Name: .name, URL: .url}'
To pack the result into an array:
jq '.[0].stations' .config/radiotray-ng/bookmarks.json | jq '[.[] |{Name: .name, URL: .url}]'
The latter is said to be necessary for other output tools in a pipe.
Those would be the basics to make the information from Bookmarks.json available from the point of view of my preparation. It may be incomplete, I will then add that to the posting about the web radio extension if necessary.