Browse Source

given the format of the json file generated by the "export" function, give me a `jq` command to find all the playback history entries that have "tags".

```git-revs
fa87e56  (Base revision)
HEAD     Save context window contents for jq filter tags feature
```

codemcp-id: 21-untitled
Brandon Wong 4 months ago
parent
commit
71b280f380
1 changed files with 33 additions and 0 deletions
  1. 33 0
      2025-02-24-codemcp-jq-filter-tags.md

+ 33 - 0
2025-02-24-codemcp-jq-filter-tags.md

@@ -0,0 +1,33 @@
+# 2025-02-24 - jq filter tags
+
+## User Request
+given the format of the json file generated by the "export" function, give me a `jq` command to find all the playback history entries that have "tags".
+
+generate an additional command that will do the same thing (as the third example), but only filtering the entries that have the "plus one" tag
+
+## Export JSON Structure
+From `popup/popup.js` lines 768-774:
+```javascript
+const exportData = {
+  playlists,
+  playbackHistory,
+  openTabs,
+  exportDate: new Date().toISOString(),
+};
+```
+
+The `playbackHistory` object has:
+- Keys: video IDs
+- Values: objects containing `history` array, `tags` array, `title`, etc.
+
+## jq Commands Provided
+
+### All entries with any tags:
+```bash
+jq '.playbackHistory | to_entries | map(select(.value.tags | length > 0)) | map({videoId: .key, tags: .value.tags, title: .value.title})' export.json
+```
+
+### Only entries with "plus one" tag:
+```bash
+jq '.playbackHistory | to_entries | map(select(.value.tags | index("plus one"))) | map({videoId: .key, tags: .value.tags, title: .value.title})' export.json
+```