forked from fanmingming/live
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
124 lines (124 loc) · 3.84 KB
/
index.html
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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>在线TXT转M3U格式 - 范明明</title>
<meta name="description" content="一个简单的在线TXT转M3U格式工具,纯前端处理,无需上传txt文件粘贴即转换,安全不偷源。">
<meta name="keywords" content="txt转m3u,txt转换,m3u生成,范明明,LIVE">
<style>
body {
text-align: center;
font-family: Arial, sans-serif;
background-color: #f5f5f5;
margin: 0;
padding: 0;
}
h2 {
color: #333;
}
#inputContainer {
margin-top: 10px;
}
label {
display: block;
margin-bottom: 5px;
color: #666;
}
textarea, #m3uOutput {
width: 800px;
height: 368px;
box-sizing: border-box;
padding: 10px;
margin-top: 5px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 12px;
}
button {
margin-top: 10px;
padding: 10px 10px;
font-size: 14px;
cursor: pointer;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
}
button:hover {
background-color: #45a049;
}
#m3uOutput {
margin-top: 5px;
background-color: #fff;
color: #333;
}
#copyright {
margin-top: 20px;
color: #666;
font-size: 12px;
}
</style>
</head>
<body>
<h2>在线TXT转M3U格式</h2>
<h3>TXT格式源:</h3>
<div id="inputContainer">
<textarea id="txtInput" rows="10" cols="80"></textarea>
</div>
<button onclick="convertToM3U()">转换格式</button>
<button onclick="clearScreen()">清除屏幕</button>
<button onclick="copyContent()">拷贝结果</button>
<button onclick="saveAsM3U()">保存m3u</button>
<h3>M3U格式转换结果:</h3>
<textarea id="m3uOutput" rows="10" cols="80" readonly></textarea>
<div id="copyright">
<p>© 2023 live.fanmingming.com All Rights Reserved.</p>
</div>
<script>
function convertToM3U() {
const txtInput = document.getElementById('txtInput').value;
const lines = txtInput.split('\n');
let m3uOutput = '#EXTM3U x-tvg-url="https://live.fanmingming.com/e.xml"\n';
let currentGroup = null;
for (const line of lines) {
const trimmedLine = line.trim();
if (trimmedLine !== '') {
if (trimmedLine.includes('#genre#')) {
currentGroup = trimmedLine.replace(/,#genre#/, '').trim();
} else {
const [originalChannelName, channelLink] = trimmedLine.split(',').map(item => item.trim());
const processedChannelName = originalChannelName.replace(/(CCTV|CETV)-(\d+).*/, '$1$2');
m3uOutput += `#EXTINF:-1 tvg-name="${processedChannelName}" tvg-logo="https://live.fanmingming.com/tv/${processedChannelName}.png"`;
if (currentGroup) {
m3uOutput += ` group-title="${currentGroup}"`;
}
m3uOutput += `,${originalChannelName}\n${channelLink}\n`;
}
}
}
document.getElementById('m3uOutput').value = m3uOutput;
}
function clearScreen() {
document.getElementById('txtInput').value = '';
document.getElementById('m3uOutput').value = '';
}
function copyContent() {
const m3uOutput = document.getElementById('m3uOutput');
m3uOutput.select();
document.execCommand('copy');
alert('内容已复制到剪贴板!');
}
function saveAsM3U() {
const m3uContent = document.getElementById('m3uOutput').value;
const blob = new Blob([m3uContent], { type: 'text/plain' });
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = 'playlist.m3u';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
</script>
</body>
</html>