@xriss/weerss 0.0.4 → 0.0.6

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/cmd.js CHANGED
@@ -2,6 +2,7 @@
2
2
  const cmd={}
3
3
  export default cmd
4
4
 
5
+ import wtf from 'wtfnode'
5
6
 
6
7
  import mri from "mri"
7
8
 
@@ -98,6 +99,7 @@ if( arg1=="config" )
98
99
  else
99
100
  if( arg1=="fetch" )
100
101
  {
102
+ args.wtf=true // torrents are a problem so force exit afterwards
101
103
  await weerss.fetch(args)
102
104
  }
103
105
  else
@@ -124,3 +126,10 @@ else
124
126
  {
125
127
  console.log(` Unknown weerss command "${arg1}" `)
126
128
  }
129
+
130
+ if(args.wtf)
131
+ {
132
+ console.log(` Forcing exit `)
133
+ wtf.dump()
134
+ process.exit(0)
135
+ }
package/hoard.js CHANGED
@@ -66,10 +66,13 @@ hoard.fetch_text=async function(url,refresh)
66
66
  it.date=new Date()
67
67
  try{
68
68
 
69
+ let timeout_id
69
70
  let res=await Promise.race([
70
71
  fetch(corsurl),
71
- new Promise((_, reject) => setTimeout(() => reject("timeout"), 2*1000)),
72
+ new Promise(function(_, reject){ timeout_id=setTimeout(function(){reject("timeout")}, 2*1000) } ),
72
73
  ])
74
+ if(timeout_id) { clearTimeout(timeout_id) }
75
+
73
76
  it.status=res.status
74
77
  it.text=await res.text()
75
78
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xriss/weerss",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "source": "weerss.js",
5
5
  "type": "module",
6
6
  "repository": {
@@ -17,6 +17,7 @@
17
17
  "dependencies": {
18
18
  "@xriss/djon": "^0.0.14",
19
19
  "express": "^4.19.2",
20
+ "memory-chunk-store": "^1.3.5",
20
21
  "move-file": "^3.1.0",
21
22
  "mri": "^1.2.0",
22
23
  "parse-torrent": "^11.0.17",
@@ -27,7 +28,9 @@
27
28
  "sax": "^1.4.1",
28
29
  "sqlite3": "^5.1.7",
29
30
  "stream-browserify": "^3.0.0",
30
- "webpack": "^5.94.0"
31
+ "webpack": "^5.94.0",
32
+ "webtorrent": "^2.5.1",
33
+ "wtfnode": "^0.9.3"
31
34
  },
32
35
  "devDependencies": {
33
36
  "webpack-cli": "^5.1.4"
package/torrents.js CHANGED
@@ -4,9 +4,12 @@ let torrents={}
4
4
  export default torrents
5
5
 
6
6
 
7
- import db from "./db.js"
7
+ import db from "./db.js"
8
+ import hoard from "./hoard.js"
8
9
 
10
+ import WebTorrent from 'webtorrent'
9
11
  import { remote } from 'parse-torrent'
12
+ import memchunks from 'memory-chunk-store'
10
13
 
11
14
 
12
15
 
@@ -27,15 +30,90 @@ torrents.fetch=async function(url)
27
30
  let ret = await torrents.get(url)
28
31
  if( ret && ret.data) { return ret.data }
29
32
 
30
- let torrent_parse=function(torrent) {
33
+ let urlplus=url
34
+ if(urlplus.toLowerCase().startsWith("magnet:")) // auto add trackers
35
+ {
36
+ let trackers=(await hoard.fast_text("https://newtrackon.com/api/stable")).split("\n")
37
+ let count=0
38
+ for(let t of trackers)
39
+ {
40
+ t=t.trim()
41
+ if(t!="")
42
+ {
43
+ urlplus=urlplus+"&tr="+encodeURIComponent(t)
44
+ count=count+1
45
+ if(count>10){break}
46
+ }
47
+ }
48
+ }
49
+ // console.log(urlplus)
50
+
51
+ let torrent_parse=function(url) {
31
52
  return new Promise(function(resolve, reject) {
32
- remote(torrent, { timeout: 60 * 1000 }, function(err, parsedTorrent){
53
+ remote(url, { timeout: 60 * 1000 }, function(err, parsedTorrent){
33
54
  if (err) { reject(err) }
34
55
  resolve(parsedTorrent)
35
56
  })
36
57
  })
37
58
  }
38
- let data=await torrent_parse(url) // should work with magnets
59
+ let data=await torrent_parse(urlplus) // does not work with magnets?
60
+
61
+ let client
62
+ let torrent_magnet_add=async function(url) {
63
+ return new Promise(function(resolve, reject)
64
+ {
65
+ client = new WebTorrent()
66
+ client.on('error', function(err){ if(!client.destroyed){client.destroy()} ; reject(err) })
67
+ // download to memory using memchunks
68
+ let torrent=client.add(url, {store:memchunks} , function(torrent){
69
+ resolve(torrent)
70
+ })
71
+ torrent.on('error', function(err){ if(!client.destroyed){client.destroy()} ; reject(err) })
72
+ torrent.on('noPeers', function(err){ if(!client.destroyed){client.destroy()} ; reject(err) })
73
+ /*
74
+ for(let n of [
75
+ "infoHash" , "metadata" , "ready" , "warning" ,
76
+ "error" , "done" , "download" , "upload" ,
77
+ "wire" , "noPeers" , "verified"
78
+ ])
79
+ {
80
+ torrent.on(n, function(d){ console.log(n,d) })
81
+ }
82
+ */
83
+ })
84
+ }
85
+
86
+ if(!data.files) // need to magnet?
87
+ {
88
+ data.files=[]
89
+ // console.log(data)
90
+
91
+ let timeout_id
92
+ let torrent=await Promise.race([
93
+ torrent_magnet_add(urlplus),
94
+ new Promise(function(_, reject){ timeout_id=setTimeout(function(){reject("timeout")}, 10*1000) } ),
95
+ ])
96
+ if(timeout_id) { clearTimeout(timeout_id) }
97
+
98
+ if(torrent)
99
+ {
100
+ data.length=torrent.length
101
+ // console.log(data.files)
102
+ for( let ff of torrent.files )
103
+ {
104
+ let f={}
105
+ f.name=ff.name
106
+ f.length=ff.length
107
+ data.files.push(f)
108
+ }
109
+ torrent.destroy()
110
+ }
111
+ if(client)
112
+ {
113
+ if(!client.destroyed){client.destroy()}
114
+ client=undefined
115
+ }
116
+ }
39
117
 
40
118
  if(data)
41
119
  {
@@ -91,7 +169,7 @@ torrents.fill_torrent=async function(item)
91
169
  if( torrent ) // did we get something
92
170
  {
93
171
  item.torrent={fail:true}
94
-
172
+
95
173
  for(let file of torrent.files)
96
174
  {
97
175
  let pct=Math.floor(100*file.length/torrent.length)
package/weerss.js CHANGED
@@ -167,6 +167,10 @@ weerss.fetch=async function()
167
167
  await db.setup()
168
168
  // db.clear("hoard") // delete cache on startup
169
169
 
170
+ // clear cached data
171
+ db.clear("torrents")
172
+ db.clear("hoard")
173
+
170
174
  for(let feed of await db.list("feeds") )
171
175
  {
172
176
  let keep=false
@@ -350,10 +354,10 @@ weerss.save_rss=async function(args)
350
354
  "/rss/channel/language" : "en-us" ,
351
355
  "/rss/channel/lastBuildDate" : dates ,
352
356
  "/rss/channel/pubDate" : dates ,
353
- "/rss/channel/description" : "RERSS" ,
354
- "/rss/channel/generator" : "RERSS" ,
355
- "/rss/channel/link" : "RERSS" ,
356
- "/rss/channel/title" : "RERSS" ,
357
+ "/rss/channel/description" : "WEERSS" ,
358
+ "/rss/channel/generator" : "WEERSS" ,
359
+ "/rss/channel/link" : "WEERSS" ,
360
+ "/rss/channel/title" : "WEERSS" ,
357
361
  "/rss/channel/item" : rss_items ,
358
362
  }
359
363