Repository navigation
Expand file tree
/
Copy pathmeta-handler.js
More file actions
144 lines (112 loc) · 4.47 KB
/
Copy pathmeta-handler.js
File metadata and controls
144 lines (112 loc) · 4.47 KB
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
const config = require('./config');
const CacheManager = require('./cache-manager')(config);
const EPGManager = require('./epg-manager');
function normalizeId(id) {
return id?.toLowerCase().replace(/[^\w.]/g, '').trim() || '';
}
function enrichWithDetailedEPG(meta, channelId, userConfig) {
if (!userConfig.epg_enabled) {
console.log('❌ EPG non abilitato');
return meta;
}
const normalizedId = normalizeId(channelId);
const currentProgram = EPGManager.getCurrentProgram(normalizedId);
const upcomingPrograms = EPGManager.getUpcomingPrograms(normalizedId);
if (currentProgram) {
let description = [];
description.push('📺 IN ONDA ORA:', currentProgram.title);
if (currentProgram.description) {
description.push('', currentProgram.description);
}
description.push('', `⏰ ${currentProgram.start} - ${currentProgram.stop}`);
if (currentProgram.category) {
description.push(`🏷️ ${currentProgram.category}`);
}
if (upcomingPrograms?.length > 0) {
description.push('', '📅 PROSSIMI PROGRAMMI:');
upcomingPrograms.forEach(program => {
description.push(
'',
`• ${program.start} - ${program.title}`
);
if (program.description) {
description.push(` ${program.description}`);
}
if (program.category) {
description.push(` 🏷️ ${program.category}`);
}
});
}
meta.description = description.join('\n');
meta.releaseInfo = `${currentProgram.title} (${currentProgram.start})`;
} else {
}
return meta;
}
async function metaHandler({ type, id, config: userConfig }) {
try {
if (!userConfig.m3u) {
console.log('❌ URL M3U mancante');
return { meta: null };
}
if (CacheManager.cache.m3uUrl !== userConfig.m3u) {
console.log('Cache M3U non aggiornata, ricostruzione...');
await CacheManager.rebuildCache(userConfig.m3u, userConfig);
}
const channelId = id.split('|')[1];
// Usa direttamente getChannel dalla cache, che ora gestisce correttamente i suffissi
const channel = CacheManager.getChannel(channelId);
if (!channel) {
console.log('=== Fine Meta Handler ===\n');
return { meta: null };
}
const meta = {
id: channel.id,
type: 'tv',
name: channel.streamInfo?.tvg?.chno
? `${channel.streamInfo.tvg.chno}. ${channel.name}`
: channel.name,
poster: channel.poster || channel.logo,
background: channel.background || channel.logo,
logo: channel.logo,
description: '',
releaseInfo: 'LIVE',
genre: channel.genre,
posterShape: 'square',
language: 'ita',
country: 'ITA',
isFree: true,
behaviorHints: {
isLive: true,
defaultVideoId: channel.id
}
};
if ((!meta.poster || !meta.background || !meta.logo) && channel.streamInfo?.tvg?.id) {
const epgIcon = EPGManager.getChannelIcon(normalizeId(channel.streamInfo.tvg.id));
if (epgIcon) {
meta.poster = meta.poster || epgIcon;
meta.background = meta.background || epgIcon;
meta.logo = meta.logo || epgIcon;
} else {
}
}
let baseDescription = [];
if (channel.streamInfo?.tvg?.chno) {
baseDescription.push(`📺 Canale ${channel.streamInfo.tvg.chno}`);
}
if (channel.description) {
baseDescription.push('', channel.description);
} else {
baseDescription.push('', `ID Canale: ${channel.streamInfo?.tvg?.id}`);
}
meta.description = baseDescription.join('\n');
const enrichedMeta = enrichWithDetailedEPG(meta, channel.streamInfo?.tvg?.id, userConfig);
console.log('✓ Meta handler completato');
return { meta: enrichedMeta };
} catch (error) {
console.error('[MetaHandler] Errore:', error.message);
console.log('=== Fine Meta Handler con Errore ===\n');
return { meta: null };
}
}
module.exports = metaHandler;