Wideband autonomous SDR analysis engine forked from sdr-visual-suite
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
997B

  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. EventID int64 `json:"event_id"`
  14. Path string `json:"path"`
  15. }
  16. func ListRecordings(root string) ([]Recording, error) {
  17. entries, err := os.ReadDir(root)
  18. if err != nil {
  19. if os.IsNotExist(err) {
  20. return nil, nil
  21. }
  22. return nil, err
  23. }
  24. var out []Recording
  25. for _, e := range entries {
  26. if !e.IsDir() {
  27. continue
  28. }
  29. id := e.Name()
  30. metaPath := filepath.Join(root, id, "meta.json")
  31. b, err := os.ReadFile(metaPath)
  32. if err != nil {
  33. continue
  34. }
  35. var m Meta
  36. if err := json.Unmarshal(b, &m); err != nil {
  37. continue
  38. }
  39. out = append(out, Recording{ID: id, Start: m.Start, CenterHz: m.CenterHz, EventID: m.EventID, Path: filepath.Join(root, id)})
  40. }
  41. sort.Slice(out, func(i, j int) bool { return out[i].Start.After(out[j].Start) })
  42. return out, nil
  43. }