Add advice and finish size filter

This commit is contained in:
2025-11-15 18:48:11 +01:00
parent 08be6a2455
commit a4fdd6e965
5 changed files with 56 additions and 29 deletions

View File

@@ -8,7 +8,6 @@ ALLDEBRID_API_KEY = os.getenv("ALLDEBRID_API_KEY")
NTFY_TOPIC_URL = os.getenv("NTFY_TOPIC_URL") NTFY_TOPIC_URL = os.getenv("NTFY_TOPIC_URL")
NTFY_TOKEN = os.getenv("NTFY_TOKEN") NTFY_TOKEN = os.getenv("NTFY_TOKEN")
MAX_SIZE_BYTES = 5*1024**3
NB_PAGES = 2 NB_PAGES = 2
def check_alldebrid_status(): def check_alldebrid_status():
@@ -71,11 +70,11 @@ def search_torrents(query: str, category_id: str | None = None) -> list[dict]:
return results return results
def filter_and_format_torrents(torrents: list[dict]) -> list[dict]: def filter_and_format_torrents(torrents: list[dict], max_size: int, season: int | None = None, episode: int | None = None) -> list[dict]:
"""Filtre les torrents trop gros et formate la taille et l'âge.""" """Filtre les torrents trop gros et formate la taille et l'âge."""
filtered = [] filtered = []
for t in torrents: for t in torrents:
if t['size'] <= MAX_SIZE_BYTES: if t['size'] <= max_size*1024**3:
t['size'] = format_size(t['size']) t['size'] = format_size(t['size'])
days, human = calculate_age(t['uploaded_at']) days, human = calculate_age(t['uploaded_at'])
t['age_days'] = days t['age_days'] = days

View File

@@ -55,12 +55,16 @@ def init_app(app):
def search(): def search():
query = request.args.get('query') query = request.args.get('query')
category_id = request.args.get('category_id') category_id = request.args.get('category_id')
max_size = request.args.get('max_size', default=5, type=int)
season = request.args.get('season', type=int) # None si absent
episode = request.args.get('episode', type=int) # None si absent
# 1. Recherche brute # 1. Recherche brute
torrents = search_torrents(query, category_id) torrents = search_torrents(query, category_id)
# 2. Filtrage et formatage # 2. Filtrage et formatage
filtered_results = filter_and_format_torrents(torrents) filtered_results = filter_and_format_torrents(torrents, max_size, season, episode)
return render_template( return render_template(
'search_results.html', 'search_results.html',

View File

@@ -11,7 +11,6 @@ body {
header { header {
color: #00ff41; color: #00ff41;
text-shadow: 0 0 10px #00ff41; text-shadow: 0 0 10px #00ff41;
margin-bottom: 20px;
text-align: center; text-align: center;
} }
@@ -29,7 +28,7 @@ td {
.user-info { .user-info {
display:inline; display:inline;
margin-right:10px; margin: 5px;
color:white; color:white;
font-weight:bold; font-weight:bold;
} }
@@ -40,7 +39,7 @@ td {
.second-header { .second-header {
font-weight: bold; font-weight: bold;
margin-bottom: 20px; margin: 10px;
} }
#results-table td:nth-child(2), #results-table td:nth-child(2),

View File

@@ -30,21 +30,20 @@
<form action="{{ url_for('logout') }}" method="GET" style="display:inline;"> <form action="{{ url_for('logout') }}" method="GET" style="display:inline;">
<button type="submit">Déconnexion</button> <button type="submit">Déconnexion</button>
</form> </form>
{% if session.alldebrid_active is defined %}
{% if session.alldebrid_active %}
<div class="second-header">
✅ Service fonctionnel
</div>
{% else %}
<div class="second-header">
⚠️ Service en panne, je répare !
</div>
{% endif %}
{% endif %}
{% endif %} {% endif %}
</header> </header>
{% if session.alldebrid_active is defined %}
{% if session.alldebrid_active %}
<div class="second-header">
✅ Service fonctionnel
</div>
{% else %}
<div class="second-header">
⚠️ Service en panne, je répare !
</div>
{% endif %}
{% endif %}
<main> <main>
{% block content %}{% endblock %} {% block content %}{% endblock %}
</main> </main>

View File

@@ -1,6 +1,6 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% block title %}Tableau de bord{% endblock %} {% block title %}Les films de Lulu{% endblock %}
{% block matrix %} {% block matrix %}
<canvas id="matrix"></canvas> <canvas id="matrix"></canvas>
@@ -12,21 +12,31 @@
<!-- Colonne principale des filtres --> <!-- Colonne principale des filtres -->
<div style="display: flex; flex-direction: column; gap: 10px;"> <div style="display: flex; flex-direction: column; gap: 10px;">
<div style="display: flex; flex-direction: column;">
<p class="user-info" style="text-align: center;">
Conseils de recherche 😊
</p>
<p class="user-info">
- Préciser une catégorie<br>
- Essayer les titres en anglais<br>
- Ajuster la taille maximale
</p>
</div>
<!-- Ligne 1 : Catégorie et Recherche --> <!-- Ligne 1 : Catégorie et Recherche -->
<div style="display: flex; gap: 10px; align-items: flex-start"> <div style="display: flex; gap: 10px; align-items: flex-start">
<div style="display: flex; flex-direction: column;"> <div style="display: flex; flex-direction: column;">
<label class="bold-label">Catégorie</label> <label class="bold-label">Catégorie</label>
<select name="category_id"> <select name="category_id" id="category_id">
<option value="">Tout</option> <option value="">Tout</option>
<optgroup label="🎬 Film / Vidéo"> <optgroup label="🎬 Film / Vidéo">
<option value="2183" selected>Film/Vidéo : Film</option>
<option value="2184">Film/Vidéo : Série TV</option>
<option value="2178">Film/Vidéo : Animation</option> <option value="2178">Film/Vidéo : Animation</option>
<option value="2179">Film/Vidéo : Animation Série</option> <option value="2179">Film/Vidéo : Animation Série</option>
<option value="2180">Film/Vidéo : Concert</option>
<option value="2181">Film/Vidéo : Documentaire</option> <option value="2181">Film/Vidéo : Documentaire</option>
<option value="2182">Film/Vidéo : Émission TV</option> <option value="2182">Film/Vidéo : Émission TV</option>
<option value="2183">Film/Vidéo : Film</option> <option value="2180">Film/Vidéo : Concert</option>
<option value="2184">Film/Vidéo : Série TV</option>
<option value="2185">Film/Vidéo : Spectacle</option> <option value="2185">Film/Vidéo : Spectacle</option>
<option value="2186">Film/Vidéo : Sport</option> <option value="2186">Film/Vidéo : Sport</option>
<option value="2187">Film/Vidéo : Vidéo-clips</option> <option value="2187">Film/Vidéo : Vidéo-clips</option>
@@ -91,12 +101,12 @@
<div style="display: flex; flex-direction: column;"> <div style="display: flex; flex-direction: column;">
<label class="bold-label">Taille max (Go)</label> <label class="bold-label">Taille max (Go)</label>
<input type="number" name="max_size" min="1" step="1" value="15"> <input type="number" name="max_size" min="1" step="1" value="5">
</div> </div>
</div> </div>
<!-- Ligne 3 : Série --> <!-- Ligne 3 : Série -->
<div style="display: flex; flex-direction: column; gap: 5px;"> <div id="serie-section" style="display: none; flex-direction: column; gap: 5px;">
<label class="bold-label">Série</label> <label class="bold-label">Série</label>
<div style="display: flex; gap: 10px;"> <div style="display: flex; gap: 10px;">
<label><input type="radio" name="serie_type" value="all" checked> Tout</label> <label><input type="radio" name="serie_type" value="all" checked> Tout</label>
@@ -104,7 +114,6 @@
<label><input type="radio" name="serie_type" value="episode"> Épisode précis</label> <label><input type="radio" name="serie_type" value="episode"> Épisode précis</label>
</div> </div>
<!-- Champs conditionnels -->
<div id="season-field" style="display: none; margin-top: 5px;"> <div id="season-field" style="display: none; margin-top: 5px;">
<label>Saison</label> <label>Saison</label>
<input type="number" name="season" min="1" step="1" placeholder="1"> <input type="number" name="season" min="1" step="1" placeholder="1">
@@ -112,10 +121,10 @@
<div id="episode-field" style="display: none; margin-top: 5px;"> <div id="episode-field" style="display: none; margin-top: 5px;">
<label>Épisode</label> <label>Épisode</label>
<input type="number" name="episode_number" min="1" step="1" placeholder="1"> <input type="number" name="episode" min="1" step="1" placeholder="1">
</div> </div>
</div> </div>
<!-- Bouton Recherche sur le côté -->
<div style="display: flex; justify-content: center;"> <div style="display: flex; justify-content: center;">
<button type="submit" style="padding: 5px 30px;">Rechercher</button> <button type="submit" style="padding: 5px 30px;">Rechercher</button>
</div> </div>
@@ -131,7 +140,10 @@
const radioButtons = document.querySelectorAll('input[name="serie_type"]'); const radioButtons = document.querySelectorAll('input[name="serie_type"]');
const seasonField = document.getElementById('season-field'); const seasonField = document.getElementById('season-field');
const episodeField = document.getElementById('episode-field'); const episodeField = document.getElementById('episode-field');
const serieSection = document.getElementById('serie-section');
const categorySelect = document.getElementById('category_id');
// Gestion des radio boutons (saison/épisode)
radioButtons.forEach(radio => { radioButtons.forEach(radio => {
radio.addEventListener('change', () => { radio.addEventListener('change', () => {
if (radio.value === 'all') { if (radio.value === 'all') {
@@ -146,5 +158,19 @@ radioButtons.forEach(radio => {
} }
}); });
}); });
// Affiche la section Série uniquement si la catégorie correspond à une série
function updateSerieVisibility() {
const selected = categorySelect.value;
if (selected === "2184" || selected === "2179" || selected === "2182") {
serieSection.style.display = "flex";
} else {
serieSection.style.display = "none";
}
}
// Exécute au chargement et lors dun changement de catégorie
categorySelect.addEventListener('change', updateSerieVisibility);
updateSerieVisibility();
</script> </script>
{% endblock %} {% endblock %}