index.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>在线TXT转M3U格式 - 范明明</title>
  7. <meta name="description" content="一个简单的在线TXT转M3U格式工具,纯前端处理,无需上传txt文件粘贴即转换,安全不偷源。">
  8. <meta name="keywords" content="txt转m3u,txt转换,m3u生成,范明明,LIVE">
  9. <style>
  10. body {
  11. text-align: center;
  12. font-family: Arial, sans-serif;
  13. background-color: #f5f5f5;
  14. margin: 0;
  15. padding: 0;
  16. }
  17. h2 {
  18. color: #333;
  19. }
  20. #inputContainer {
  21. margin-top: 10px;
  22. }
  23. label {
  24. display: block;
  25. margin-bottom: 5px;
  26. color: #666;
  27. }
  28. textarea, #m3uOutput {
  29. width: 800px;
  30. height: 368px;
  31. box-sizing: border-box;
  32. padding: 10px;
  33. margin-top: 5px;
  34. border: 1px solid #ccc;
  35. border-radius: 5px;
  36. font-size: 12px;
  37. }
  38. button {
  39. margin-top: 10px;
  40. padding: 10px 10px;
  41. font-size: 14px;
  42. cursor: pointer;
  43. background-color: #4CAF50;
  44. color: white;
  45. border: none;
  46. border-radius: 5px;
  47. }
  48. button:hover {
  49. background-color: #45a049;
  50. }
  51. #m3uOutput {
  52. margin-top: 5px;
  53. background-color: #fff;
  54. color: #333;
  55. }
  56. #copyright {
  57. margin-top: 20px;
  58. color: #666;
  59. font-size: 12px;
  60. }
  61. </style>
  62. </head>
  63. <body>
  64. <h2>在线TXT转M3U格式</h2>
  65. <h3>TXT格式源:</h3>
  66. <div id="inputContainer">
  67. <textarea id="txtInput" rows="10" cols="80"></textarea>
  68. </div>
  69. <button onclick="convertToM3U()">转换格式</button>
  70. <button onclick="clearScreen()">清除屏幕</button>
  71. <button onclick="copyContent()">拷贝结果</button>
  72. <button onclick="saveAsM3U()">保存m3u</button>
  73. <h3>M3U格式转换结果:</h3>
  74. <textarea id="m3uOutput" rows="10" cols="80" readonly></textarea>
  75. <div id="copyright">
  76. <p>© 2023 live.fanmingming.com All Rights Reserved.</p>
  77. </div>
  78. <script>
  79. function convertToM3U() {
  80. const txtInput = document.getElementById('txtInput').value;
  81. const lines = txtInput.split('\n');
  82. let m3uOutput = '#EXTM3U x-tvg-url="https://live.fanmingming.cn/e.xml"\n';
  83. let currentGroup = null;
  84. for (const line of lines) {
  85. const trimmedLine = line.trim();
  86. if (trimmedLine !== '') {
  87. if (trimmedLine.includes('#genre#')) {
  88. currentGroup = trimmedLine.replace(/,#genre#/, '').trim();
  89. } else {
  90. const [originalChannelName, channelLink] = trimmedLine.split(',').map(item => item.trim());
  91. const processedChannelName = originalChannelName.replace(/(CCTV|CETV)-(\d+).*/, '$1$2');
  92. m3uOutput += `#EXTINF:-1 tvg-name="${processedChannelName}" tvg-logo="https://live.fanmingming.cn/tv/${processedChannelName}.png"`;
  93. if (currentGroup) {
  94. m3uOutput += ` group-title="${currentGroup}"`;
  95. }
  96. m3uOutput += `,${originalChannelName}\n${channelLink}\n`;
  97. }
  98. }
  99. }
  100. document.getElementById('m3uOutput').value = m3uOutput;
  101. }
  102. function clearScreen() {
  103. document.getElementById('txtInput').value = '';
  104. document.getElementById('m3uOutput').value = '';
  105. }
  106. function copyContent() {
  107. const m3uOutput = document.getElementById('m3uOutput');
  108. m3uOutput.select();
  109. document.execCommand('copy');
  110. alert('内容已复制到剪贴板!');
  111. }
  112. function saveAsM3U() {
  113. const m3uContent = document.getElementById('m3uOutput').value;
  114. const blob = new Blob([m3uContent], { type: 'text/plain' });
  115. const a = document.createElement('a');
  116. a.href = URL.createObjectURL(blob);
  117. a.download = 'playlist.m3u';
  118. document.body.appendChild(a);
  119. a.click();
  120. document.body.removeChild(a);
  121. }
  122. </script>
  123. </body>
  124. </html>