@xriss/weerss 0.0.10 → 0.0.12

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 (3) hide show
  1. package/package.json +1 -1
  2. package/shows.js +40 -3
  3. package/weerss.js +22 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xriss/weerss",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "source": "weerss.js",
5
5
  "type": "module",
6
6
  "repository": {
package/shows.js CHANGED
@@ -16,6 +16,7 @@ import weerss from "./weerss.js"
16
16
  // cleanup a file name as best we can to be used in search
17
17
  shows.clean_name=function(name)
18
18
  {
19
+ name=name.replace(/\s*\[.*?\]\s*/g, ' ') // remove any [tags]
19
20
  return name.replace(/'|’/g,"").replace(/[^a-zA-Z0-9]/g," ").replace(/\s+/g," ").trim().toLowerCase()
20
21
  }
21
22
 
@@ -40,6 +41,7 @@ shows.fetch=async function(url,force)
40
41
  }
41
42
 
42
43
  let data = await fetch(url).then(res => res.json())
44
+ data=data && data[0] && data[0].show // get first item from array returned from search
43
45
  if(data)
44
46
  {
45
47
  await shows.set({url:url,data:data})
@@ -54,15 +56,34 @@ shows.prepare=function(show)
54
56
  }
55
57
 
56
58
 
59
+ // lookup show episode on tvmaze, this needs a valid tvmaze id
60
+ shows.get_tvmaze_episode=async function(showid,season,episode)
61
+ {
62
+ await new Promise(resolve => setTimeout(resolve, 500)) // do not spam requests
63
+
64
+ let ret=null
65
+
66
+ try{ // on network errors, just return nil
67
+
68
+ let qurl="https://api.tvmaze.com/shows/"+showid+"/episodebynumber?season="+season+"&number="+episode
69
+ let text=await hoard.fetch_text(qurl)
70
+ ret=JSON.parse(text)
71
+ }catch(e){console.log(e)}
72
+
73
+ return ret
74
+ }
75
+
57
76
  // lookup show on tvmaze
58
77
  shows.get_tvmaze=async function(show,force)
59
78
  {
79
+
60
80
  try{ // on network errors, just return non tvmaze info
61
81
 
62
82
  let show_year
63
83
  let show_country
64
84
  let show_name=show.name
65
- let qurl="https://api.tvmaze.com/singlesearch/shows?q="+show_name.replaceAll(" ","+")
85
+ let qurl="https://api.tvmaze.com/search/shows?q="+show_name.replaceAll(" ","+")
86
+ await new Promise(resolve => setTimeout(resolve, 500)) // do not spam requests
66
87
  let tvmaze=await shows.fetch(qurl,force)
67
88
 
68
89
  if(!tvmaze) // maybe try again
@@ -71,7 +92,8 @@ shows.get_tvmaze=async function(show,force)
71
92
  {
72
93
  show_year=show_name.substring(show_name.length-4)
73
94
  show_name=show_name.substring(0,show_name.length-5)
74
- qurl="https://api.tvmaze.com/singlesearch/shows?q="+show_name.replaceAll(" ","+")
95
+ qurl="https://api.tvmaze.com/search/shows?q="+show_name.replaceAll(" ","+")
96
+ await new Promise(resolve => setTimeout(resolve, 500)) // do not spam requests
75
97
  tvmaze=await shows.fetch(qurl,force)
76
98
  if(tvmaze)
77
99
  {
@@ -86,7 +108,8 @@ shows.get_tvmaze=async function(show,force)
86
108
  {
87
109
  show_country=show_name.substring(show_name.length-2)
88
110
  show_name=show_name.substring(0,show_name.length-3)
89
- qurl="https://api.tvmaze.com/singlesearch/shows?q="+show_name.replaceAll(" ","+")
111
+ qurl="https://api.tvmaze.com/search/shows?q="+show_name.replaceAll(" ","+")
112
+ await new Promise(resolve => setTimeout(resolve, 500)) // do not spam requests
90
113
  tvmaze=await shows.fetch(qurl,force)
91
114
  if(tvmaze)
92
115
  {
@@ -115,6 +138,7 @@ shows.get_show=async function(filename)
115
138
  let item_name
116
139
  let item_season
117
140
  let item_episode
141
+ let item_date
118
142
 
119
143
  let name=filename
120
144
  if(!name){return} // give up
@@ -141,6 +165,7 @@ shows.get_show=async function(filename)
141
165
  item_season=Number(aa[2]) // season is the year
142
166
  item_episode=Number(aa[3]+aa[4]) // join month and day to make a 4 digit episode number
143
167
  item_tags=aa[5].replace(/[^a-zA-Z0-9]/g," ").replace(/\s+/g," ").trim().toLowerCase().split(" ")
168
+ item_date=aa[2]+"-"+aa[3]+"-"+aa[4]
144
169
  }
145
170
  }
146
171
 
@@ -151,6 +176,7 @@ shows.get_show=async function(filename)
151
176
  tags:item_tags,
152
177
  season:item_season,
153
178
  episode:item_episode,
179
+ date:item_date,
154
180
  }
155
181
 
156
182
  await shows.get_tvmaze(show)
@@ -163,6 +189,17 @@ shows.fill_show=async function(item)
163
189
  {
164
190
 
165
191
  item.show=await shows.get_show(item.torrent.file_name)
192
+ if( (item.show) && (item.show.tvmaze) )
193
+ {
194
+ if( !item.show.date ) // need a date so ask tvmaze
195
+ {
196
+ item.tvmaze_episode=await shows.get_tvmaze_episode( item.show.id , item.show.season , item.show.episode )
197
+ if( item.tvmaze_episode )
198
+ {
199
+ item.show.date=item.tvmaze_episode.airdate
200
+ }
201
+ }
202
+ }
166
203
 
167
204
  item.show=item.show||{fail:true}
168
205
 
package/weerss.js CHANGED
@@ -159,7 +159,8 @@ let item_to_string=function(item)
159
159
  let tvmaze=show.tvmaze || {}
160
160
  let siz=Math.floor((torrent.file_length||0)/(1024*1024)).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")+".MB"
161
161
  let SxxExx=("S"+(show.season||0).toString().padStart(2, "0")+"E"+(show.episode||0).toString().padStart(2, "0") )
162
- return ( siz.padStart(9, " ")+" "+(tvmaze.name||torrent.file_name||item.uuid)+" "+SxxExx)
162
+ let airdate=show.date || ""
163
+ return ( siz.padStart(9, " ")+" "+(tvmaze.name||torrent.file_name||item.uuid)+" "+SxxExx+" "+airdate)
163
164
  }
164
165
 
165
166
  weerss.fetch=async function()
@@ -268,6 +269,26 @@ weerss.getlist=async function()
268
269
  {
269
270
  let bucket=buckets[showid][SxxExx]
270
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
+
271
292
  if( weerss.config.episode.best == "small" )
272
293
  {
273
294
  bucket.sort(function(a,b){