vidhimudaliar commited on
Commit
4e7ff38
·
verified ·
1 Parent(s): 43e41f2

Update assets/js/all_videos.js

Browse files
Files changed (1) hide show
  1. assets/js/all_videos.js +136 -27
assets/js/all_videos.js CHANGED
@@ -1,8 +1,6 @@
1
  // assets/js/all_videos.js
2
 
3
  const CSV_PATH = "cleaned_data.csv";
4
-
5
- /* >>> DATASET VIDEO BASE <<< */
6
  const VIDEO_DATASET_BASE =
7
  "https://huggingface.co/datasets/therarelab/codebook-videos/resolve/main/videos/";
8
 
@@ -16,18 +14,46 @@ function parseCSV(text) {
16
  const lines = text.trim().split("\n");
17
  const header = lines[0].split(",").map(s => s.trim());
18
  const rows = [];
19
-
20
  for (let i = 1; i < lines.length; i++) {
21
  const cols = lines[i].split(",");
22
  const obj = {};
23
- for (let j = 0; j < header.length; j++) {
24
- obj[header[j]] = (cols[j] ?? "").trim();
25
- }
26
  rows.push(obj);
27
  }
28
  return rows;
29
  }
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  function render(rows) {
32
  tbody.innerHTML = "";
33
 
@@ -47,35 +73,21 @@ function render(rows) {
47
  shown++;
48
  uniqueVideos.add(filename);
49
 
50
- const video_url =
51
- VIDEO_DATASET_BASE + encodeURIComponent(filename);
52
-
53
  const tr = document.createElement("tr");
54
-
55
  tr.innerHTML = `
56
  <td>${filename}</td>
57
  <td>
58
  <a href="category.html?cat=${encodeURIComponent(label)}"
59
- style="color: var(--accent); text-decoration: none;">
60
- ${label}
61
  </a>
62
  </td>
63
  <td>${start}-${end}</td>
64
- <td class="video-cell">
65
- <video preload="metadata" controls>
66
- <source src="${video_url}" type="video/mp4">
67
- </video>
68
- </td>
69
  `;
70
 
71
- const videoEl = tr.querySelector("video");
72
-
73
- attachLabeledLoop(videoEl, {
74
- label,
75
- startFrame: start,
76
- endFrame: end,
77
- fps: DEFAULT_FPS
78
- });
79
 
80
  tbody.appendChild(tr);
81
  }
@@ -93,6 +105,103 @@ fetch(CSV_PATH)
93
  })
94
  .catch(err => {
95
  console.error(err);
96
- tbody.innerHTML =
97
- `<tr><td colspan="4">Could not load cleaned_data.csv</td></tr>`;
98
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  // assets/js/all_videos.js
2
 
3
  const CSV_PATH = "cleaned_data.csv";
 
 
4
  const VIDEO_DATASET_BASE =
5
  "https://huggingface.co/datasets/therarelab/codebook-videos/resolve/main/videos/";
6
 
 
14
  const lines = text.trim().split("\n");
15
  const header = lines[0].split(",").map(s => s.trim());
16
  const rows = [];
 
17
  for (let i = 1; i < lines.length; i++) {
18
  const cols = lines[i].split(",");
19
  const obj = {};
20
+ for (let j = 0; j < header.length; j++) obj[header[j]] = (cols[j] ?? "").trim();
 
 
21
  rows.push(obj);
22
  }
23
  return rows;
24
  }
25
 
26
+ function makeLoadButtonCell({ filename, label, start, end }) {
27
+ const video_url = VIDEO_DATASET_BASE + encodeURIComponent(filename);
28
+
29
+ const wrap = document.createElement("div");
30
+ wrap.className = "video-cell";
31
+
32
+ // Lightweight placeholder
33
+ wrap.innerHTML = `
34
+ <div style="display:flex; flex-direction:column; gap:8px;">
35
+ <button class="btn" style="width:max-content;">▶ Load clip</button>
36
+ <div class="note" style="margin:0; opacity:0.85;">
37
+ Loads video on demand (faster page).
38
+ </div>
39
+ </div>
40
+ `;
41
+
42
+ const btn = wrap.querySelector("button");
43
+ btn.addEventListener("click", () => {
44
+ // Replace placeholder with actual video
45
+ wrap.innerHTML = `
46
+ <video preload="metadata" controls playsinline>
47
+ <source src="${video_url}" type="video/mp4">
48
+ </video>
49
+ `;
50
+ const videoEl = wrap.querySelector("video");
51
+ attachLabeledLoop(videoEl, { label, startFrame: start, endFrame: end, fps: DEFAULT_FPS });
52
+ });
53
+
54
+ return wrap;
55
+ }
56
+
57
  function render(rows) {
58
  tbody.innerHTML = "";
59
 
 
73
  shown++;
74
  uniqueVideos.add(filename);
75
 
 
 
 
76
  const tr = document.createElement("tr");
 
77
  tr.innerHTML = `
78
  <td>${filename}</td>
79
  <td>
80
  <a href="category.html?cat=${encodeURIComponent(label)}"
81
+ style="color: var(--accent); text-decoration:none;">
82
+ ${label}
83
  </a>
84
  </td>
85
  <td>${start}-${end}</td>
86
+ <td></td>
 
 
 
 
87
  `;
88
 
89
+ const tdVideo = tr.querySelectorAll("td")[3];
90
+ tdVideo.appendChild(makeLoadButtonCell({ filename, label, start, end }));
 
 
 
 
 
 
91
 
92
  tbody.appendChild(tr);
93
  }
 
105
  })
106
  .catch(err => {
107
  console.error(err);
108
+ tbody.innerHTML = `<tr><td colspan="4">Could not load cleaned_data.csv</td></tr>`;
 
109
  });
110
+
111
+
112
+ // const CSV_PATH = "cleaned_data.csv";
113
+
114
+ // /* >>> DATASET VIDEO BASE <<< */
115
+ // const VIDEO_DATASET_BASE =
116
+ // "https://huggingface.co/datasets/therarelab/codebook-videos/resolve/main/videos/";
117
+
118
+ // const searchInput = document.getElementById("search");
119
+ // const tbody = document.querySelector("#segmentsTable tbody");
120
+
121
+ // const rowsCountEl = document.getElementById("rowsCount");
122
+ // const videosCountEl = document.getElementById("videosCount");
123
+
124
+ // function parseCSV(text) {
125
+ // const lines = text.trim().split("\n");
126
+ // const header = lines[0].split(",").map(s => s.trim());
127
+ // const rows = [];
128
+
129
+ // for (let i = 1; i < lines.length; i++) {
130
+ // const cols = lines[i].split(",");
131
+ // const obj = {};
132
+ // for (let j = 0; j < header.length; j++) {
133
+ // obj[header[j]] = (cols[j] ?? "").trim();
134
+ // }
135
+ // rows.push(obj);
136
+ // }
137
+ // return rows;
138
+ // }
139
+
140
+ // function render(rows) {
141
+ // tbody.innerHTML = "";
142
+
143
+ // const q = (searchInput.value || "").toLowerCase().trim();
144
+ // const uniqueVideos = new Set();
145
+ // let shown = 0;
146
+
147
+ // for (const r of rows) {
148
+ // const filename = r.filename || "";
149
+ // const label = r.label || "";
150
+ // const start = r.start || "";
151
+ // const end = r.end || "";
152
+
153
+ // const hay = `${filename} ${label}`.toLowerCase();
154
+ // if (q && !hay.includes(q)) continue;
155
+
156
+ // shown++;
157
+ // uniqueVideos.add(filename);
158
+
159
+ // const video_url =
160
+ // VIDEO_DATASET_BASE + encodeURIComponent(filename);
161
+
162
+ // const tr = document.createElement("tr");
163
+
164
+ // tr.innerHTML = `
165
+ // <td>${filename}</td>
166
+ // <td>
167
+ // <a href="category.html?cat=${encodeURIComponent(label)}"
168
+ // style="color: var(--accent); text-decoration: none;">
169
+ // ${label}
170
+ // </a>
171
+ // </td>
172
+ // <td>${start}-${end}</td>
173
+ // <td class="video-cell">
174
+ // <video preload="metadata" controls>
175
+ // <source src="${video_url}" type="video/mp4">
176
+ // </video>
177
+ // </td>
178
+ // `;
179
+
180
+ // const videoEl = tr.querySelector("video");
181
+
182
+ // attachLabeledLoop(videoEl, {
183
+ // label,
184
+ // startFrame: start,
185
+ // endFrame: end,
186
+ // fps: DEFAULT_FPS
187
+ // });
188
+
189
+ // tbody.appendChild(tr);
190
+ // }
191
+
192
+ // rowsCountEl.textContent = `${shown} segments`;
193
+ // videosCountEl.textContent = `${uniqueVideos.size} videos`;
194
+ // }
195
+
196
+ // fetch(CSV_PATH)
197
+ // .then(r => r.text())
198
+ // .then(text => {
199
+ // const rows = parseCSV(text);
200
+ // render(rows);
201
+ // searchInput.addEventListener("input", () => render(rows));
202
+ // })
203
+ // .catch(err => {
204
+ // console.error(err);
205
+ // tbody.innerHTML =
206
+ // `<tr><td colspan="4">Could not load cleaned_data.csv</td></tr>`;
207
+ // });