@xriss/weerss 0.0.10 → 0.0.11
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/package.json +1 -1
- package/shows.js +34 -0
- package/weerss.js +22 -1
package/package.json
CHANGED
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
|
|
|
@@ -54,9 +55,28 @@ shows.prepare=function(show)
|
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
|
|
58
|
+
// lookup show episode on tvmaze, this needs a valid tvmaze id
|
|
59
|
+
shows.get_tvmaze_episode=async function(showid,season,episode)
|
|
60
|
+
{
|
|
61
|
+
await new Promise(resolve => setTimeout(resolve, 500)) // do not spam requests
|
|
62
|
+
|
|
63
|
+
let ret=null
|
|
64
|
+
|
|
65
|
+
try{ // on network errors, just return nil
|
|
66
|
+
|
|
67
|
+
let qurl="https://api.tvmaze.com/shows/"+showid+"/episodebynumber?season="+season+"&number="+episode
|
|
68
|
+
let text=await hoard.fetch_text(qurl)
|
|
69
|
+
ret=JSON.parse(text)
|
|
70
|
+
}catch(e){console.log(e)}
|
|
71
|
+
|
|
72
|
+
return ret
|
|
73
|
+
}
|
|
74
|
+
|
|
57
75
|
// lookup show on tvmaze
|
|
58
76
|
shows.get_tvmaze=async function(show,force)
|
|
59
77
|
{
|
|
78
|
+
await new Promise(resolve => setTimeout(resolve, 500)) // do not spam requests
|
|
79
|
+
|
|
60
80
|
try{ // on network errors, just return non tvmaze info
|
|
61
81
|
|
|
62
82
|
let show_year
|
|
@@ -115,6 +135,7 @@ shows.get_show=async function(filename)
|
|
|
115
135
|
let item_name
|
|
116
136
|
let item_season
|
|
117
137
|
let item_episode
|
|
138
|
+
let item_date
|
|
118
139
|
|
|
119
140
|
let name=filename
|
|
120
141
|
if(!name){return} // give up
|
|
@@ -141,6 +162,7 @@ shows.get_show=async function(filename)
|
|
|
141
162
|
item_season=Number(aa[2]) // season is the year
|
|
142
163
|
item_episode=Number(aa[3]+aa[4]) // join month and day to make a 4 digit episode number
|
|
143
164
|
item_tags=aa[5].replace(/[^a-zA-Z0-9]/g," ").replace(/\s+/g," ").trim().toLowerCase().split(" ")
|
|
165
|
+
item_date=aa[2]+"-"+aa[3]+"-"+aa[4]
|
|
144
166
|
}
|
|
145
167
|
}
|
|
146
168
|
|
|
@@ -151,6 +173,7 @@ shows.get_show=async function(filename)
|
|
|
151
173
|
tags:item_tags,
|
|
152
174
|
season:item_season,
|
|
153
175
|
episode:item_episode,
|
|
176
|
+
date:item_date,
|
|
154
177
|
}
|
|
155
178
|
|
|
156
179
|
await shows.get_tvmaze(show)
|
|
@@ -163,6 +186,17 @@ shows.fill_show=async function(item)
|
|
|
163
186
|
{
|
|
164
187
|
|
|
165
188
|
item.show=await shows.get_show(item.torrent.file_name)
|
|
189
|
+
if( (item.show) && (item.show.tvmaze) )
|
|
190
|
+
{
|
|
191
|
+
if( !item.show.date ) // need a date so ask tvmaze
|
|
192
|
+
{
|
|
193
|
+
item.tvmaze_episode=await shows.get_tvmaze_episode( item.show.id , item.show.season , item.show.episode )
|
|
194
|
+
if( item.tvmaze_episode )
|
|
195
|
+
{
|
|
196
|
+
item.show.date=item.tvmaze_episode.airdate
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
166
200
|
|
|
167
201
|
item.show=item.show||{fail:true}
|
|
168
202
|
|
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
|
-
|
|
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){
|