-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovieDB.html
337 lines (317 loc) · 12.4 KB
/
movieDB.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Movie Data Collector</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
line-height: 1.6;
color: #333;
}
h1, h2 {
color: #2c3e50;
text-align: center;
}
form {
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #f9f9f9;
border-radius: 8px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
.form-group {
margin-bottom: 15px;
display: flex;
flex-wrap: wrap;
align-items: center;
}
.form-group label {
flex: 1 0 100%;
font-weight: bold;
margin-bottom: 5px;
}
.form-group input, .form-group button, .form-group select {
padding: 8px;
font-size: 14px;
border: 1px solid #ccc;
border-radius: 4px;
}
.form-group input[type="number"], .form-group input[type="text"], .form-group select {
flex: 1 0 auto;
width: 100%;
max-width: 180px;
margin-right: 10px;
margin-bottom: 10px;
}
.row {
display: flex;
gap: 15px;
flex-wrap: wrap;
}
.row .input-wrapper {
flex: 1 0 calc(50% - 15px);
display: flex;
flex-direction: column;
}
.timestamps-container {
display: flex;
flex-direction: column;
gap: 10px;
}
button {
padding: 10px 15px;
background: #3498db;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
margin-top: 10px;
}
button:hover {
background: #2980b9;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
font-size: 14px;
}
table, th, td {
border: 1px solid #ccc;
}
th, td {
padding: 10px;
text-align: left;
}
th {
background-color: #f2f2f2;
cursor: pointer;
}
.timestamp-pair {
display: flex;
gap: 10px;
}
#output {
color: green;
margin-top: 15px;
text-align: center;
}
</style>
</head>
<body>
<h1>Movie Data Collector</h1>
<form id="movieForm">
<!-- Title and Year -->
<div class="form-group row">
<div class="input-wrapper">
<label for="title">Movie Title:</label>
<input type="text" id="title" placeholder="Enter movie title" required>
</div>
<div class="input-wrapper">
<label for="year">Production Year:</label>
<input type="number" id="year" min="1888" max="2099" placeholder="Year">
</div>
</div>
<!-- Runtime and Ratings -->
<div class="form-group row">
<div class="input-wrapper">
<label for="runtime">Runtime (minutes):</label>
<input type="number" id="runtime" min="1" placeholder="Runtime">
</div>
<div class="input-wrapper">
<label for="plotQuality">Plot Quality (1-100):</label>
<input type="number" id="plotQuality" min="1" max="100" placeholder="Plot quality">
</div>
</div>
<div class="form-group row">
<div class="input-wrapper">
<label for="actorsAppearance">Actors Appearance (1-100):</label>
<input type="number" id="actorsAppearance" min="1" max="100" placeholder="Actors appearance">
</div>
<div class="input-wrapper">
<label>
<input type="checkbox" id="sc"> SC
</label>
</div>
</div>
<!-- Plot Driven Field -->
<div class="form-group">
<label for="plotDriven">Plot Driven:</label>
<select id="plotDriven" required>
<option value="">NA</option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
</div>
<!-- Timestamps -->
<div class="form-group">
<label>R-Rated Scene Timestamps:</label>
<div id="timestampsContainer" class="timestamps-container">
<div class="timestamp-pair">
<input type="number" class="scene-start" min="0" placeholder="Start time (min)">
<input type="number" class="scene-end" min="0" placeholder="End time (min)">
</div>
</div>
<button type="button" id="addTimestamp">Add Another Scene</button>
</div>
<!-- Buttons -->
<button type="button" id="saveData">Save Movie</button>
<button type="button" id="exportData">Export Data</button>
<input type="file" id="importData" style="display: none;">
<button type="button" id="importDataTrigger">Import Data</button>
<button type="button" id="clearData">Clear All Data</button>
</form>
<div id="output"></div>
<h2>Saved Movies</h2>
<table id="moviesTable" class="sortable">
<thead>
<tr>
<th>Title</th>
<th>Year</th>
<th>Runtime</th>
<th>Plot Quality</th>
<th>Actors Appearance</th>
<th>SC</th>
<th>Plot Driven</th>
<th>R-Rated Timestamps</th>
<th>% R-Rated</th>
<th>Avg Scene Length</th>
<th>Avg Gap</th>
</tr>
</thead>
<tbody>
<!-- Movie data will be inserted here -->
</tbody>
</table>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tablesort/5.2.1/tablesort.min.js"></script>
<script>
const saveDataBtn = document.getElementById('saveData');
const exportDataBtn = document.getElementById('exportData');
const importDataInput = document.getElementById('importData');
const importDataTrigger = document.getElementById('importDataTrigger');
const addTimestampBtn = document.getElementById('addTimestamp');
const clearDataBtn = document.getElementById('clearData');
const timestampsContainer = document.getElementById('timestampsContainer');
const moviesTable = document.getElementById('moviesTable').querySelector('tbody');
const output = document.getElementById('output');
const storageKey = 'moviesDB';
function loadMovies() {
const data = localStorage.getItem(storageKey);
return data ? JSON.parse(data) : [];
}
function saveMovies(movies) {
localStorage.setItem(storageKey, JSON.stringify(movies));
}
function calculateMetrics(runtime, timestamps) {
const totalRRatedTime = timestamps.reduce((acc, scene) => acc + (scene.end - scene.start), 0);
const averageSceneLength = totalRRatedTime / timestamps.length || 0;
const gaps = timestamps.slice(1).map((scene, i) => scene.start - timestamps[i].end);
const averageGap = gaps.reduce((acc, gap) => acc + gap, 0) / gaps.length || 0;
const rRatedPercentage = ((totalRRatedTime / runtime) * 100).toFixed(2);
return {
rRatedPercentage,
averageSceneLength: averageSceneLength.toFixed(2),
averageGap: averageGap.toFixed(2)
};
}
function updateMoviesTable() {
const movies = loadMovies();
moviesTable.innerHTML = '';
movies.forEach(movie => {
const { rRatedPercentage, averageSceneLength, averageGap } = calculateMetrics(movie.runtime, movie.timestamps);
const row = document.createElement('tr');
row.innerHTML = `
<td>${movie.title || 'NA'}</td>
<td>${movie.year || 'NA'}</td>
<td>${movie.runtime || 'NA'}</td>
<td>${movie.plotQuality || 'NA'}</td>
<td>${movie.actorsAppearance || 'NA'}</td>
<td>${movie.sc ? 'Yes' : 'No'}</td>
<td>${movie.plotDriven || 'NA'}</td>
<td>${movie.timestamps.map(scene => `(${scene.start} - ${scene.end})`).join(', ')}</td>
<td>${rRatedPercentage}%</td>
<td>${averageSceneLength} min</td>
<td>${averageGap} min</td>
`;
moviesTable.appendChild(row);
});
new Tablesort(document.querySelector('.sortable')); // Reinitialize sorting after updating the table
}
document.addEventListener('DOMContentLoaded', () => {
new Tablesort(document.querySelector('.sortable'));
});
saveDataBtn.addEventListener('click', () => {
const movies = loadMovies();
const timestamps = [...document.querySelectorAll('.timestamp-pair')].map(pair => {
const start = Number(pair.querySelector('.scene-start').value);
const end = Number(pair.querySelector('.scene-end').value);
if (!isNaN(start) && !isNaN(end) && start < end) {
return { start, end };
}
return null;
}).filter(Boolean);
const movie = {
title: document.getElementById('title').value.trim() || "NA",
year: Number(document.getElementById('year').value) || "NA",
runtime: Number(document.getElementById('runtime').value) || "NA",
plotQuality: Number(document.getElementById('plotQuality').value) || "NA",
actorsAppearance: Number(document.getElementById('actorsAppearance').value) || "NA",
sc: document.getElementById('sc').checked,
plotDriven: document.getElementById('plotDriven').value || "NA",
timestamps
};
movies.push(movie);
saveMovies(movies);
updateMoviesTable();
output.textContent = 'Movie saved successfully!';
});
exportDataBtn.addEventListener('click', () => {
const movies = loadMovies();
const blob = new Blob([JSON.stringify(movies, null, 2)], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'movies.json';
a.click();
URL.revokeObjectURL(url);
});
importDataTrigger.addEventListener('click', () => {
importDataInput.click();
});
importDataInput.addEventListener('change', event => {
const file = event.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = () => {
const movies = JSON.parse(reader.result);
saveMovies(movies);
updateMoviesTable();
output.textContent = 'Data imported successfully!';
};
reader.readAsText(file);
});
addTimestampBtn.addEventListener('click', () => {
const pair = document.createElement('div');
pair.className = 'timestamp-pair';
pair.innerHTML = `
<input type="number" class="scene-start" min="0" placeholder="Start time (min)">
<input type="number" class="scene-end" min="0" placeholder="End time (min)">
`;
timestampsContainer.appendChild(pair);
});
clearDataBtn.addEventListener('click', () => {
if (confirm('Are you sure you want to clear all data? This action cannot be undone.')) {
localStorage.removeItem(storageKey);
updateMoviesTable();
output.textContent = 'All data has been cleared.';
}
});
// Initialize the table on load
updateMoviesTable();
</script>
</body>
</html>