-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtv.html
More file actions
486 lines (427 loc) · 22.6 KB
/
tv.html
File metadata and controls
486 lines (427 loc) · 22.6 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ТВ каналы - Online Cinema</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Ubuntu:ital,wght@0,300;0,400;0,500;0,700;1,300;1,400;1,500;1,700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="main.css">
<script src="https://cdn.jsdelivr.net/npm/hls.js@1.4.10/dist/hls.min.js"></script>
</head>
<body>
<!-- Верхняя панель навигации -->
<div class="top-nav">
<div class="nav-buttons">
<a href="index.html" class="nav-btn">
<img src="home.png" alt="Главная" class="nav-icon">
<span>Главная</span>
</a>
<a href="tv.html" class="nav-btn">
<img src="tv.png" alt="ТВ" class="nav-icon">
<span>ТВ</span>
</a>
<a href="search.html" class="nav-btn">
<img src="search.png" alt="Поиск" class="nav-icon">
<span>Поиск</span>
</a>
</div>
</div>
<!-- Основной контент -->
<div class="container">
<h1>ТВ каналы</h1>
<div class="tv-controls">
<div class="playlist-selector">
<label for="playlist-select">Выберите плейлист:</label>
<select id="playlist-select" class="playlist-select">
<option value="">Выберите категорию...</option>
<optgroup label="По категориям">
<option value="https://iptv-org.github.io/iptv/categories/general.m3u">Общие каналы (General)</option>
<option value="https://iptv-org.github.io/iptv/categories/movies.m3u">Фильмы</option>
<option value="https://iptv-org.github.io/iptv/categories/series.m3u">Сериалы</option>
<option value="https://iptv-org.github.io/iptv/categories/sports.m3u">Спорт</option>
<option value="https://iptv-org.github.io/iptv/categories/news.m3u">Новости</option>
<option value="https://iptv-org.github.io/iptv/categories/kids.m3u">Детские</option>
<option value="https://iptv-org.github.io/iptv/categories/music.m3u">Музыка</option>
</optgroup>
<optgroup label="По языкам">
<option value="https://iptv-org.github.io/iptv/languages/rus.m3u">Русский</option>
<option value="https://iptv-org.github.io/iptv/languages/eng.m3u">Английский</option>
<option value="https://iptv-org.github.io/iptv/languages/spa.m3u">Испанский</option>
</optgroup>
<optgroup label="По странам">
<option value="https://iptv-org.github.io/iptv/countries/ru.m3u">Россия</option>
<option value="https://iptv-org.github.io/iptv/countries/us.m3u">США</option>
<option value="https://iptv-org.github.io/iptv/countries/uk.m3u">Великобритания</option>
</optgroup>
</select>
</div>
<div class="search-container">
<input
type="text"
id="channel-search"
class="search-input"
placeholder="Поиск канала..."
autocomplete="off"
>
</div>
</div>
<div class="tv-content">
<div class="channels-section">
<h2>Список каналов</h2>
<div id="channels-container" class="channels-grid">
<div class="empty-state">
<p>Выберите плейлист для загрузки каналов</p>
<p class="empty-state-sub">Выберите категорию из выпадающего списка выше</p>
</div>
</div>
</div>
<div class="player-section">
<h2>Просмотр канала</h2>
<div class="player-container">
<div class="player-frame">
<video id="tv-player" controls playsinline></video>
<div id="player-loading" class="player-loading">
<div class="loading-spinner"></div>
<p>Выберите канал для просмотра</p>
</div>
<div id="player-error" class="player-error" style="display: none;">
<p>Ошибка загрузки канала</p>
<button id="retry-btn" class="retry-btn">Повторить попытку</button>
</div>
</div>
<div class="player-info">
<h3 id="current-channel-name">Канал не выбран</h3>
<div class="player-controls">
<button id="fullscreen-btn" class="control-btn">
<img src="fullscreen.png" alt="Полный экран" class="control-icon">
<span>Полный экран</span>
</button>
<button id="mute-btn" class="control-btn">
<img src="volume.png" alt="Звук" class="control-icon">
<span>Звук</span>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Нижний колонтитул -->
<footer>
<div class="footer-content">
<p>© 2025 Endlad7373. All rights reserved.</p>
</div>
</footer>
<script src="script.js"></script>
<script>
// Глобальные переменные
let hls = null;
let currentPlaylist = [];
let filteredChannels = [];
let currentChannel = null;
let isMuted = false;
document.addEventListener('DOMContentLoaded', function() {
// Инициализация элементов
const playlistSelect = document.getElementById('playlist-select');
const channelSearch = document.getElementById('channel-search');
const channelsContainer = document.getElementById('channels-container');
const videoPlayer = document.getElementById('tv-player');
const playerLoading = document.getElementById('player-loading');
const playerError = document.getElementById('player-error');
const retryBtn = document.getElementById('retry-btn');
const fullscreenBtn = document.getElementById('fullscreen-btn');
const muteBtn = document.getElementById('mute-btn');
const currentChannelName = document.getElementById('current-channel-name');
// Обработчики событий
playlistSelect.addEventListener('change', loadPlaylist);
channelSearch.addEventListener('input', filterChannels);
retryBtn.addEventListener('click', retryPlayback);
fullscreenBtn.addEventListener('click', toggleFullscreen);
muteBtn.addEventListener('click', toggleMute);
// Инициализация HLS.js если браузер поддерживает
if (Hls.isSupported()) {
hls = new Hls({
debug: false,
enableWorker: true,
lowLatencyMode: true,
backBufferLength: 90
});
hls.on(Hls.Events.ERROR, function(event, data) {
console.error('HLS error:', data);
if (data.fatal) {
showPlayerError();
}
});
hls.on(Hls.Events.MANIFEST_PARSED, function() {
console.log('Manifest loaded, start playing');
playerLoading.style.display = 'none';
playerError.style.display = 'none';
videoPlayer.style.display = 'block';
videoPlayer.play().catch(e => console.log('Autoplay prevented:', e));
});
}
// Функция загрузки плейлиста
async function loadPlaylist() {
const playlistUrl = playlistSelect.value;
if (!playlistUrl) return;
channelsContainer.innerHTML = '<div class="loading-spinner"></div>';
try {
const response = await fetch(playlistUrl);
if (!response.ok) throw new Error('Ошибка загрузки плейлиста');
const m3uContent = await response.text();
currentPlaylist = parseM3U(m3uContent);
filteredChannels = [...currentPlaylist];
displayChannels();
} catch (error) {
console.error('Ошибка загрузки плейлиста:', error);
channelsContainer.innerHTML = `
<div class="error-message">
<p>Не удалось загрузить плейлист</p>
<p class="error-sub">${error.message}</p>
</div>
`;
}
}
// Функция парсинга M3U файла
function parseM3U(content) {
const channels = [];
const lines = content.split('\n');
let currentChannel = null;
for (let i = 0; i < lines.length; i++) {
const line = lines[i].trim();
if (line.startsWith('#EXTINF:')) {
currentChannel = {
name: extractChannelName(line),
logo: extractLogo(line),
group: extractGroup(line),
url: null
};
} else if (line && !line.startsWith('#') && currentChannel) {
currentChannel.url = line;
channels.push({...currentChannel});
currentChannel = null;
}
}
return channels;
}
// Вспомогательные функции для парсинга M3U
function extractChannelName(line) {
const match = line.match(/,(.+)$/);
return match ? match[1].trim() : 'Без названия';
}
function extractLogo(line) {
const match = line.match(/tvg-logo="([^"]+)"/);
return match ? match[1] : null;
}
function extractGroup(line) {
const match = line.match(/group-title="([^"]+)"/);
return match ? match[1] : 'Без категории';
}
// Функция отображения каналов
function displayChannels() {
channelsContainer.innerHTML = '';
if (filteredChannels.length === 0) {
channelsContainer.innerHTML = `
<div class="empty-state">
<p>Каналы не найдены</p>
<p class="empty-state-sub">Попробуйте изменить поисковый запрос</p>
</div>
`;
return;
}
// Группировка каналов по категориям
const groupedChannels = {};
filteredChannels.forEach(channel => {
if (!groupedChannels[channel.group]) {
groupedChannels[channel.group] = [];
}
groupedChannels[channel.group].push(channel);
});
// Отображение каналов по группам
Object.keys(groupedChannels).forEach(groupName => {
const groupContainer = document.createElement('div');
groupContainer.className = 'channel-group';
const groupHeader = document.createElement('h3');
groupHeader.className = 'channel-group-title';
groupHeader.textContent = groupName;
groupContainer.appendChild(groupHeader);
const groupGrid = document.createElement('div');
groupGrid.className = 'channel-group-grid';
groupedChannels[groupName].forEach(channel => {
const channelCard = createChannelCard(channel);
groupGrid.appendChild(channelCard);
});
groupContainer.appendChild(groupGrid);
channelsContainer.appendChild(groupContainer);
});
}
// Функция создания карточки канала
function createChannelCard(channel) {
const card = document.createElement('div');
card.className = 'channel-card';
card.dataset.url = channel.url;
card.dataset.name = channel.name;
card.innerHTML = `
<div class="channel-logo">
${channel.logo ? `<img src="${channel.logo}" alt="${channel.name}" onerror="this.src='tv-default.png'">` :
'<div class="channel-logo-placeholder">' + channel.name.charAt(0) + '</div>'}
</div>
<div class="channel-info">
<h4 class="channel-name">${channel.name}</h4>
<span class="channel-group">${channel.group}</span>
</div>
`;
card.addEventListener('click', () => playChannel(channel));
return card;
}
// Функция фильтрации каналов
function filterChannels() {
const searchTerm = channelSearch.value.toLowerCase().trim();
if (!searchTerm) {
filteredChannels = [...currentPlaylist];
} else {
filteredChannels = currentPlaylist.filter(channel =>
channel.name.toLowerCase().includes(searchTerm) ||
channel.group.toLowerCase().includes(searchTerm)
);
}
displayChannels();
}
// Функция воспроизведения канала
function playChannel(channel) {
if (!channel.url) return;
currentChannel = channel;
currentChannelName.textContent = channel.name;
// Показываем загрузку
const playerLoading = document.getElementById('player-loading');
const playerError = document.getElementById('player-error');
const videoPlayer = document.getElementById('tv-player');
playerLoading.style.display = 'flex';
playerError.style.display = 'none';
videoPlayer.style.display = 'none';
// Останавливаем текущее воспроизведение
if (hls) {
hls.destroy();
}
videoPlayer.pause();
videoPlayer.src = '';
// Проверяем поддерживает ли браузер HLS нативно
if (videoPlayer.canPlayType('application/vnd.apple.mpegurl')) {
// Для Safari и других браузеров с нативной поддержкой HLS
videoPlayer.src = channel.url;
videoPlayer.addEventListener('loadedmetadata', function() {
playerLoading.style.display = 'none';
videoPlayer.style.display = 'block';
videoPlayer.play().catch(e => {
console.log('Autoplay prevented:', e);
showPlayerError();
});
});
videoPlayer.addEventListener('error', function() {
showPlayerError();
});
} else if (Hls.isSupported()) {
// Используем HLS.js для других браузеров
hls = new Hls({
debug: false,
enableWorker: true,
lowLatencyMode: true
});
hls.loadSource(channel.url);
hls.attachMedia(videoPlayer);
hls.on(Hls.Events.MANIFEST_PARSED, function() {
playerLoading.style.display = 'none';
videoPlayer.style.display = 'block';
videoPlayer.play().catch(e => {
console.log('Autoplay prevented:', e);
showPlayerError();
});
});
hls.on(Hls.Events.ERROR, function(event, data) {
console.error('HLS error:', data);
if (data.fatal) {
showPlayerError();
}
});
} else {
// Браузер не поддерживает HLS
showPlayerError();
console.error('HLS is not supported in this browser');
}
}
// Функция показа ошибки плеера
function showPlayerError() {
const playerLoading = document.getElementById('player-loading');
const playerError = document.getElementById('player-error');
const videoPlayer = document.getElementById('tv-player');
playerLoading.style.display = 'none';
playerError.style.display = 'block';
videoPlayer.style.display = 'none';
}
// Функция повторной попытки воспроизведения
function retryPlayback() {
if (currentChannel) {
playChannel(currentChannel);
}
}
// Функция переключения полноэкранного режима
function toggleFullscreen() {
const videoPlayer = document.getElementById('tv-player');
if (!document.fullscreenElement) {
if (videoPlayer.requestFullscreen) {
videoPlayer.requestFullscreen();
} else if (videoPlayer.webkitRequestFullscreen) {
videoPlayer.webkitRequestFullscreen();
} else if (videoPlayer.msRequestFullscreen) {
videoPlayer.msRequestFullscreen();
}
} else {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
}
}
// Функция переключения звука
function toggleMute() {
const videoPlayer = document.getElementById('tv-player');
const muteIcon = muteBtn.querySelector('.control-icon');
const muteText = muteBtn.querySelector('span');
if (isMuted) {
videoPlayer.muted = false;
isMuted = false;
muteIcon.src = 'volume.png';
muteText.textContent = 'Звук';
} else {
videoPlayer.muted = true;
isMuted = true;
muteIcon.src = 'mute.png';
muteText.textContent = 'Без звука';
}
}
// Обработчик изменения полноэкранного режима
document.addEventListener('fullscreenchange', updateFullscreenButton);
document.addEventListener('webkitfullscreenchange', updateFullscreenButton);
document.addEventListener('msfullscreenchange', updateFullscreenButton);
function updateFullscreenButton() {
const fullscreenIcon = fullscreenBtn.querySelector('.control-icon');
const fullscreenText = fullscreenBtn.querySelector('span');
if (document.fullscreenElement ||
document.webkitFullscreenElement ||
document.msFullscreenElement) {
fullscreenIcon.src = 'exit-fullscreen.png';
fullscreenText.textContent = 'Выйти из полного экрана';
} else {
fullscreenIcon.src = 'fullscreen.png';
fullscreenText.textContent = 'Полный экран';
}
}
});
</script>
</body>
</html>