mirror of
https://github.com/nirvana-7777/script.service.ultimate.git
synced 2026-10-12 19:02:33 +02:00
Add web config
This commit is contained in:
@@ -624,7 +624,29 @@ class EPGMappingManager {
|
||||
|
||||
async showEPGPreview(epgId) {
|
||||
try {
|
||||
const response = await fetch(`${this.apiBase}/api/epg/preview/${encodeURIComponent(epgId)}`);
|
||||
// We need to find which channel in the current provider uses this EPG ID
|
||||
const channel = this.channelData.find(c => c.currentEpgId === epgId);
|
||||
|
||||
if (!channel) {
|
||||
// If no channel is mapped to this EPG ID yet, we can't get EPG data
|
||||
const modal = document.getElementById('epg-preview-modal');
|
||||
const body = document.getElementById('epg-preview-body');
|
||||
|
||||
body.innerHTML = `
|
||||
<h4>EPG Data for: ${this.escapeHtml(epgId)}</h4>
|
||||
<p>No channel is currently mapped to this EPG ID.</p>
|
||||
<p>Map a channel first to see EPG data.</p>
|
||||
`;
|
||||
|
||||
modal.style.display = 'flex';
|
||||
return;
|
||||
}
|
||||
|
||||
// Use the same endpoint as Kodi addon
|
||||
const response = await fetch(
|
||||
`${this.apiBase}/api/providers/${this.currentProvider}/channels/${channel.id}/epg`
|
||||
);
|
||||
|
||||
if (!response.ok) throw new Error('No EPG data available');
|
||||
|
||||
const epgData = await response.json();
|
||||
@@ -632,10 +654,10 @@ class EPGMappingManager {
|
||||
const body = document.getElementById('epg-preview-body');
|
||||
|
||||
body.innerHTML = `
|
||||
<h4>EPG Data for: ${this.escapeHtml(epgId)}</h4>
|
||||
${epgData.programs && epgData.programs.length > 0 ? `
|
||||
<h4>EPG Data for: ${this.escapeHtml(channel.name)} → ${this.escapeHtml(epgId)}</h4>
|
||||
${epgData.epg && epgData.epg.length > 0 ? `
|
||||
<div class="epg-programs">
|
||||
${epgData.programs.slice(0, 5).map(program => `
|
||||
${epgData.epg.slice(0, 5).map(program => `
|
||||
<div class="epg-program">
|
||||
<div class="epg-program-time">
|
||||
${new Date(program.start * 1000).toLocaleString()} -
|
||||
|
||||
+2
-72
@@ -2344,9 +2344,10 @@ class UltimateService:
|
||||
# }
|
||||
|
||||
# Extract mapping (skip internal fields starting with _)
|
||||
internal_fields = ['_provider_name', '_created_at', '_updated_at', '_version']
|
||||
actual_mapping = {
|
||||
k: v for k, v in mapping_data.items()
|
||||
if not k.startswith('_')
|
||||
if k not in internal_fields
|
||||
}
|
||||
|
||||
logger.info(f"Loaded EPG mapping for {provider}: {len(actual_mapping)} channels")
|
||||
@@ -2454,77 +2455,6 @@ class UltimateService:
|
||||
response.status = 500
|
||||
return {"error": f"Failed to save mapping: {str(e)}"}
|
||||
|
||||
@self.app.route("/api/epg/preview/<epg_id>", method='GET')
|
||||
def get_epg_preview(epg_id):
|
||||
"""Get EPG preview data for a channel"""
|
||||
# Import at the top of the function to avoid scope issues
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
try:
|
||||
from streaming_providers.base.epg.epg_manager import EPGManager
|
||||
except ImportError:
|
||||
# If EPG module is not available, return empty data
|
||||
return {
|
||||
"epg_id": epg_id,
|
||||
"programs": []
|
||||
}
|
||||
|
||||
try:
|
||||
epg_manager = EPGManager()
|
||||
|
||||
# Try to get actual EPG data for the channel
|
||||
try:
|
||||
# Get EPG data for the next 12 hours
|
||||
now = datetime.now()
|
||||
end_time = now + timedelta(hours=12)
|
||||
|
||||
# This should call the actual EPG parsing method
|
||||
epg_data = epg_manager.get_channel_epg(
|
||||
epg_id=epg_id,
|
||||
start_time=now,
|
||||
end_time=end_time
|
||||
)
|
||||
|
||||
if epg_data:
|
||||
# Convert to the format expected by the frontend
|
||||
programs = []
|
||||
for program in epg_data[:5]: # Limit to 5 programs
|
||||
programs.append({
|
||||
"title": program.get('title', 'No title'),
|
||||
"start": int(program.get('start', now.timestamp())),
|
||||
"end": int(program.get('end', (now + timedelta(hours=1)).timestamp())),
|
||||
"description": program.get('description', 'No description available.'),
|
||||
"episode_name": program.get('episode_name')
|
||||
})
|
||||
|
||||
return {
|
||||
"epg_id": epg_id,
|
||||
"programs": programs
|
||||
}
|
||||
except Exception as epg_error:
|
||||
logger.warning(f"Could not get real EPG data for {epg_id}: {epg_error}")
|
||||
|
||||
# Fallback: return sample data
|
||||
now = datetime.now()
|
||||
end_time = now + timedelta(hours=1)
|
||||
|
||||
return {
|
||||
"epg_id": epg_id,
|
||||
"programs": [
|
||||
{
|
||||
"title": "Sample Program",
|
||||
"start": int(now.timestamp()),
|
||||
"end": int(end_time.timestamp()),
|
||||
"description": "EPG preview not available. This is sample data."
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting EPG preview for {epg_id}: {e}", exc_info=True)
|
||||
response.status = 500
|
||||
return {"error": f"Failed to get EPG data: {str(e)}"}
|
||||
|
||||
@self.app.route('/')
|
||||
def serve_root():
|
||||
"""Redirect root to config page"""
|
||||
|
||||
Reference in New Issue
Block a user