Search for Gracenote Station ID's

Since I do this frequently enough I created a script that prompts for a channel name/callsign search phrase, searches Channels DVR for it and saves the sorted tabulated results to a text file named for the search phrase.

Since I occasionally see users asking for a station id, figured I would share the script. Enjoy.

It's a Windows command script I named _Get_stationId.cmd

It should work for anyone using windows that has curl and jq in their path.

If they aren't in your path you could edit this command script to include the paths to them.
i.e. "C:\Path To My Curl Executable\curl" OR "C:\Path To My Jq Executable\jq"
The only other thing you may need to edit is the IP and Port of your Channels DVR Server, if it's not at 192.168.1.4:8089.
These are all on line 26 that starts with curl http://192.168.1.4:8089/

_Get_stationId.cmd
@ECHO OFF
setlocal enabledelayedexpansion
REM we want to pass a double quoted search string to the Channels DVR API endpoint to act as a search phrase to match
REM /tms/stations/"NFL Sunday Ticket"
REM otherwise it searches by ORing the search words
REM /tms/stations/NFL Sunday Ticket
REM so we add url encoded double quotes (%22) around the Station Name search string entered by the user
REM curl doesn't parse a "double quoted string" as a phrase, it breaks it up on spaces, so URL encode spaces (%20) in the Station Name search string
REM in a windows command file the percent sign % must be escaped by preceding it with another percent sign %% otherwise it's interpreted as a parameter passed on the command line
SET "fndthis= "
SET rplwith=%%20
:GETSEARCHSTR
SET _SEARCHSTR=
SET _OUTFNAME=
REM SET /P prompts user for input and assigns it to the variable _SEARCHSTR
SET /P _SEARCHSTR=Enter the Station Name to search for, or press ENTER to cancel: 
REM ECHO You entered "%_SEARCHSTR%"
REM If user pressed ENTER (no search) then EXIT
IF "%_SEARCHSTR%."=="." GOTO FINISHED
REM Save jq tabulated search results in a text file named for the search phrase
SET _OUTFNAME=_stationId_%_SEARCHSTR%.txt
ECHO Searching for Station Names matching "%_SEARCHSTR%"
REM Double quote the search string so Channels DVR treats it as a phrase to match and url encode the double quotes and spaces
SET _SEARCHSTR=%%22!_SEARCHSTR:%fndthis%=%rplwith%!%%22
REM replace 192.168.1.4:8089 in the curl command below with the IP and Port of your Channels DVR Server if different
curl http://192.168.1.4:8089/tms/stations/%_SEARCHSTR% | jq --raw-output "sort_by(.type, .name) | .[] | \"type: \(.type), name: \(.name), callSign: \(.callSign), stationId: \(.stationId), logo: \(.preferredImage.uri)\"" > "%_OUTFNAME%"
ECHO Saved results to file "%_OUTFNAME%"
ECHO.
GOTO GETSEARCHSTR
:FINISHED
EXIT

Example run

Enter the Station Name to search for, or press ENTER to cancel: nfl sunday ticket
Searching for Station Names matching "nfl sunday ticket"
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 18490    0 18490    0     0   319k      0 --:--:-- --:--:-- --:--:--  322k
Saved results to file "_stationId_nfl sunday ticket.txt"

Enter the Station Name to search for, or press ENTER to cancel:
Output File _stationId_nfl sunday ticket.txt
type: Cable Only, name: NFL Sunday Ticket 2 (Sasktel), callSign: NFLS2, stationId: 61188, logo: sources/generic/generic_sources_h3.png
type: Cable Only, name: NFL Sunday Ticket 3 (Sasktel), callSign: NFLS3, stationId: 61189, logo: sources/generic/generic_sources_h3.png
type: Cable Only, name: NFL Sunday Ticket 4 (Sasktel), callSign: NFLS4, stationId: 61198, logo: sources/generic/generic_sources_h3.png
type: Cable Only, name: NFL Sunday Ticket 5 (Sasktel), callSign: NFLS5, stationId: 61199, logo: sources/generic/generic_sources_h3.png
type: Cable Only, name: NFL Sunday Ticket 6 (Sasktel), callSign: NFLS6, stationId: 61202, logo: sources/generic/generic_sources_h3.png
type: Cable Only, name: NFL Sunday Ticket HD - 712, callSign: NFLSHD9, stationId: 106626, logo: https://tmsimg.fancybits.co/assets/s17686_h3_aa.png?w=360&h=270
type: Cable Only, name: NFL Sunday Ticket HD - 714, callSign: NFLSH11, stationId: 106627, logo: https://tmsimg.fancybits.co/assets/s17728_h3_aa.png?w=360&h=270
type: Cable Only, name: NFL Sunday Ticket HD - 717, callSign: NFLSH14, stationId: 106630, logo: https://tmsimg.fancybits.co/assets/s26686_ll_h15_aa.png?w=360&h=270
type: Cable Only, name: NFL Sunday Ticket HD - 718, callSign: NFLSH15, stationId: 106631, logo: https://tmsimg.fancybits.co/assets/s31477_ll_h15_aa.png?w=360&h=270
type: Satellite, name: DirecTV - NFL Sunday Ticket - NFLST, callSign: NFLST, stationId: 20604, logo: sources/generic/generic_sources_h3.png
type: Satellite, name: DirecTV - NFL Sunday Ticket - NFLST10, callSign: NFLST10, stationId: 20821, logo: sources/generic/generic_sources_h3.png
type: Satellite, name: DirecTV - NFL Sunday Ticket - NFLST11, callSign: NFLST11, stationId: 20822, logo: sources/generic/generic_sources_h3.png
type: Satellite, name: DirecTV - NFL Sunday Ticket - NFLST13, callSign: NFLST13, stationId: 20824, logo: sources/generic/generic_sources_h3.png
type: Satellite, name: DirecTV - NFL Sunday Ticket - NFLST14, callSign: NFLST14, stationId: 20825, logo: sources/generic/generic_sources_h3.png
type: Satellite, name: DirecTV - NFL Sunday Ticket - NFLST16, callSign: NFLST16, stationId: 20827, logo: sources/generic/generic_sources_h3.png
type: Satellite, name: DirecTV - NFL Sunday Ticket - NFLST3, callSign: NFLST3, stationId: 20814, logo: sources/generic/generic_sources_h3.png
type: Satellite, name: DirecTV - NFL Sunday Ticket - NFLST4, callSign: NFLST4, stationId: 20815, logo: sources/generic/generic_sources_h3.png
type: Satellite, name: DirecTV - NFL Sunday Ticket - NFLST7, callSign: NFLST7, stationId: 20818, logo: sources/generic/generic_sources_h3.png
type: Satellite, name: DirecTV - NFL Sunday Ticket - NFLST8, callSign: NFLST8, stationId: 20819, logo: sources/generic/generic_sources_h3.png
type: Satellite, name: DirecTV - NFL Sunday Ticket - NFLST9, callSign: NFLST9, stationId: 20820, logo: sources/generic/generic_sources_h3.png
type: Satellite, name: NFL Sunday Ticket - 704, callSign: NFL704, stationId: 17678, logo: https://tmsimg.fancybits.co/assets/s17678_ll_h15_aa.png?w=360&h=270
type: Satellite, name: NFL Sunday Ticket - 705, callSign: NFL705, stationId: 17679, logo: https://tmsimg.fancybits.co/assets/s17679_ll_h15_aa.png?w=360&h=270
type: Satellite, name: NFL Sunday Ticket - 706, callSign: NFL706, stationId: 17680, logo: https://tmsimg.fancybits.co/assets/s17680_ll_h15_aa.png?w=360&h=270
type: Satellite, name: NFL Sunday Ticket - 707, callSign: NFL707, stationId: 17681, logo: https://tmsimg.fancybits.co/assets/s17681_ll_h15_aa.png?w=360&h=270
type: Satellite, name: NFL Sunday Ticket - 708, callSign: NFL708, stationId: 17682, logo: https://tmsimg.fancybits.co/assets/s17682_ll_h15_aa.png?w=360&h=270
type: Satellite, name: NFL Sunday Ticket - 709, callSign: NFL709, stationId: 17683, logo: https://tmsimg.fancybits.co/assets/s17683_ll_h15_aa.png?w=360&h=270
type: Satellite, name: NFL Sunday Ticket - 710, callSign: NFL710, stationId: 17684, logo: https://tmsimg.fancybits.co/assets/s17684_ll_h15_aa.png?w=360&h=270
type: Satellite, name: NFL Sunday Ticket - 711, callSign: NFL711, stationId: 17685, logo: https://tmsimg.fancybits.co/assets/s17685_ll_h15_aa.png?w=360&h=270
type: Satellite, name: NFL Sunday Ticket - 713, callSign: NFL713, stationId: 24258, logo: https://tmsimg.fancybits.co/assets/s24258_ll_h15_aa.png?w=360&h=270
type: Satellite, name: NFL Sunday Ticket - 715, callSign: NFL715, stationId: 17729, logo: https://tmsimg.fancybits.co/assets/s17729_ll_h15_aa.png?w=360&h=270
type: Satellite, name: NFL Sunday Ticket - 716, callSign: NFL716, stationId: 17789, logo: https://tmsimg.fancybits.co/assets/s17789_ll_h15_aa.png?w=360&h=270
type: Satellite, name: NFL Sunday Ticket NFL7 (HDTV), callSign: NFLHD7, stationId: 44458, logo: https://tmsimg.fancybits.co/assets/s112287_ll_h15_aa.png?w=360&h=270
type: Streaming, name: NFL Sunday Ticket 1, callSign: YNFLS1, stationId: 139448, logo: https://tmsimg.fancybits.co/assets/s139448_ll_h15_aa.png?w=360&h=270
type: Streaming, name: NFL Sunday Ticket 10, callSign: YNFLS10, stationId: 139489, logo: https://tmsimg.fancybits.co/assets/s139448_ll_h15_aa.png?w=360&h=270
type: Streaming, name: NFL Sunday Ticket 11, callSign: YNFLS11, stationId: 139490, logo: https://tmsimg.fancybits.co/assets/s139448_ll_h15_aa.png?w=360&h=270
type: Streaming, name: NFL Sunday Ticket 12, callSign: YNFLS12, stationId: 139491, logo: https://tmsimg.fancybits.co/assets/s139448_ll_h15_aa.png?w=360&h=270
type: Streaming, name: NFL Sunday Ticket 13, callSign: YNFLS13, stationId: 139492, logo: https://tmsimg.fancybits.co/assets/s139448_ll_h15_aa.png?w=360&h=270
type: Streaming, name: NFL Sunday Ticket 14, callSign: YNFLS14, stationId: 139493, logo: https://tmsimg.fancybits.co/assets/s139448_ll_h15_aa.png?w=360&h=270
type: Streaming, name: NFL Sunday Ticket 15, callSign: YNFLS15, stationId: 139494, logo: https://tmsimg.fancybits.co/assets/s139448_ll_h15_aa.png?w=360&h=270
type: Streaming, name: NFL Sunday Ticket 16, callSign: YNFLS16, stationId: 139495, logo: https://tmsimg.fancybits.co/assets/s139448_ll_h15_aa.png?w=360&h=270
type: Streaming, name: NFL Sunday Ticket 2, callSign: YNFLS2, stationId: 139481, logo: https://tmsimg.fancybits.co/assets/s139448_ll_h15_aa.png?w=360&h=270
type: Streaming, name: NFL Sunday Ticket 3, callSign: YNFLS3, stationId: 139482, logo: https://tmsimg.fancybits.co/assets/s139448_ll_h15_aa.png?w=360&h=270
type: Streaming, name: NFL Sunday Ticket 4, callSign: YNFLS4, stationId: 139483, logo: https://tmsimg.fancybits.co/assets/s139448_ll_h15_aa.png?w=360&h=270
type: Streaming, name: NFL Sunday Ticket 5, callSign: YNFLS5, stationId: 139484, logo: https://tmsimg.fancybits.co/assets/s139448_ll_h15_aa.png?w=360&h=270
type: Streaming, name: NFL Sunday Ticket 6, callSign: YNFLS6, stationId: 139485, logo: https://tmsimg.fancybits.co/assets/s139448_ll_h15_aa.png?w=360&h=270
type: Streaming, name: NFL Sunday Ticket 7, callSign: YNFLS7, stationId: 139486, logo: https://tmsimg.fancybits.co/assets/s139448_ll_h15_aa.png?w=360&h=270
type: Streaming, name: NFL Sunday Ticket 8, callSign: YNFLS8, stationId: 139487, logo: https://tmsimg.fancybits.co/assets/s139448_ll_h15_aa.png?w=360&h=270
type: Streaming, name: NFL Sunday Ticket 9, callSign: YNFLS9, stationId: 139488, logo: https://tmsimg.fancybits.co/assets/s139448_ll_h15_aa.png?w=360&h=270
type: TMS Specialty, name: NFL SUNDAY TICKET - NFL13, callSign: NFL13, stationId: 40749, logo: sources/generic/generic_sources_h3.png
type: TMS Specialty, name: SEG NFL SUNDAY TICKET 15, callSign: 40799, stationId: 40799, logo: sources/generic/generic_sources_h3.png
2 Likes

Nice! :slightly_smiling_face:

Awesome script/tool. Kudos to you kind sir for sharing.

I added the affiliate call sign to mine
i.e. DABL, CIRCLE, CATCHYC, METV, STARTTV
affiliate: \(.affiliateCallSign)

Either insert it in the above script jq command where you want it, or replace line 29 in the script with this that inserts it between the stationId and logo.

curl http://192.168.1.4:8089/tms/stations/%_SEARCHSTR% | jq --raw-output "sort_by(.type, .name) | .[] | \"type: \(.type), name: \(.name), callSign: \(.callSign), stationId: \(.stationId), affiliate: \(.affiliateCallSign), logo: \(.preferredImage.uri)\"" > "%_OUTFNAME%"
Example Output File _stationId_wbbm.txt
type: Cable Only, name: WBBM-DT2 (Duplicate Feed), callSign: WBBM2SD, stationId: 96857, affiliate: STARTTV, logo: https://tmsimg.fancybits.co/assets/s109454_h3_aa.png?w=360&h=270
type: Full Power Broadcast, name: SPAN WBBM 02, callSign: ESWBBM, stationId: 37405, affiliate: CBS, logo: https://tmsimg.fancybits.co/assets/s10098_ll_h15_ac.png?w=360&h=270
type: Full Power Broadcast, name: WBBM, callSign: WBBM, stationId: 11299, affiliate: CBS, logo: https://tmsimg.fancybits.co/assets/s10098_h3_aa.png?w=360&h=270
type: Full Power Broadcast, name: WBBM-DT, callSign: WBBMDT, stationId: 20454, affiliate: CBS, logo: https://tmsimg.fancybits.co/assets/s28711_ll_h15_ab.png?w=360&h=270
type: Full Power Broadcast, name: WBBM-DT2, callSign: WBBMDT2, stationId: 91649, affiliate: STARTTV, logo: https://tmsimg.fancybits.co/assets/s109454_ll_h15_ab.png?w=360&h=270
type: Full Power Broadcast, name: WBBM-DT3, callSign: WBBMDT3, stationId: 112504, affiliate: DABL, logo: https://tmsimg.fancybits.co/assets/s112157_ll_h9_aa.png?w=360&h=270
type: Full Power Broadcast, name: WBBM-DT4, callSign: WBBMDT4, stationId: 117193, affiliate: FAVETV, logo: https://tmsimg.fancybits.co/assets/s117058_ll_h15_aa.png?w=360&h=270
type: Full Power Broadcast, name: WBBM-DT5, callSign: WBBMDT5, stationId: 141301, affiliate: CIRCLE, logo: https://tmsimg.fancybits.co/assets/s113430_h3_ba.png?w=360&h=270
type: Low Power Broadcast, name: WBBM-LD, callSign: WBBMLD, stationId: 88518, affiliate: CBS, logo: https://tmsimg.fancybits.co/assets/s28711_h3_ba.png?w=360&h=270
type: Low Power Broadcast, name: WBBM-LD2, callSign: WBBMLD2, stationId: 98552, affiliate: CATCHYC, logo: https://tmsimg.fancybits.co/assets/s91415_ll_h15_ab.png?w=360&h=270
type: Streaming, name: NFL on WBBM, callSign: WBBMNFL, stationId: 119699, affiliate: null, logo: https://tmsimg.fancybits.co/assets/s28711_ll_h15_ab.png?w=360&h=270
3 Likes