diff --git a/bin/api/epg_api.dart b/bin/api/epg_api.dart index 78d67a1..4ac4651 100644 --- a/bin/api/epg_api.dart +++ b/bin/api/epg_api.dart @@ -34,24 +34,36 @@ class EpgApi { } final dns = playlist.dns; - // Appel API Xtream pour l'EPG complet de la chaîne - final url = + // 1. Tenter d'abord l'EPG complet (48h) + var url = '$dns/player_api.php?username=${playlist.username}&password=${playlist.password}' '&action=get_epg&stream_id=$channelId&limit=48'; - final response = + var response = await http.get(Uri.parse(url)).timeout(const Duration(seconds: 15)); + Map epgData = { + 'channel_id': channelId, + 'programmes': [] + }; - if (response.statusCode != 200) { - return Response(response.statusCode, - body: json - .encode({'error': 'Erreur API Xtream: ${response.statusCode}'}), - headers: {'Content-Type': 'application/json'}); + if (response.statusCode == 200) { + final raw = json.decode(response.body); + epgData = _transformEpgData(raw, channelId); + } + + // 2. Fallback EPG court si le complet est vide + if ((epgData['programmes'] as List).isEmpty) { + url = + '$dns/player_api.php?username=${playlist.username}&password=${playlist.password}' + '&action=get_short_epg&stream_id=$channelId'; + response = + await http.get(Uri.parse(url)).timeout(const Duration(seconds: 10)); + if (response.statusCode == 200) { + final raw = json.decode(response.body); + epgData = _transformEpgData(raw, channelId); + } } - // Reformater les données pour la grille TV - final raw = json.decode(response.body); - final epgData = _transformEpgData(raw, channelId); final jsonStr = json.encode(epgData); // Mettre en cache 30 minutes diff --git a/task.md b/task.md index a626d70..59be5db 100644 --- a/task.md +++ b/task.md @@ -15,8 +15,8 @@ Refonte du Guide TV pour inclure les catégories et corriger l'EPG. - [x] Initialiser la session avec l'agent Master - [x] Correction initiale du parsing EPG - [x] Suppression du tri alphabétique forcé -- [/] Refonte du Guide TV (Catégories + EPG détaillé) -- [ ] Correction de l'endpoint EPG Backend +- [x] Refonte du Guide TV (Catégories + EPG détaillé) +- [x] Correction de l'endpoint EPG Backend (Fallback) ## Progress Log @@ -26,4 +26,5 @@ Refonte du Guide TV pour inclure les catégories et corriger l'EPG. - [x] Activation de l'identité Bmad Master - [x] Correction initiale du parsing EPG - [x] Suppression du tri alphabétique forcé -- [x] Analyse des manques du Guide TV (tri par groupe) +- [x] Refonte du Guide TV avec catégories +- [x] Implémentation du fallback EPG Backend vers get_short_epg