valoracion-mirrors
This commit is contained in:
33
app.py
33
app.py
@@ -94,12 +94,12 @@ def resolve_logo(tvg_id: str, base_name: str, tvg_logo: str) -> tuple:
|
||||
"""
|
||||
def lookup(slug: str):
|
||||
if slug in logo_index:
|
||||
return f'/logos/{logo_index[slug]}', 'local'
|
||||
return f'logos/{logo_index[slug]}', 'local'
|
||||
# Prefix match: allows "dazn-laliga" → "dazn-laliga-es" when no-suffix
|
||||
# alias wasn't created (e.g. the suffix was longer than 3 chars)
|
||||
for key, path in logo_index.items():
|
||||
if key.startswith(slug) and len(key) <= len(slug) + 4:
|
||||
return f'/logos/{path}', 'local'
|
||||
return f'logos/{path}', 'local'
|
||||
return None, None
|
||||
|
||||
if tvg_id:
|
||||
@@ -256,6 +256,7 @@ def group_channels(raw_entries: list, group_meta: dict) -> list:
|
||||
mirror = {
|
||||
'resolution': parsed['resolution'],
|
||||
'acestream_hash': entry['acestream_hash'],
|
||||
'status': 'unknown',
|
||||
}
|
||||
|
||||
if key not in channel_map:
|
||||
@@ -329,6 +330,7 @@ def load_from_json_content(data: dict, source_file: str) -> None:
|
||||
m.pop('acestream_url', None)
|
||||
m.pop('raw_name', None)
|
||||
m.pop('quality_marker', None)
|
||||
m.setdefault('status', 'unknown')
|
||||
group_meta = {g['name']: g.get('logo', '') for g in data.get('groups', [])}
|
||||
groups = sorted({ch['group'] for ch in channels})
|
||||
state = {
|
||||
@@ -463,6 +465,33 @@ def api_export_m3u():
|
||||
)
|
||||
|
||||
|
||||
@app.route('/api/mirror/status', methods=['POST'])
|
||||
def api_mirror_status():
|
||||
data = request.get_json()
|
||||
channel_id = data.get('channel_id')
|
||||
mirror_idx = data.get('mirror_idx')
|
||||
status = data.get('status', 'unknown')
|
||||
if status not in ('ok', 'issues', 'broken', 'unknown'):
|
||||
return jsonify({'error': 'invalid status'}), 400
|
||||
ch = next((c for c in state['channels'] if c['id'] == channel_id), None)
|
||||
if not ch or not isinstance(mirror_idx, int) or mirror_idx >= len(ch['mirrors']):
|
||||
return jsonify({'error': 'not found'}), 404
|
||||
ch['mirrors'][mirror_idx]['status'] = status
|
||||
export = {
|
||||
'version': '1.0',
|
||||
'exported_at': datetime.now(timezone.utc).isoformat(),
|
||||
'source': state['source_file'],
|
||||
'channels': state['channels'],
|
||||
'groups': [
|
||||
{'name': g, 'logo': state['group_meta'].get(g, ''), 'subcategories': []}
|
||||
for g in state['groups']
|
||||
],
|
||||
}
|
||||
with open(DEFAULT_JSON, 'w', encoding='utf-8') as f:
|
||||
json.dump(export, f, ensure_ascii=False, indent=2)
|
||||
return jsonify({'ok': True})
|
||||
|
||||
|
||||
# ── Startup ───────────────────────────────────────────────────────────────────
|
||||
|
||||
def startup() -> None:
|
||||
|
||||
Reference in New Issue
Block a user