format-playlists.sh 605 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/bin/bash
  2. if [ $# -eq 0 ]; then
  3. echo "Usage: $0 <export-file.json>" >&2
  4. exit 1
  5. fi
  6. export_file="$1"
  7. if [ ! -f "$export_file" ]; then
  8. echo "Error: File '$export_file' not found" >&2
  9. exit 1
  10. fi
  11. jq -r '
  12. .playlists | to_entries | .[] |
  13. "# \(.key)",
  14. (
  15. [.value[] |
  16. select(.status != "done") |
  17. "\(.url)\t\(.title)"
  18. ] |
  19. if length > 0 then .[] else empty end
  20. ),
  21. (
  22. if ([.value[] | select(.status == "done")] | length) > 0 then
  23. "## Done",
  24. ([.value[] |
  25. select(.status == "done") |
  26. "\(.url)\t\(.title)"
  27. ] | .[])
  28. else
  29. empty
  30. end
  31. ),
  32. ""
  33. ' "$export_file"