@xriss/weerss 0.0.26 → 0.0.28
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 +5 -0
- package/db.js +6 -2
- package/package.json +1 -1
- package/weerss.js +74 -104
package/cmd.js
CHANGED
package/db.js
CHANGED
|
@@ -183,7 +183,7 @@ db.clean=async function(table)
|
|
|
183
183
|
})
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
db.list=async function(table,filter)
|
|
186
|
+
db.list=async function(table,filter,cb)
|
|
187
187
|
{
|
|
188
188
|
table=table||"keyval"
|
|
189
189
|
filter=filter || {}
|
|
@@ -265,7 +265,11 @@ db.list=async function(table,filter)
|
|
|
265
265
|
|
|
266
266
|
`,{},function(row)
|
|
267
267
|
{
|
|
268
|
-
|
|
268
|
+
let v=JSON.parse(row.value)
|
|
269
|
+
if((!cb)||(cb(row.key,v)))
|
|
270
|
+
{
|
|
271
|
+
rs.push(v)
|
|
272
|
+
}
|
|
269
273
|
})
|
|
270
274
|
|
|
271
275
|
return rs // filtered only, sorted by date
|
package/package.json
CHANGED
package/weerss.js
CHANGED
|
@@ -226,22 +226,70 @@ weerss.fetch=async function()
|
|
|
226
226
|
await db.close()
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
+
weerss.bucket_sort=function(bucket)
|
|
230
|
+
{
|
|
231
|
+
if( weerss.config.episode.best == "small" )
|
|
232
|
+
{
|
|
233
|
+
bucket.sort(function(a,b){
|
|
234
|
+
let al=(a && a.torrent && a.torrent.file_length) || 0
|
|
235
|
+
let bl=(b && b.torrent && b.torrent.file_length) || 0
|
|
236
|
+
return al - bl
|
|
237
|
+
})
|
|
238
|
+
}
|
|
239
|
+
else
|
|
240
|
+
if( weerss.config.episode.best == "large" )
|
|
241
|
+
{
|
|
242
|
+
bucket.sort(function(a,b){
|
|
243
|
+
let al=(a && a.torrent && a.torrent.file_length) || 0
|
|
244
|
+
let bl=(b && b.torrent && b.torrent.file_length) || 0
|
|
245
|
+
return bl - al
|
|
246
|
+
})
|
|
247
|
+
}
|
|
248
|
+
else
|
|
249
|
+
{
|
|
250
|
+
error("unknown config.episode.best option")
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return bucket
|
|
254
|
+
}
|
|
255
|
+
|
|
229
256
|
weerss.getlist=async function(filters)
|
|
230
257
|
{
|
|
258
|
+
let cb=function(key,item)
|
|
259
|
+
{
|
|
260
|
+
if(!item.show) { return false }
|
|
261
|
+
if(item.show.fail) { return false }
|
|
262
|
+
if(!item.show.tvmaze) { return false }
|
|
263
|
+
if( ! shows.good_show(item.show,weerss.config.show.rules) ) { return false }
|
|
264
|
+
|
|
265
|
+
// remove huge/small files
|
|
266
|
+
if(!item.torrent) { return false }
|
|
267
|
+
if(!item.torrent.file_length) { return false }
|
|
268
|
+
if( item.torrent.file_length > weerss.config.episode.maxsize ) { return false }
|
|
269
|
+
if( item.torrent.file_length < weerss.config.episode.minsize ) { return false }
|
|
270
|
+
|
|
271
|
+
if( weerss.config.episode.maxage ) // remove old episodes
|
|
272
|
+
{
|
|
273
|
+
if(!item.show.date) { return false }
|
|
274
|
+
let now=(new Date()).getTime()
|
|
275
|
+
let test=Date.parse(item.show.date)
|
|
276
|
+
let days=Math.floor((now-test)/(1000*60*60*24))
|
|
277
|
+
if( days > weerss.config.episode.maxage ) { return false } // this episode is too old
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
if( ! shows.good_episode(item.show,weerss.config.episode.rules) ) { return false } // skip this episode?
|
|
281
|
+
|
|
282
|
+
return true
|
|
283
|
+
}
|
|
284
|
+
|
|
231
285
|
// all items then we sort and filter and list
|
|
232
|
-
let its=await db.list("items",filters||{})
|
|
286
|
+
let its=await db.list("items",filters||{},cb)
|
|
233
287
|
|
|
234
288
|
let buckets={}
|
|
235
289
|
let itemshows={}
|
|
236
290
|
|
|
237
291
|
for(let item of its)
|
|
238
292
|
{
|
|
239
|
-
if(!item.show) { continue }
|
|
240
|
-
// if(!item.show.tvmaze) { continue }
|
|
241
|
-
if(item.show.fail) { continue }
|
|
242
|
-
|
|
243
|
-
// let bid=item.show.id+"_"+item.show.season+"_"+item.show.episode
|
|
244
|
-
|
|
245
293
|
let SxxExx=("S"+item.show.season.toString().padStart(2, "0")+"E"+item.show.episode.toString().padStart(2, "0") )
|
|
246
294
|
|
|
247
295
|
if(!buckets[item.show.id]){buckets[item.show.id]={}}
|
|
@@ -255,102 +303,17 @@ weerss.getlist=async function(filters)
|
|
|
255
303
|
let list=[]
|
|
256
304
|
for( let showid in itemshows )
|
|
257
305
|
{
|
|
258
|
-
let
|
|
259
|
-
|
|
260
|
-
if( show.tvmaze )
|
|
306
|
+
for( let SxxExx in buckets[showid] )
|
|
261
307
|
{
|
|
262
|
-
|
|
263
|
-
{
|
|
264
|
-
continue
|
|
265
|
-
}
|
|
266
|
-
// console.log("SHOW : "+show.tvmaze.name+" + "+(show.tvmaze.type+" "+show.tvmaze.genres.join(" ")).toLowerCase() )
|
|
308
|
+
let bucket=buckets[showid][SxxExx]
|
|
267
309
|
|
|
268
|
-
|
|
269
|
-
{
|
|
270
|
-
let bucket=buckets[showid][SxxExx]
|
|
271
|
-
// console.log( SxxExx + " x " + bucket.length )
|
|
310
|
+
weerss.bucket_sort(bucket) // sort by size etc
|
|
272
311
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
{
|
|
277
|
-
if( (it.show) && (it.show.date) ) // check all for first episode we find with valid date
|
|
278
|
-
{
|
|
279
|
-
let now=(new Date()).getTime()
|
|
280
|
-
let test=Date.parse(it.show.date)
|
|
281
|
-
let days=Math.floor((now-test)/(1000*60*60*24))
|
|
282
|
-
if( days > weerss.config.episode.maxage ) // this episode is too old
|
|
283
|
-
{
|
|
284
|
-
while( bucket.length > 0){ bucket.pop() } // empty array
|
|
285
|
-
}
|
|
286
|
-
break;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
for( let idx=bucket.length-1 ; idx>=0 ; idx-- ) // remove huge/small files
|
|
292
|
-
{
|
|
293
|
-
let it=bucket[ idx ]
|
|
294
|
-
if( it && it.torrent && it.torrent.file_length )
|
|
295
|
-
{
|
|
296
|
-
if( it.torrent.file_length > weerss.config.episode.maxsize ) // 3GB
|
|
297
|
-
{
|
|
298
|
-
bucket.splice( idx , 1 )
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
if( it.torrent.file_length < weerss.config.episode.minsize ) // 3GB
|
|
302
|
-
{
|
|
303
|
-
bucket.splice( idx , 1 )
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
if( weerss.config.episode.best == "small" )
|
|
310
|
-
{
|
|
311
|
-
bucket.sort(function(a,b){
|
|
312
|
-
let al=(a && a.torrent && a.torrent.file_length) || 0
|
|
313
|
-
let bl=(b && b.torrent && b.torrent.file_length) || 0
|
|
314
|
-
return al - bl
|
|
315
|
-
})
|
|
316
|
-
}
|
|
317
|
-
else
|
|
318
|
-
if( weerss.config.episode.best == "large" )
|
|
319
|
-
{
|
|
320
|
-
bucket.sort(function(a,b){
|
|
321
|
-
let al=(a && a.torrent && a.torrent.file_length) || 0
|
|
322
|
-
let bl=(b && b.torrent && b.torrent.file_length) || 0
|
|
323
|
-
return bl - al
|
|
324
|
-
})
|
|
325
|
-
}
|
|
326
|
-
else
|
|
327
|
-
{
|
|
328
|
-
error("unknown config.episode.best option")
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
while( bucket.length>0 ) // check episode flags ( uses words from filename + all the show flags )
|
|
332
|
-
{
|
|
333
|
-
if( ! shows.good_episode(bucket[ 0 ].show,weerss.config.episode.rules) ) // skip this episode?
|
|
334
|
-
{
|
|
335
|
-
bucket.shift() // remove
|
|
336
|
-
}
|
|
337
|
-
else
|
|
338
|
-
{
|
|
339
|
-
break
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
// console.log(aa.join(" "))
|
|
343
|
-
// console.log(bucket[0].show.tags.join(" ") + " : " + Math.floor(bucket[0].torrent.file_length/(1024*1024)) )
|
|
344
|
-
if( bucket[0] )
|
|
345
|
-
{
|
|
346
|
-
list.push( bucket[0] )
|
|
347
|
-
}
|
|
312
|
+
if( bucket[0] )
|
|
313
|
+
{
|
|
314
|
+
list.push( bucket[0] )
|
|
348
315
|
}
|
|
349
316
|
}
|
|
350
|
-
else
|
|
351
|
-
{
|
|
352
|
-
// console.log("UNKNOWN : "+show.name)
|
|
353
|
-
}
|
|
354
317
|
}
|
|
355
318
|
list.sort( function(a,b){
|
|
356
319
|
return new Date(b.date) - new Date(a.date)
|
|
@@ -360,14 +323,16 @@ weerss.getlist=async function(filters)
|
|
|
360
323
|
|
|
361
324
|
weerss.list=async function(args)
|
|
362
325
|
{
|
|
326
|
+
/*
|
|
363
327
|
let past=new Date()
|
|
364
328
|
past.setDate( past.getDate()-28 )
|
|
365
329
|
past=past.toISOString()
|
|
366
330
|
let filters={date_gt:past}
|
|
331
|
+
*/
|
|
367
332
|
|
|
368
333
|
await db.setup()
|
|
369
334
|
|
|
370
|
-
let list=(await weerss.getlist(
|
|
335
|
+
let list=(await weerss.getlist()).slice(0,weerss.config.rss.length)
|
|
371
336
|
for(let item of list)
|
|
372
337
|
{
|
|
373
338
|
console.log( item_to_string(item))
|
|
@@ -421,11 +386,7 @@ weerss.save_rss=async function(args)
|
|
|
421
386
|
rss_items.push(it)
|
|
422
387
|
}
|
|
423
388
|
|
|
424
|
-
let
|
|
425
|
-
past.setDate( past.getDate()-28 )
|
|
426
|
-
past=past.toISOString()
|
|
427
|
-
let filters={date_gt:past}
|
|
428
|
-
let list=(await weerss.getlist(filters)).slice(0,weerss.config.rss.length)
|
|
389
|
+
let list=(await weerss.getlist()).slice(0,weerss.config.rss.length)
|
|
429
390
|
for(let item of list)
|
|
430
391
|
{
|
|
431
392
|
push_item(item)
|
|
@@ -644,5 +605,14 @@ weerss.dirs=async function(args)
|
|
|
644
605
|
|
|
645
606
|
|
|
646
607
|
|
|
608
|
+
await db.close()
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
weerss.purge=async function(args)
|
|
613
|
+
{
|
|
614
|
+
await db.setup()
|
|
615
|
+
|
|
616
|
+
|
|
647
617
|
await db.close()
|
|
648
618
|
}
|