@xriss/weerss 0.0.2 → 0.0.4

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.
Files changed (4) hide show
  1. package/cmd.js +35 -15
  2. package/db.js +1 -1
  3. package/package.json +2 -2
  4. package/weerss.js +41 -24
package/cmd.js CHANGED
@@ -3,7 +3,7 @@ const cmd={}
3
3
  export default cmd
4
4
 
5
5
 
6
- import minimist from "minimist"
6
+ import mri from "mri"
7
7
 
8
8
  import path from "path"
9
9
  import url from "url"
@@ -17,14 +17,16 @@ import items from "./items.js"
17
17
 
18
18
  import weerss from "./weerss.js"
19
19
 
20
- const args = minimist(process.argv.slice(2),{boolean:true})
20
+ const args = mri(process.argv.slice(2))
21
+ //console.log(args)
21
22
 
22
- args.config=args.config || process.env.WEERSS_CONFIG
23
+ args.config=args.config || process.env.WEERSS_CONFIG || process.env.HOME+"/.config/weerss/config.djon"
23
24
 
24
25
  await weerss.load_config(args)
25
26
 
26
27
  let arg1=args._[0] || "help"
27
28
  let arg2=args._[1]
29
+ let arg3=args._[3]
28
30
 
29
31
  if( arg1=="help" )
30
32
  {
@@ -42,30 +44,48 @@ options:
42
44
 
43
45
  export WEERSS_CONFIG=/home/dave/weerss.config
44
46
 
47
+ All options are loaded into this config structure with . used as an
48
+ object seperator and the value parsed as json.
49
+
50
+ EG To choose the number of items in your rss feed from the command line
51
+ and thus overide the config file setting.
52
+
53
+ --rss.length=100
54
+ or
55
+ --rss='{length:100}'
56
+
57
+ With the later removing any other values in the rss object while the
58
+ former just changes the legth value.
59
+
45
60
  commands:
46
61
 
47
- tvrss config
48
- Print current config.
62
+ weerss config
63
+ Create a default to config file if we do not already have one and
64
+ then print the current config. I recomend reading the default
65
+ config file for comments about how to configure weerss.
49
66
 
50
- tvrss config FILENAME
51
- Save current (default?) config to FILENAME.
67
+ weerss config --force
68
+ Force saving of default config over current config.
52
69
 
53
- tvrss fetch
70
+ weerss fetch
54
71
  Fetch all feeds and scan files with tvmaze.
55
72
 
56
- tvrss list
73
+ weerss list
57
74
  List torrents in db.
58
75
 
59
- tvrss rss
76
+ weerss rss
60
77
  Save torrents as rss.
61
78
 
62
- tvrss move
63
- Move downloaded chaotic files to an organised location.
79
+ weerss move
80
+ Move downloaded chaotic files to an organised jellyfin style
81
+ directory.
64
82
 
65
- tvrss dirs
66
- Create a script to cleanup TV dirs using tvmaze.
83
+ weerss dirs
84
+ Create a script to cleanup TV dirs using tvmaze. This does not do
85
+ any cleanup just prints bash commands that you may wish to run
86
+ later.
67
87
 
68
- tvrss help
88
+ weerss help
69
89
  Print this help message.
70
90
 
71
91
  `)
package/db.js CHANGED
@@ -29,7 +29,7 @@ db.name="weerss"
29
29
  db.setup=async function()
30
30
  {
31
31
 
32
- db.handle = await AsyncDatabase.open( weerss.get_config_path("sqlite_filename") );
32
+ db.handle = await AsyncDatabase.open( weerss.get_config_path("sqlite") );
33
33
 
34
34
  // db.handle.inner.on("trace", (sql) => console.log("[TRACE]", sql));
35
35
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xriss/weerss",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "source": "weerss.js",
5
5
  "type": "module",
6
6
  "repository": {
@@ -17,8 +17,8 @@
17
17
  "dependencies": {
18
18
  "@xriss/djon": "^0.0.14",
19
19
  "express": "^4.19.2",
20
- "minimist": "^1.2.8",
21
20
  "move-file": "^3.1.0",
21
+ "mri": "^1.2.0",
22
22
  "parse-torrent": "^11.0.17",
23
23
  "path-browserify": "^1.0.1",
24
24
  "promised-sqlite3": "^2.1.0",
package/weerss.js CHANGED
@@ -17,31 +17,36 @@ import shows from "./shows.js"
17
17
  import util from "util"
18
18
  import {moveFile} from 'move-file'
19
19
 
20
+ import { promises as pfs } from "fs"
20
21
  import fs from "fs"
21
22
  import path from "path"
22
23
 
23
24
  import sanitize from "sanitize-filename"
24
25
 
25
-
26
26
  import djon from "@xriss/djon"
27
27
 
28
28
 
29
29
 
30
30
  weerss.config_default=`
31
31
  {
32
+ // set to true for verbose rule checking
32
33
  debug = FALSE
34
+ // array of url to rss feeds of torrent files
33
35
  feeds = [
34
36
  "https://archive.org/services/collection-rss.php?collection=television_inbox"
35
37
  ]
36
38
  rss = {
39
+ // number of episodes to list in the rss files
37
40
  length = 100
38
41
  }
42
+ // decide which shows we like ( data from tvmaze )
39
43
  show = {
40
44
  rules = [
41
45
  [ TRUE ]
42
46
  [ "!english" FALSE ]
43
47
  ]
44
48
  }
49
+ // decide which episode we like tags come from filename
45
50
  episode = {
46
51
  best = "small"
47
52
  maxsize = 4000000000
@@ -51,9 +56,13 @@ weerss.config_default=`
51
56
  [ "480p" FALSE ]
52
57
  ]
53
58
  }
54
- sqlite_filename = "./weerss.sqlite"
55
- download_dirname = "./download"
56
- tv_dirname = "./TV"
59
+ // paths can be relative to this config files location
60
+ paths = {
61
+ rss = "./weerss.rss"
62
+ sqlite = "./weerss.sqlite"
63
+ download = "./download"
64
+ tv = "./TV"
65
+ }
57
66
  }
58
67
  `
59
68
 
@@ -86,29 +95,37 @@ weerss.load_config=async function(args)
86
95
  {
87
96
  if(n!="_")
88
97
  {
89
- weerss.config[n]=args[n]
98
+ let va=args[n]
99
+ try{ va=djon.load(va) }catch(e){} // if can parse
100
+ let ns=n.split(".")
101
+ let f=ns.pop()
102
+ let b=weerss.config
103
+ for( let v of ns ) { b=b[v] } // sub sets
104
+ b[f]=va
90
105
  }
91
106
  }
92
107
  }
93
108
 
94
109
  weerss.save_config=async function(args)
95
110
  {
96
- if( args._[1] )
111
+ if(args.config) // need a config location
97
112
  {
98
- let fname=args._[1]
99
- console.log(` Saving config to `+fname)
100
- if(args.config) // loading a config
113
+ if( (!args.force) && fs.existsSync(args.config) ) // must not already exist
101
114
  {
102
- djon.save_file(fname,weerss.config,"djon","strict")
115
+ console.log( "Config already exists : "+args.config )
116
+ console.log( djon.save(weerss.config,"djon","strict") )
103
117
  }
104
- else // save default
118
+ else // write defaukt config
105
119
  {
106
- fs.writeFileSync( fname , weerss.config_default )
120
+ console.log( "Writing config to : "+args.config )
121
+ try{ await pfs.mkdir( path.dirname(args.config) ) }catch(e){}
122
+ fs.writeFileSync( args.config , weerss.config_default )
107
123
  }
108
- return
109
124
  }
110
-
111
- console.log( djon.save(weerss.config,"djon","strict") )
125
+ else
126
+ {
127
+ console.log( "Must specify config file with --config=~/.weerss.config " )
128
+ }
112
129
  }
113
130
 
114
131
  weerss.get_config_path=function(name)
@@ -123,8 +140,8 @@ weerss.get_config_path=function(name)
123
140
  d=path.resolve( "." )
124
141
  }
125
142
 
126
- let f=weerss.config[name] || "."
127
- if( ! f.startsWith("/" ) )
143
+ let f=weerss.config.paths[name] || "."
144
+ if( ! path.isAbsolute(f) )
128
145
  {
129
146
  f=path.join( d , f )
130
147
  }
@@ -313,7 +330,7 @@ weerss.list=async function(args)
313
330
  {
314
331
  await db.setup()
315
332
 
316
- let list=(await weerss.getlist())
333
+ let list=(await weerss.getlist()).slice(0,weerss.config.rss.length)
317
334
  for(let item of list)
318
335
  {
319
336
  console.log( item_to_string(item))
@@ -367,16 +384,16 @@ weerss.save_rss=async function(args)
367
384
  rss_items.push(it)
368
385
  }
369
386
 
370
- let list=(await weerss.getlist(weerss.config.show.rules)).slice(0,100)
387
+ let list=(await weerss.getlist(weerss.config.show.rules)).slice(0,weerss.config.rss.length)
371
388
  for(let item of list)
372
389
  {
373
390
  push_item(item)
374
391
  }
375
392
 
376
393
 
377
- if( args._[1] )
394
+ let fname=weerss.get_config_path("rss")
395
+ if( fname )
378
396
  {
379
- let fname=args._[1]
380
397
  console.log(` Saving rss to `+fname)
381
398
 
382
399
  fs.writeFileSync( fname , jxml.build_xml(dat) )
@@ -393,8 +410,8 @@ weerss.save_rss=async function(args)
393
410
  weerss.move=async function(args)
394
411
  {
395
412
 
396
- let from=weerss.get_config_path("download_dirname") //args._[2] // optional dest dir
397
- let dest=weerss.get_config_path("tv_dirname") //args._[2] // optional dest dir
413
+ let from=weerss.get_config_path("download") //args._[2] // optional dest dir
414
+ let dest=weerss.get_config_path("tv") //args._[2] // optional dest dir
398
415
 
399
416
  dest=null // do not move
400
417
 
@@ -483,7 +500,7 @@ weerss.move=async function(args)
483
500
 
484
501
  weerss.dirs=async function(args)
485
502
  {
486
- let dest=weerss.get_config_path("tv_dirname")
503
+ let dest=weerss.get_config_path("tv")
487
504
 
488
505
 
489
506
  await db.setup()