Get data from selected item in table

Dear Community,

i have a *csv file in GitHub and there is also a mp3 file for each item. The link to the file consists of the data (confidence, Date, Bird and Time ) of the entry. In an table i can select inidivdual items.
Is it possible to read the selected item out and generate the link (currently hardcoded) to the recorded mp3 file?
The whole Notebook is Fetch Data from Gist / Raw GitHub URL / gitalm / Observable

Thanks for your help.

1 Like

You can access the data of the currently selected row via


or for example


However, I don’t see any index that links your CSV data to the respective MP3 files. And since the filenames seem to include a rather arbitrary number right after the common name, I don’t see a way to “guess” the file name that corresponds to each entry.

Assuming that you do not have an index, I’d recommend the following:

  1. Generate a list of all mp3 files (file path and name)
  2. From each file, extract the date
  3. Index all filenames by date
  4. Index your CSV data by date, using the same format as the files

This should give you an index that lets you match up DB entries and MP3 files.

1 Like

Thanks, this is helped me a lot and i solved the problem with your support. The link to the files are now generated and loaded dynamically.

Only a subset of your DB seems to have a matching mp3 file, then? If that’s the case, I really recommend using a static index of your mp3 files for reference. That way you can also filter out entries without mp3 files.

I’d also suggest to move your path building into a function, along with a few simplifications:

mp3Path = d => `${d.Com_Name}/` + 
  encodeURI(`${d.Com_Name}-${Math.floor(d.Confidence*100)}%-${d.Date.replaceAll('/', '-')}-birdnet-${d.Time}.mp3`)

then use

spec_mp3 = mp3Path(voegel)
1 Like

Dear mootari,
thanks for the help. I had problems to synchronice data from the analysis PC (BirdNETPi) to GitHub, therefore some data has no mp3. But now this is solved and just some old data remains.
To be honest, i’m not capable to make a static index for a better solution.
The idea with the functions is working great and is really simpler.

Best wishes Johannes

1 Like

Here’s a function that lets you list all files:

async function listGithubFiles(owner, repo, options = {}) {
  const {
    ref = 'master',
    prefix = '',
    suffix = '',
    filter = prefix.length || suffix.length
      ? d => (!prefix.length || d.path.startsWith(prefix)) && (!suffix.length || d.path.endsWith(suffix))
      : null,
    map = file => file.path
  } = options;
  return fetch(`${owner}/${repo}/git/trees/${ref}?recursive=1`)
    .then(r => r.json())
    .then(d => filter ? d.tree.filter(filter) : d.tree)
    .then(d => map ? : d);

Use it like this:

files = listGithubFiles('gitalm', 'BirdNetPiGitHub', {prefix: 'By_Common_Name/', suffix: '.mp3'})

You’ll notice that you have 230 entries in your DB, but only 152 files.

I also recommend that you add the file path to your dataset instead of building it on the fly. You could even add a column “file_exists” to allow filtering/sorting. :slight_smile: