@xriss/weerss 0.0.25 → 0.0.27
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/feeds.js +1 -1
- package/package.json +1 -1
- package/weerss.js +79 -100
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/feeds.js
CHANGED
|
@@ -206,7 +206,7 @@ feeds.fetch_all=async function()
|
|
|
206
206
|
return ( b.items_date || 0 ) - ( a.items_date || 0 )
|
|
207
207
|
})
|
|
208
208
|
|
|
209
|
-
let topitem=(await db.list("items",{},"date","prev",1))[0] ; topitem=topitem && topitem.uuid
|
|
209
|
+
// let topitem=(await db.list("items",{},"date","prev",1))[0] ; topitem=topitem && topitem.uuid
|
|
210
210
|
|
|
211
211
|
for(let feed of list )
|
|
212
212
|
{
|
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.
|
|
229
|
+
weerss.bucket_sort=function(bucket)
|
|
230
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
|
+
|
|
256
|
+
weerss.getlist=async function(filters)
|
|
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(it.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",{})
|
|
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()
|
|
|
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() )
|
|
267
|
-
|
|
268
|
-
for( let SxxExx in buckets[showid] )
|
|
269
|
-
{
|
|
270
|
-
let bucket=buckets[showid][SxxExx]
|
|
271
|
-
// console.log( SxxExx + " x " + bucket.length )
|
|
272
|
-
|
|
273
|
-
if( weerss.config.episode.maxage )
|
|
274
|
-
{
|
|
275
|
-
for( let it of bucket )
|
|
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
|
-
}
|
|
308
|
+
let bucket=buckets[showid][SxxExx]
|
|
307
309
|
|
|
310
|
+
weerss.bucket_sort(bucket) // sort by size etc
|
|
308
311
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
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,6 +323,13 @@ weerss.getlist=async function()
|
|
|
360
323
|
|
|
361
324
|
weerss.list=async function(args)
|
|
362
325
|
{
|
|
326
|
+
/*
|
|
327
|
+
let past=new Date()
|
|
328
|
+
past.setDate( past.getDate()-28 )
|
|
329
|
+
past=past.toISOString()
|
|
330
|
+
let filters={date_gt:past}
|
|
331
|
+
*/
|
|
332
|
+
|
|
363
333
|
await db.setup()
|
|
364
334
|
|
|
365
335
|
let list=(await weerss.getlist()).slice(0,weerss.config.rss.length)
|
|
@@ -416,7 +386,7 @@ weerss.save_rss=async function(args)
|
|
|
416
386
|
rss_items.push(it)
|
|
417
387
|
}
|
|
418
388
|
|
|
419
|
-
let list=(await weerss.getlist(
|
|
389
|
+
let list=(await weerss.getlist()).slice(0,weerss.config.rss.length)
|
|
420
390
|
for(let item of list)
|
|
421
391
|
{
|
|
422
392
|
push_item(item)
|
|
@@ -635,5 +605,14 @@ weerss.dirs=async function(args)
|
|
|
635
605
|
|
|
636
606
|
|
|
637
607
|
|
|
608
|
+
await db.close()
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
weerss.purge=async function(args)
|
|
613
|
+
{
|
|
614
|
+
await db.setup()
|
|
615
|
+
|
|
616
|
+
|
|
638
617
|
await db.close()
|
|
639
618
|
}
|