Wideband autonomous SDR analysis engine forked from sdr-visual-suite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
939B

  1. package recorder
  2. import (
  3. "encoding/json"
  4. "os"
  5. "path/filepath"
  6. "sort"
  7. "time"
  8. )
  9. type Recording struct {
  10. ID string `json:"id"`
  11. Start time.Time `json:"start"`
  12. CenterHz float64 `json:"center_hz"`
  13. Path string `json:"path"`
  14. }
  15. func ListRecordings(root string) ([]Recording, error) {
  16. entries, err := os.ReadDir(root)
  17. if err != nil {
  18. if os.IsNotExist(err) {
  19. return nil, nil
  20. }
  21. return nil, err
  22. }
  23. var out []Recording
  24. for _, e := range entries {
  25. if !e.IsDir() {
  26. continue
  27. }
  28. id := e.Name()
  29. metaPath := filepath.Join(root, id, "meta.json")
  30. b, err := os.ReadFile(metaPath)
  31. if err != nil {
  32. continue
  33. }
  34. var m Meta
  35. if err := json.Unmarshal(b, &m); err != nil {
  36. continue
  37. }
  38. out = append(out, Recording{ID: id, Start: m.Start, CenterHz: m.CenterHz, Path: filepath.Join(root, id)})
  39. }
  40. sort.Slice(out, func(i, j int) bool { return out[i].Start.After(out[j].Start) })
  41. return out, nil
  42. }