File size: 8,592 Bytes
36dde81 | 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 | {% extends "base.html" %}
{% block title %}Request a Title{% endblock %}
{% block content %}
<style>
.rp-shell { max-width: 1040px; margin: 0 auto; }
.rp-brand { display: flex; align-items: center; gap: .6rem; font-weight: 600; margin-bottom: 2.5rem; }
.rp-hero { padding: .5rem 0 1rem; }
.rp-hero h1 { font-size: clamp(1.75rem, 4.5vw, 2.5rem); font-weight: 600; letter-spacing: -0.025em; line-height: 1.1; }
.rp-hero p { color: var(--text-sec); margin-top: .6rem; font-size: .98rem; max-width: 34rem; }
.rp-search { position: relative; display: flex; max-width: 640px; margin-top: 1.5rem; }
.rp-search input { flex: 1; min-width: 0; background: var(--card); border: 1px solid var(--border); color: var(--text); border-radius: 9999px; padding: .9rem 4rem .9rem 1.25rem; font-size: 1rem; outline: none; transition: border-color .18s var(--ease), box-shadow .18s var(--ease); }
.rp-search input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); }
.rp-search button { position: absolute; right: 5px; top: 5px; bottom: 5px; aspect-ratio: 1; background: var(--primary); color: var(--on-primary); border: 0; border-radius: 9999px; cursor: pointer; transition: transform .12s var(--ease); }
.rp-search button:active { transform: scale(.94); }
.rp-hint { color: var(--text-sec); font-size: .82rem; margin-top: .7rem; }
.rp-hint b { color: var(--text); font-weight: 500; }
.rp-section-title { font-size: .72rem; font-weight: 500; letter-spacing: .1em; text-transform: uppercase; color: var(--text-sec); margin: 2.5rem .25rem .75rem; display: flex; align-items: center; gap: .5rem; }
.rp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1.25rem 1rem; }
.rp-card { min-width: 0; display: flex; flex-direction: column; }
.rp-poster { position: relative; aspect-ratio: 2/3; border-radius: 14px; overflow: hidden; background: var(--card-high); }
.rp-poster img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .4s var(--ease); }
.rp-card:hover .rp-poster img { transform: scale(1.04); }
.rp-poster .noimg { position: absolute; inset: 0; display: grid; place-items: center; font-size: 1.5rem; color: var(--text-sec); }
.rp-type, .rp-count { position: absolute; top: 6px; padding: 2px 8px; border-radius: 9999px; font-size: .72rem; line-height: 1.4; background: rgba(0,0,0,.72); color: #fff; }
.rp-type { left: 6px; }
.rp-count { right: 6px; }
.rp-body { padding: .6rem .1rem 0; display: flex; flex-direction: column; gap: .6rem; flex: 1; }
.rp-title { font-weight: 500; font-size: .92rem; line-height: 1.3; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.rp-btn { margin-top: auto; border: 1px solid var(--border); border-radius: 9999px; padding: .45rem; font-size: .84rem; cursor: pointer; background: transparent; color: var(--text); transition: background-color .15s var(--ease), color .15s var(--ease), border-color .15s var(--ease), transform .12s var(--ease); }
.rp-btn:hover { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.rp-btn:active { transform: scale(.96); }
.rp-btn:disabled { opacity: .5; cursor: default; }
.rp-empty { color: var(--text-sec); padding: 2rem .25rem; }
.rp-spinner { color: var(--text-sec); padding: 2rem .25rem; }
</style>
<div class="rp-shell">
<div class="rp-brand"><span class="brand-mark"><i class="fa-solid fa-play"></i></span>TG Stremio</div>
<div class="rp-hero">
<h1>Request a movie or show</h1>
<p>Can't find something? Search below and send a request — we'll try to add it.</p>
<form class="rp-search" onsubmit="doSearch(event)">
<input id="rp-q" type="search" enterkeyhint="search" placeholder="Search by name, IMDb ID (tt…) or TMDB ID" autocomplete="off">
<button type="submit" aria-label="Search"><i class="fa-solid fa-magnifying-glass"></i></button>
</form>
<p class="rp-hint">Examples: <b>Inception</b> · <b>tt1375666</b> · <b>27205</b></p>
</div>
<div id="rp-results-wrap" style="display:none">
<div class="rp-section-title">Search results</div>
<div id="rp-results" class="rp-grid"></div>
</div>
<div id="rp-popular-wrap">
<div class="rp-section-title">Most requested</div>
<div id="rp-popular" class="rp-grid"></div>
</div>
</div>
<script>
let searchResults = [];
function esc(s) {
return String(s == null ? '' : s).replace(/&/g,'&').replace(/</g,'<')
.replace(/>/g,'>').replace(/"/g,'"').replace(/'/g,''');
}
function posterHtml(r, extra) {
const img = r.poster ? `<img src="${esc(r.poster)}" loading="lazy" alt="">`
: `<div class="noimg"><i class="fa-solid fa-film"></i></div>`;
const type = r.media_type === 'tv' ? 'TV' : 'Movie';
return `<div class="rp-poster">${img}<span class="rp-type">${type}</span>${extra || ''}</div>`;
}
function resultCard(r, idx) {
const yr = r.year ? ` (${esc(r.year)})` : '';
return `<div class="rp-card">
${posterHtml(r)}
<div class="rp-body">
<div class="rp-title">${esc(r.title)}${yr}</div>
<button class="rp-btn" onclick="sendRequest(${idx})"><i class="fa-solid fa-paper-plane"></i> Request</button>
</div>
</div>`;
}
function popularCard(r) {
const yr = r.year ? ` (${esc(r.year)})` : '';
const count = `<span class="rp-count"><i class="fa-solid fa-user-group"></i> ${esc(r.request_count || 0)}</span>`;
return `<div class="rp-card">
${posterHtml(r, count)}
<div class="rp-body"><div class="rp-title">${esc(r.title)}${yr}</div></div>
</div>`;
}
async function doSearch(e) {
if (e) e.preventDefault();
const q = document.getElementById('rp-q').value.trim();
if (q.length < 2) { showToast('Type at least 2 characters.', 'info'); return; }
const wrap = document.getElementById('rp-results-wrap');
const box = document.getElementById('rp-results');
wrap.style.display = '';
box.innerHTML = `<div class="rp-spinner" style="grid-column:1/-1"><i class="fa-solid fa-spinner fa-spin"></i> Searching…</div>`;
try {
const res = await fetch('/api/request/search?q=' + encodeURIComponent(q));
const data = await res.json();
searchResults = data.data || [];
box.innerHTML = searchResults.length
? searchResults.map((r, i) => resultCard(r, i)).join('')
: `<div class="rp-empty" style="grid-column:1/-1">No matches found. Try a different name or an IMDb/TMDB ID.</div>`;
} catch (err) {
box.innerHTML = `<div class="rp-empty" style="grid-column:1/-1;color:var(--danger)">Search failed. Please try again.</div>`;
}
}
async function sendRequest(idx) {
const r = searchResults[idx];
if (!r) return;
try {
const res = await fetch('/api/request/submit', {
method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
media_type: r.media_type, tmdb_id: r.tmdb_id, imdb_id: r.imdb_id || null,
title: r.title, year: r.year, poster: r.poster,
}),
});
const data = await res.json();
const map = {
created: ['Request submitted! We\'ll try to add it soon.', 'success', 'Requested'],
added: ['Added your vote — this was already requested.', 'success', 'Requested'],
reopened: ['Request re-opened. Thanks!', 'success', 'Requested'],
already_available: ['Good news — this is already in the library!', 'info', 'Available'],
banned: ['This title has been banned and can\'t be requested.', 'error', 'Not allowed'],
invalid: ['Could not identify this title.', 'error', 'Error'],
};
const m = map[data.reason] || (data.ok ? ['Request submitted!', 'success', 'Requested']
: ['Something went wrong.', 'error', 'Error']);
showToast(m[0], m[1], m[2]);
if (data.ok) loadPopular();
} catch (err) {
showToast('Request failed. Please try again.', 'error', 'Error');
}
}
async function loadPopular() {
const box = document.getElementById('rp-popular');
const wrap = document.getElementById('rp-popular-wrap');
try {
const res = await fetch('/api/request/popular');
const data = await res.json();
const items = data.data || [];
if (!items.length) { wrap.style.display = 'none'; return; }
wrap.style.display = '';
box.innerHTML = items.map(popularCard).join('');
} catch (err) {
wrap.style.display = 'none';
}
}
document.addEventListener('DOMContentLoaded', loadPopular);
</script>
{% endblock %}
|