-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathposter.html
More file actions
333 lines (289 loc) · 16.1 KB
/
poster.html
File metadata and controls
333 lines (289 loc) · 16.1 KB
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
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Poster</title>
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🎬</text></svg>">
<style>
:root { --tmdb: #01b4e4; --fanart: #ffad00; --dark: #0a0a0a; --success: #27ae60; --error: #e74c3c; }
body { font-family: 'Segoe UI', sans-serif; background: var(--dark); color: white; margin: 0; padding: 20px; }
.wrapper { max-width: 1400px; margin: 0 auto; }
/* ── MODAL ── */
.modal-overlay {
position: fixed; inset: 0; background: rgba(0,0,0,0.85);
display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-overlay.hidden { display: none; }
.modal {
background: #1a1a1a; border: 1px solid #333; border-radius: 16px;
padding: 36px 40px; width: 460px; max-width: 95vw;
}
.modal h2 { margin: 0 0 6px; font-size: 1.2rem; }
.modal p { margin: 0 0 24px; font-size: 0.8rem; color: #888; }
.modal label { display: block; font-size: 0.78rem; color: #aaa; margin-bottom: 6px; letter-spacing: .05em; text-transform: uppercase; }
.modal input[type="text"], .modal input[type="password"] {
width: 100%; box-sizing: border-box; padding: 11px 14px;
background: #2a2a2a; border: 1px solid #444; border-radius: 8px;
color: white; font-size: 0.9rem; outline: none; margin-bottom: 18px;
transition: border-color .2s;
}
.modal input:focus { border-color: var(--tmdb); }
.modal-actions { display: flex; gap: 10px; margin-top: 6px; }
.modal-actions button { flex: 1; padding: 12px; border: none; border-radius: 8px; font-weight: bold; cursor: pointer; font-size: 0.85rem; }
.btn-save { background: var(--tmdb); color: white; }
.btn-reset { background: #2a2a2a; color: #aaa; border: 1px solid #444 !important; }
.key-hint { font-size: 0.72rem; color: #555; margin-top: -14px; margin-bottom: 18px; }
.key-hint a { color: var(--fanart); text-decoration: none; }
/* ── STATUS BAR ── */
.api-status { display: flex; justify-content: center; gap: 20px; margin-bottom: 20px; font-size: 12px; font-weight: bold; }
.status-item { padding: 5px 15px; border-radius: 20px; background: #1a1a1a; border: 1px solid #333; display: flex; align-items: center; gap: 8px; cursor: pointer; transition: border-color .2s; }
.status-item:hover { border-color: #555; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #555; }
.dot.online { background: var(--success); box-shadow: 0 0 5px var(--success); }
.dot.offline { background: var(--error); }
.dot.loading { background: var(--fanart); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }
/* ── SEARCH ── */
.search-area {
background: #1a1a1a; padding: 15px; border-radius: 50px;
display: flex; gap: 10px; margin: 0 auto 40px auto;
max-width: 700px; border: 1px solid #333;
}
input[type="text"]#movieSearch { flex-grow: 1; padding: 12px 25px; border-radius: 30px; border: none; background: #2a2a2a; color: white; outline: none; width: auto; }
button.btn-search { background: var(--tmdb); color: white; border: none; padding: 12px 30px; border-radius: 30px; cursor: pointer; font-weight: bold; }
/* ── GALLERY ── */
#gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 25px; }
.card { background: #1a1a1a; border-radius: 12px; overflow: hidden; border: 1px solid #333; position: relative; }
.card img { width: 100%; height: auto; display: block; background: #111; cursor: pointer; transition: opacity 0.3s; }
.card img:hover { opacity: 0.8; }
/* Badges */
.badge { position: absolute; padding: 4px 8px; border-radius: 4px; font-size: 10px; font-weight: bold; z-index: 5; }
.dim-source { top: 10px; right: 10px; background: rgba(0,0,0,0.85); color: var(--tmdb); border: 1px solid var(--tmdb); }
.source-label { top: 10px; left: 10px; background: rgba(0,0,0,0.85); color: white; border: 1px solid #555; }
.source-fanart { color: var(--fanart); border-color: var(--fanart); }
.card-body { padding: 15px; text-align: center; }
.movie-title { font-size: 0.85rem; height: 2.5em; overflow: hidden; margin-bottom: 10px; color: #ccc; }
.btn-dl { display: block; width: 100%; background: var(--success); color: white; padding: 10px 0; border-radius: 6px; font-size: 0.75rem; font-weight: bold; cursor: pointer; border: none; }
</style>
</head>
<body>
<!-- ── MODAL CLÉS API ── -->
<div class="modal-overlay" id="modalOverlay">
<div class="modal">
<h2>🔑 Configuration des clés API</h2>
<p>Saisies une seule fois, elles sont sauvegardées localement dans votre navigateur.</p>
<label>Clé TMDb *</label>
<input type="text" id="inputTmdb" placeholder="ex: 9c68a19b1c3..." />
<p class="key-hint">→ <a href="https://www.themoviedb.org/settings/api" target="_blank">Obtenir une clé TMDb</a></p>
<label>Clé Fanart.tv (optionnelle)</label>
<input type="text" id="inputFanart" placeholder="ex: abcdef1234..." />
<p class="key-hint">→ <a href="https://fanart.tv/get-an-api-key/" target="_blank">Obtenir une clé Fanart.tv</a></p>
<div class="modal-actions">
<button class="btn-save" onclick="saveKeys()">Enregistrer & lancer</button>
<button class="btn-reset" onclick="resetKeys()">Réinitialiser</button>
</div>
</div>
</div>
<div class="wrapper">
<div class="api-status">
<div class="status-item" onclick="openModal()" title="Cliquer pour modifier les clés">
TMDb <span id="tmdb-dot" class="dot"></span>
</div>
<div class="status-item" onclick="openModal()" title="Cliquer pour modifier les clés">
Fanart.tv <span id="fanart-dot" class="dot"></span>
</div>
</div>
<div class="search-area">
<input type="text" id="movieSearch" placeholder="Titre du film..." autofocus>
<button class="btn-search" onclick="fetchAllArt()">RECHERCHER</button>
</div>
<div id="gallery"></div>
</div>
<script>
let TMDB_KEY = '';
let FANART_KEY = '';
// ── GESTION DES CLÉS ──────────────────────────────────────────────────────
function loadKeys() {
TMDB_KEY = localStorage.getItem('tmdb_key') || '';
FANART_KEY = localStorage.getItem('fanart_key') || '';
}
function openModal() {
loadKeys();
document.getElementById('inputTmdb').value = TMDB_KEY;
document.getElementById('inputFanart').value = FANART_KEY;
document.getElementById('modalOverlay').classList.remove('hidden');
}
function saveKeys() {
const t = document.getElementById('inputTmdb').value.trim();
const f = document.getElementById('inputFanart').value.trim();
if (!t) { alert('La clé TMDb est obligatoire.'); return; }
localStorage.setItem('tmdb_key', t);
localStorage.setItem('fanart_key', f);
TMDB_KEY = t;
FANART_KEY = f;
document.getElementById('modalOverlay').classList.add('hidden');
checkApis();
}
function resetKeys() {
localStorage.removeItem('tmdb_key');
localStorage.removeItem('fanart_key');
document.getElementById('inputTmdb').value = '';
document.getElementById('inputFanart').value = '';
}
// ── CORS PROXY — chaîne de secours ────────────────────────────────────────
// Fanart.tv ne renvoie pas les en-têtes CORS requis par les navigateurs.
// On tente plusieurs proxies publics dans l'ordre jusqu'à en trouver un actif.
const CORS_PROXIES = [
url => `https://api.allorigins.win/raw?url=${encodeURIComponent(url)}`,
url => `https://corsproxy.io/?url=${encodeURIComponent(url)}`,
url => `https://cors-anywhere.herokuapp.com/${url}`,
];
const FANART_BASE = 'https://webservice.fanart.tv/v3.2';
async function fanartFetch(path) {
const target = `${FANART_BASE}/${path}?api_key=${FANART_KEY}`;
let lastErr = null;
for (const proxyFn of CORS_PROXIES) {
try {
const r = await fetch(proxyFn(target));
if (r.ok) {
const data = await r.json();
// Fanart.tv renvoie {"status":"error","error message":"..."} pour clé invalide
if (data.status === 'error') throw new Error(data['error message'] || 'Clé invalide');
return data;
}
lastErr = `HTTP ${r.status}`;
} catch(e) { lastErr = e.message; }
}
throw new Error(lastErr || 'Tous les proxies ont échoué');
}
// ── DIAGNOSTIC API ────────────────────────────────────────────────────────
async function checkApis() {
setDot('tmdb-dot', 'loading');
setDot('fanart-dot', 'loading');
// TMDb
try {
const r = await fetch(`https://api.themoviedb.org/3/authentication?api_key=${TMDB_KEY}`);
setDot('tmdb-dot', r.ok ? 'online' : 'offline', r.ok ? null : `HTTP ${r.status}`);
} catch(e) {
setDot('tmdb-dot', 'offline', 'Erreur réseau : ' + e.message);
}
// Fanart.tv — test sur The Matrix (TMDb ID: 603), film bien référencé
if (FANART_KEY) {
try {
await fanartFetch('movies/603');
setDot('fanart-dot', 'online');
} catch(e) {
setDot('fanart-dot', 'offline', e.message);
}
} else {
setDot('fanart-dot', 'offline', 'Aucune clé renseignée');
}
}
function setDot(id, state, reason) {
const el = document.getElementById(id);
el.className = 'dot ' + state;
const item = el.closest('.status-item');
item.title = reason ? `⚠ ${reason}` : (state === 'online' ? 'Connecté' : '');
}
// ── INITIALISATION ────────────────────────────────────────────────────────
window.onload = () => {
loadKeys();
if (!TMDB_KEY) {
openModal();
} else {
document.getElementById('modalOverlay').classList.add('hidden');
checkApis();
}
};
// ── TÉLÉCHARGEMENT ────────────────────────────────────────────────────────
async function processAndDownload(url, filename) {
const img = new Image();
img.crossOrigin = 'Anonymous';
img.src = url;
img.onload = function() {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
const targetW = 600;
const targetH = Math.round(img.height * (targetW / img.width));
canvas.width = targetW;
canvas.height = targetH;
ctx.imageSmoothingEnabled = true;
ctx.imageSmoothingQuality = 'high';
ctx.drawImage(img, 0, 0, targetW, targetH);
canvas.toBlob((blob) => {
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = `${filename.replace(/[^a-z0-9]/gi,'_')}_600x${targetH}.jpg`;
a.click();
}, 'image/jpeg', 0.92);
};
img.onerror = () => alert('Impossible de charger l\'image (CORS ou URL invalide).');
}
// ── RECHERCHE & GALERIE ───────────────────────────────────────────────────
async function fetchAllArt() {
if (!TMDB_KEY) { openModal(); return; }
const query = document.getElementById('movieSearch').value.trim();
const gallery = document.getElementById('gallery');
if (!query) return;
gallery.innerHTML = '<p style="text-align:center;grid-column:1/-1;color:#888;">Synchronisation des flux en cours…</p>';
try {
const searchRes = await fetch(`https://api.themoviedb.org/3/search/movie?api_key=${TMDB_KEY}&query=${encodeURIComponent(query)}&language=fr-FR`);
const searchData = await searchRes.json();
if (!searchRes.ok) {
gallery.innerHTML = `<p style="color:var(--error);text-align:center;grid-column:1/-1;">Erreur TMDb : ${searchData.status_message || searchRes.status}</p>`;
return;
}
gallery.innerHTML = '';
const results = searchData.results.filter(m => m.poster_path).slice(0, 12);
if (!results.length) {
gallery.innerHTML = '<p style="text-align:center;grid-column:1/-1;color:#888;">Aucun résultat trouvé.</p>';
return;
}
for (const movie of results) {
// Dimensions originales via l'endpoint /images
const imagesRes = await fetch(`https://api.themoviedb.org/3/movie/${movie.id}/images?api_key=${TMDB_KEY}`);
const imagesData = await imagesRes.json();
const bestPoster = (imagesData.posters && imagesData.posters[0]) || { width: 2000, height: 3000 };
// Fanart.tv via chaîne de proxies CORS
let fanartPosterUrl = null;
if (FANART_KEY) {
try {
const faData = await fanartFetch(`movies/${movie.id}`);
if (faData.movieposter && faData.movieposter.length > 0) {
fanartPosterUrl = faData.movieposter[0].url;
}
} catch(e) { /* Fanart indispo, fallback TMDb silencieux */ }
}
const finalUrl = fanartPosterUrl || `https://image.tmdb.org/t/p/original${movie.poster_path}`;
const previewUrl = `https://image.tmdb.org/t/p/w500${movie.poster_path}`;
const sourceName = fanartPosterUrl ? 'FANART.TV' : 'TMDB';
const targetH = Math.round(bestPoster.height * (600 / bestPoster.width));
const safeTitle = movie.title.replace(/'/g, "\\'");
const card = document.createElement('div');
card.className = 'card';
card.innerHTML = `
<div class="badge source-label ${fanartPosterUrl ? 'source-fanart' : ''}">${sourceName}</div>
<div class="badge dim-source">Orig: ${bestPoster.width}×${bestPoster.height}</div>
<img src="${previewUrl}" loading="lazy"
onclick="processAndDownload('${finalUrl}', '${safeTitle}')">
<div class="card-body">
<div class="movie-title">${movie.title}</div>
<button class="btn-dl" onclick="processAndDownload('${finalUrl}', '${safeTitle}')">
TÉLÉCHARGER (600 × ${targetH})
</button>
</div>
`;
gallery.appendChild(card);
}
} catch (err) {
console.error(err);
gallery.innerHTML = '<p style="color:var(--error);text-align:center;grid-column:1/-1;">Erreur réseau. Vérifiez vos clés API.</p>';
}
}
document.getElementById('movieSearch').addEventListener('keypress', (e) => {
if (e.key === 'Enter') fetchAllArt();
});
</script>
</body>
</html>