| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- #!/bin/bash
- if [ $# -eq 0 ]; then
- echo "Usage: $0 <export-file.json> [tag1] [tag2] ..." >&2
- exit 1
- fi
- export_file="$1"
- shift
- tags=("$@")
- if [ ! -f "$export_file" ]; then
- echo "Error: File '$export_file' not found" >&2
- exit 1
- fi
- if [ ${#tags[@]} -eq 0 ]; then
- jq -r '
- .playbackHistory | to_entries |
- map({
- url: .value.url,
- title: .value.title,
- lastInteraction: ([.value.history[].timestamp] | max)
- }) |
- sort_by(.lastInteraction) | reverse |
- .[] |
- "\((.lastInteraction / 1000 | strftime("%Y-%m-%d %H:%M:%S")))\t\(.url)\t\(.title)"
- ' "$export_file"
- else
- # Build jq filter for tag matching
- tag_filters=""
- for tag in "${tags[@]}"; do
- if [ -n "$tag_filters" ]; then
- tag_filters="$tag_filters and "
- fi
- tag_filters="${tag_filters}(.value.tags // [] | contains([\"$tag\"]))"
- done
- jq -r "
- .playbackHistory | to_entries |
- map(select($tag_filters)) |
- map({
- url: .value.url,
- title: .value.title,
- lastInteraction: ([.value.history[].timestamp] | max)
- }) |
- sort_by(.lastInteraction) | reverse |
- .[] |
- \"\((.lastInteraction / 1000 | strftime(\"%Y-%m-%d %H:%M:%S\")))\\t\(.url)\\t\(.title)\"
- " "$export_file"
- fi
|