torrent-online 1.7.1 → 1.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -1
- package/wtui.js +20 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "torrent-online",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Stream .torrent / magnet to VLC or browser — torrent streaming for macOS/Linux without a torrent client. Стрим торрентов в VLC или браузер.",
|
|
6
6
|
"keywords": [
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@inquirer/prompts": "^7.0.0",
|
|
43
|
+
"hls.js": "^1.5.17",
|
|
43
44
|
"webtorrent": "^3.0.21"
|
|
44
45
|
},
|
|
45
46
|
"engines": {
|
package/wtui.js
CHANGED
|
@@ -586,17 +586,25 @@ video{width:100vw;height:100vh;background:#000;display:block;margin:0}
|
|
|
586
586
|
var BASE="__BASE__";
|
|
587
587
|
function esc(s){return String(s).replace(/[&<>"']/g,function(c){return {'&':'&','<':'<','>':'>','"':'"',"'":'''}[c];});}
|
|
588
588
|
function api(p,body){var o=body?{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify(body)}:undefined;return fetch(BASE+p,o).then(function(r){return r.json();});}
|
|
589
|
+
function addTorrent(mag){
|
|
590
|
+
var box=document.getElementById('torrents');
|
|
591
|
+
var dn=(/dn=([^&]*)/.exec(mag)||[,''])[1];try{dn=decodeURIComponent(dn.replace(/\+/g,' '))}catch(e){}
|
|
592
|
+
var ph=document.createElement('div');ph.className='card';
|
|
593
|
+
ph.innerHTML='<div class=tname>⏳ '+esc(dn||'торрент')+'</div><div class=tmeta>добавляю в клиент…</div>';
|
|
594
|
+
box.prepend(ph);
|
|
595
|
+
api('/api/add',{source:mag}).then(function(d){if(d&&d.error){ph.innerHTML='<div class=tname>⚠ '+esc(d.error)+'</div>';}poll();toTorrents();}).catch(function(e){ph.innerHTML='<div class=tname>⚠ Ошибка /api/add: '+esc(e&&e.message||e)+'</div>';});
|
|
596
|
+
}
|
|
589
597
|
function doSearch(){var q=document.getElementById('q').value.trim();if(!q)return;var box=document.getElementById('results');box.innerHTML='<div class=note>Ищу…</div>';
|
|
590
598
|
api('/api/search?q='+encodeURIComponent(q)).then(function(d){
|
|
591
599
|
var h='';(d.notes||[]).forEach(function(n){h+='<div class=note>⚠ '+esc(n)+'</div>';});
|
|
592
600
|
if(!d.items.length){box.innerHTML=h+'<div class=note>Ничего не найдено</div>';return;}
|
|
593
601
|
h+=d.items.map(function(it){return '<div class=row data-mag="'+esc(it.mag)+'"><span class=tag>'+esc(it.src)+'</span><span class=rname>'+esc(it.name)+'</span>'+(it.size?'<span class=meta>'+esc(it.size)+'</span>':'')+(it.seeds?'<span class=meta>🌱 '+it.seeds+'</span>':'')+'</div>';}).join('');
|
|
594
602
|
box.innerHTML=h;
|
|
595
|
-
[].forEach.call(box.querySelectorAll('.row'),function(r){r.onclick=function(){
|
|
603
|
+
[].forEach.call(box.querySelectorAll('.row'),function(r){r.onclick=function(){addTorrent(r.getAttribute('data-mag'));};});
|
|
596
604
|
}).catch(function(){box.innerHTML='<div class=note>Ошибка поиска</div>';});}
|
|
597
605
|
document.getElementById('go').onclick=doSearch;
|
|
598
606
|
document.getElementById('q').addEventListener('keydown',function(e){if(e.key==='Enter')doSearch();});
|
|
599
|
-
document.getElementById('mag').onclick=function(){var m=prompt('magnet:');if(m&&m.indexOf('magnet:')===0){
|
|
607
|
+
document.getElementById('mag').onclick=function(){var m=prompt('magnet:');if(m&&m.indexOf('magnet:')===0){addTorrent(m);}};
|
|
600
608
|
document.getElementById('tpath').onclick=function(){document.getElementById('tt').click();};
|
|
601
609
|
document.getElementById('tt').onchange=function(){if(this.files&&this.files[0])uploadFile(this.files[0]);this.value='';};
|
|
602
610
|
function uploadFile(f){var nb=document.getElementById('notes');nb.innerHTML='<div class=note>⏳ Загружаю '+esc(f.name)+'…</div>';
|
|
@@ -669,6 +677,15 @@ async function webReq(req, res, client, st, opts, cacheDir, base) {
|
|
|
669
677
|
res.end(WEB_HTML.replace('__BASE__', base));
|
|
670
678
|
return;
|
|
671
679
|
}
|
|
680
|
+
if (p === '/hls.min.js') {
|
|
681
|
+
try {
|
|
682
|
+
const b = fs.readFileSync(require.resolve('hls.js/dist/hls.min.js'));
|
|
683
|
+
res.setHeader('Content-Type', 'application/javascript; charset=utf-8');
|
|
684
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
685
|
+
res.end(b);
|
|
686
|
+
} catch { res.statusCode = 404; res.end('no hls.js'); }
|
|
687
|
+
return;
|
|
688
|
+
}
|
|
672
689
|
if (p === '/api/search') {
|
|
673
690
|
const q = u.searchParams.get('q') || '';
|
|
674
691
|
const { items, notes } = await searchIndexers(q);
|
|
@@ -942,7 +959,7 @@ video{flex:1;width:100%;min-height:0;background:#000}
|
|
|
942
959
|
<div class=bar><b>${esc(f.name)}</b><select id=a style=display:none></select><select id=s style=display:none></select><span id=n></span></div>
|
|
943
960
|
<video id=v controls autoplay playsinline></video>
|
|
944
961
|
<div id=ov>▶</div>
|
|
945
|
-
<script src="
|
|
962
|
+
<script src="${base}/hls.min.js"></script>
|
|
946
963
|
<script>
|
|
947
964
|
var B=${JSON.stringify(base)},ID=${mV[1]},I=${mV[2]};
|
|
948
965
|
var v=document.getElementById("v"),aS=document.getElementById("a"),sS=document.getElementById("s"),n=document.getElementById("n"),ov=document.getElementById("ov");
|