Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Build SDRTouch Presets from radioreference site
// Put this into Developer console
// on a page like https://www.radioreference.com/apps/db/?inputs=2&ctid=2230
function tableToJs ($table) {
const headers = $('th', $table).map((i, th) => $(th).text().trim())
const out = []
$('tr', $table).each((i, tr) => {
const row = {}
$('td', tr).map((i, td) => {
row[ headers[i] ] = $(td).text()
})
if (Object.keys(row).length > 0) {
out.push(row)
}
})
return out
}
const data = {}
$('table.w1p.rrtable').each((i, table) => {
const $table = $(table)
const title = $table.parent().prev().prev().text()
data[ title ] = tableToJs($table)
})
// at this point you have `data` and you can do what you like
// I'm going to make a SDRTouchPresets.xml
const getFilter = row => {
switch (row.Mode) {
case 'FMN': return 15000
case 'AM': return 75000
default: return 30000 // FM
}
}
const getDem = row => {
switch (row.Mode) {
case 'FMN': return 1
case 'AM': return 2
default : return 0 // FM
}
}
console.log(`<?xml version="1.0" encoding="UTF-8"?>
<sdr_presets version="1">
${Object.keys(data).filter(title => title.trim() !== '').map((title, c) => {
return ` <category id="${c + 1}" name="${title}">\n${data[title].map((row, r) => {
const freq = parseInt(parseFloat(row.Frequency) * 1000000)
return ` <preset id="${r + 1}" name="${row.Description.trim()}" freq="${freq}" centfreq="${freq}" offset="0" order="${r + 1}" filter="${getFilter(row)}" dem="${getDem(row)}"/>`
}).join('\n')}\n </category>`
}).join('\n')}
</sdr_presets>`)
@creuzerm

This comment has been minimized.

Copy link

commented Dec 5, 2017

SDRTouch appears to want the individual presets have unique ID's? I tried to do an import, with the IDs restarting the count at each category, and it failed. I renumbered them to all have unique preset IDs and the import was successful.

Also, I needed to tweak a couple of lines as people put in quotes. I had to change the quotes to single quotes to keep the XML file valid.
<preset id="1" name="Police: Car-to-Car [Ch 5] (Base at "Records")" freq="155040000" centfreq="155040000" offset="0" order="1" filter="30000" dem="0"/>
<preset id="1" name="Police: Car-to-Car "Low Band"" freq="155130000" centfreq="155130000" offset="0" order="1" filter="30000" dem="0"/>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.