The following is an example for what can be done with the new feature to reference the content of output buffer via %output%, but to use the full potential of this feature it needs another hack to load the content of output buffers into the input buffer and process it with other web source script commands.
The discogs web source does not deliver the total number of tracks of a release. To show how to number the tracks of a release with 5 tracks like 1/5, 1/5, etc. in a script using the discogs WS, we assume we have the following output buffers:
set "tracks" "|||||"
set "TRACK" "1|2|3|4|5|"
Our job now is to count the number of vertical bars in the buffer "tracks" and then to append that number with a slash to the numbers in buffer "TRACK".
The only way (I know so far) to count something in the web source script language is the command json_select_many_count, and that needs a json array as input. Therefore we convert "tracks" into a json array. For this we
- "load" its content
%tracks%into the input buffer, - enclose every vertical bar with quotation marks and separate them with commas
- surround all with a json array structure
- remove the last superflous comma
regexpreplace "^.*" "%tracks%"
replace "|" "\"|\","
regexpreplace "^.*" "{\"array\":[${0}]}"
replace ",]" "]"
Now the input buffer contains the desired json array
{"array":["|","|","|","|","|"]}
and we can go on with
json "on" "current"
json_select_many_count "array"
set "Totaltracks"
outputto "Totaltracks"
sayrest
To append /%Totaltracks% to the track positions we again "load" this time the content of %TRACK% into the input buffer and insert the /5 before the vertical bars.
regexpreplace "^.*" "%TRACK%"
replace "|" "/%Totaltracks%|"
set "TRACK"
outputto "TRACK"
sayrest
Finally we have in TRACK:
1/5|2/5|3/5|4/5|5/5|
Most of these tricks and hacks I got from postings of @rboss and others, and I want to thank them all for sharing their code. Further want to suggest @Florian to make the hack to load the input buffer with regexpreplace, that I needed two times, to an official and documented command, e.g.
setinput String
because it then were easier to find and would run faster.