|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Blacklight\ElasticSearchSiteSearch; |
|
6
|
|
|
use Blacklight\ManticoreSearch; |
|
7
|
|
|
use Blacklight\NZB; |
|
8
|
|
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator; |
|
9
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory; |
|
10
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
11
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo; |
|
12
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany; |
|
13
|
|
|
use Illuminate\Database\Eloquent\Relations\HasOne; |
|
14
|
|
|
use Illuminate\Support\Arr; |
|
15
|
|
|
use Illuminate\Support\Facades\Cache; |
|
16
|
|
|
use Illuminate\Support\Facades\DB; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* App\Models\Release. |
|
20
|
|
|
* |
|
21
|
|
|
* @property int $id |
|
22
|
|
|
* @property string $name |
|
23
|
|
|
* @property string $searchname |
|
24
|
|
|
* @property int|null $totalpart |
|
25
|
|
|
* @property int $groups_id FK to groups.id |
|
26
|
|
|
* @property int $size |
|
27
|
|
|
* @property string|null $postdate |
|
28
|
|
|
* @property string|null $adddate |
|
29
|
|
|
* @property string $updatetime |
|
30
|
|
|
* @property string|null $gid |
|
31
|
|
|
* @property string $guid |
|
32
|
|
|
* @property string $leftguid The first letter of the release guid |
|
33
|
|
|
* @property string|null $fromname |
|
34
|
|
|
* @property float $completion |
|
35
|
|
|
* @property int $categories_id |
|
36
|
|
|
* @property int $videos_id FK to videos.id of the parent series. |
|
37
|
|
|
* @property int $tv_episodes_id FK to tv_episodes.id for the episode. |
|
38
|
|
|
* @property int|null $imdbid |
|
39
|
|
|
* @property int $xxxinfo_id |
|
40
|
|
|
* @property int|null $musicinfo_id FK to musicinfo.id |
|
41
|
|
|
* @property int|null $consoleinfo_id FK to consoleinfo.id |
|
42
|
|
|
* @property int $gamesinfo_id |
|
43
|
|
|
* @property int|null $bookinfo_id FK to bookinfo.id |
|
44
|
|
|
* @property int|null $anidbid FK to anidb_titles.anidbid |
|
45
|
|
|
* @property int $predb_id FK to predb.id |
|
46
|
|
|
* @property int $grabs |
|
47
|
|
|
* @property int $comments |
|
48
|
|
|
* @property bool $passwordstatus |
|
49
|
|
|
* @property int $rarinnerfilecount |
|
50
|
|
|
* @property bool $haspreview |
|
51
|
|
|
* @property bool $nfostatus |
|
52
|
|
|
* @property bool $jpgstatus |
|
53
|
|
|
* @property bool $videostatus |
|
54
|
|
|
* @property bool $audiostatus |
|
55
|
|
|
* @property bool $dehashstatus |
|
56
|
|
|
* @property bool $reqidstatus |
|
57
|
|
|
* @property bool $nzbstatus |
|
58
|
|
|
* @property bool $iscategorized |
|
59
|
|
|
* @property bool $isrenamed |
|
60
|
|
|
* @property bool $ishashed |
|
61
|
|
|
* @property bool $proc_pp |
|
62
|
|
|
* @property bool $proc_sorter |
|
63
|
|
|
* @property bool $proc_par2 |
|
64
|
|
|
* @property bool $proc_nfo |
|
65
|
|
|
* @property bool $proc_files |
|
66
|
|
|
* @property bool $proc_uid |
|
67
|
|
|
* @property bool $proc_srr Has the release been srr |
|
68
|
|
|
* processed |
|
69
|
|
|
* @property bool $proc_hash16k Has the release been hash16k |
|
70
|
|
|
* processed |
|
71
|
|
|
* @property mixed|null $nzb_guid |
|
72
|
|
|
* @property-read Category $category |
|
73
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ReleaseComment[] $comment |
|
74
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\UserDownload[] $download |
|
75
|
|
|
* @property-read TvEpisode $episode |
|
76
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\DnzbFailure[] $failed |
|
77
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ReleaseFile[] $file |
|
78
|
|
|
* @property-read UsenetGroup $group |
|
79
|
|
|
* @property-read ReleaseNfo $nfo |
|
80
|
|
|
* @property-read Predb $predb |
|
81
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ReleaseExtraFull[] $releaseExtra |
|
82
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ReleasesGroups[] $releaseGroup |
|
83
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\UsersRelease[] $userRelease |
|
84
|
|
|
* @property-read Video $video |
|
85
|
|
|
* |
|
86
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereAdddate($value) |
|
87
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereAnidbid($value) |
|
88
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereAudiostatus($value) |
|
89
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereBookinfoId($value) |
|
90
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereCategoriesId($value) |
|
91
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereComments($value) |
|
92
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereCompletion($value) |
|
93
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereConsoleinfoId($value) |
|
94
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereDehashstatus($value) |
|
95
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereFromname($value) |
|
96
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereGamesinfoId($value) |
|
97
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereGid($value) |
|
98
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereGrabs($value) |
|
99
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereGroupsId($value) |
|
100
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereGuid($value) |
|
101
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereHaspreview($value) |
|
102
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereId($value) |
|
103
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereImdbid($value) |
|
104
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereIscategorized($value) |
|
105
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereIshashed($value) |
|
106
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereIsrenamed($value) |
|
107
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereJpgstatus($value) |
|
108
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereLeftguid($value) |
|
109
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereMusicinfoId($value) |
|
110
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereName($value) |
|
111
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereNfostatus($value) |
|
112
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereNzbGuid($value) |
|
113
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereNzbstatus($value) |
|
114
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release wherePasswordstatus($value) |
|
115
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release wherePostdate($value) |
|
116
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release wherePredbId($value) |
|
117
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereProcFiles($value) |
|
118
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereProcHash16k($value) |
|
119
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereProcNfo($value) |
|
120
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereProcPar2($value) |
|
121
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereProcPp($value) |
|
122
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereProcSorter($value) |
|
123
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereProcSrr($value) |
|
124
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereProcUid($value) |
|
125
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereRarinnerfilecount($value) |
|
126
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereReqidstatus($value) |
|
127
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereSearchname($value) |
|
128
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereSize($value) |
|
129
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereTotalpart($value) |
|
130
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereTvEpisodesId($value) |
|
131
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereUpdatetime($value) |
|
132
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereVideosId($value) |
|
133
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereVideostatus($value) |
|
134
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereXxxinfoId($value) |
|
135
|
|
|
* |
|
136
|
|
|
* @mixin \Eloquent |
|
137
|
|
|
* |
|
138
|
|
|
* @property int|null $movieinfo_id FK to movieinfo.id |
|
139
|
|
|
* @property int $proc_crc32 Has the release been crc32 processed |
|
140
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection |
|
141
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection |
|
142
|
|
|
* |
|
143
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release newModelQuery() |
|
144
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release newQuery() |
|
145
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release query() |
|
146
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereMovieinfoId($value) |
|
147
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereProcCrc32($value) |
|
148
|
|
|
*/ |
|
149
|
|
|
class Release extends Model |
|
150
|
|
|
{ |
|
151
|
|
|
use HasFactory; |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* @var bool |
|
155
|
|
|
*/ |
|
156
|
|
|
protected $dateFormat = false; |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* @var bool |
|
160
|
|
|
*/ |
|
161
|
|
|
public $timestamps = false; |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* @var array |
|
165
|
|
|
*/ |
|
166
|
|
|
protected $guarded = []; |
|
167
|
|
|
|
|
168
|
|
|
public function group(): BelongsTo |
|
169
|
|
|
{ |
|
170
|
|
|
return $this->belongsTo(UsenetGroup::class, 'groups_id'); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
public function download(): HasMany |
|
174
|
|
|
{ |
|
175
|
|
|
return $this->hasMany(UserDownload::class, 'releases_id'); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
public function userRelease(): HasMany |
|
179
|
|
|
{ |
|
180
|
|
|
return $this->hasMany(UsersRelease::class, 'releases_id'); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
public function file(): HasMany |
|
184
|
|
|
{ |
|
185
|
|
|
return $this->hasMany(ReleaseFile::class, 'releases_id'); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
public function category(): BelongsTo |
|
189
|
|
|
{ |
|
190
|
|
|
return $this->belongsTo(Category::class, 'categories_id'); |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
public function predb(): BelongsTo |
|
194
|
|
|
{ |
|
195
|
|
|
return $this->belongsTo(Predb::class, 'predb_id'); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
public function failed(): HasMany |
|
199
|
|
|
{ |
|
200
|
|
|
return $this->hasMany(DnzbFailure::class, 'release_id'); |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
public function nfo(): HasOne |
|
204
|
|
|
{ |
|
205
|
|
|
return $this->hasOne(ReleaseNfo::class, 'releases_id'); |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
public function comment(): HasMany |
|
209
|
|
|
{ |
|
210
|
|
|
return $this->hasMany(ReleaseComment::class, 'releases_id'); |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
public function releaseGroup(): HasMany |
|
214
|
|
|
{ |
|
215
|
|
|
return $this->hasMany(ReleasesGroups::class, 'releases_id'); |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
public function video(): BelongsTo |
|
219
|
|
|
{ |
|
220
|
|
|
return $this->belongsTo(Video::class, 'videos_id'); |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
public function episode(): BelongsTo |
|
224
|
|
|
{ |
|
225
|
|
|
return $this->belongsTo(TvEpisode::class, 'tv_episodes_id'); |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
/** |
|
229
|
|
|
* Insert a single release returning the ID on success or false on failure. |
|
230
|
|
|
* |
|
231
|
|
|
* @param array $parameters Insert parameters, must be escaped if string. |
|
232
|
|
|
* @return bool|int |
|
233
|
|
|
* |
|
234
|
|
|
* @throws \Exception |
|
235
|
|
|
*/ |
|
236
|
|
|
public static function insertRelease(array $parameters = []) |
|
237
|
|
|
{ |
|
238
|
|
|
$passwordStatus = ((int) Settings::settingValue('..checkpasswordedrar') === 1 ? -1 : 0); |
|
239
|
|
|
$parameters['id'] = self::query() |
|
240
|
|
|
->insertGetId( |
|
241
|
|
|
[ |
|
242
|
|
|
'name' => $parameters['name'], |
|
243
|
|
|
'searchname' => $parameters['searchname'], |
|
244
|
|
|
'totalpart' => $parameters['totalpart'], |
|
245
|
|
|
'groups_id' => $parameters['groups_id'], |
|
246
|
|
|
'adddate' => now(), |
|
247
|
|
|
'guid' => $parameters['guid'], |
|
248
|
|
|
'leftguid' => $parameters['guid'][0], |
|
249
|
|
|
'postdate' => $parameters['postdate'], |
|
250
|
|
|
'fromname' => $parameters['fromname'], |
|
251
|
|
|
'size' => $parameters['size'], |
|
252
|
|
|
'passwordstatus' => $passwordStatus, |
|
253
|
|
|
'haspreview' => -1, |
|
254
|
|
|
'categories_id' => $parameters['categories_id'], |
|
255
|
|
|
'nfostatus' => -1, |
|
256
|
|
|
'nzbstatus' => $parameters['nzbstatus'], |
|
257
|
|
|
'isrenamed' => $parameters['isrenamed'], |
|
258
|
|
|
'iscategorized' => 1, |
|
259
|
|
|
'predb_id' => $parameters['predb_id'], |
|
260
|
|
|
] |
|
261
|
|
|
); |
|
262
|
|
|
|
|
263
|
|
|
if (config('nntmux.elasticsearch_enabled') === true) { |
|
264
|
|
|
(new ElasticSearchSiteSearch)->insertRelease($parameters); |
|
265
|
|
|
} else { |
|
266
|
|
|
(new ManticoreSearch)->insertRelease($parameters); |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
return $parameters['id']; |
|
|
|
|
|
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
|
|
/** |
|
273
|
|
|
* @throws \Exception |
|
274
|
|
|
*/ |
|
275
|
|
|
public static function updateRelease($id, $name, $searchName, $fromName, $categoryId, $parts, $grabs, $size, $postedDate, $addedDate, $videoId, $episodeId, $imDbId, $aniDbId): void |
|
276
|
|
|
{ |
|
277
|
|
|
$movieInfoId = null; |
|
278
|
|
|
if (! empty($imDbId)) { |
|
279
|
|
|
$movieInfoId = MovieInfo::whereImdbid($imDbId)->first(['id']); |
|
280
|
|
|
} |
|
281
|
|
|
self::whereId($id)->update( |
|
282
|
|
|
[ |
|
283
|
|
|
'name' => $name, |
|
284
|
|
|
'searchname' => $searchName, |
|
285
|
|
|
'fromname' => $fromName, |
|
286
|
|
|
'categories_id' => $categoryId, |
|
287
|
|
|
'totalpart' => $parts, |
|
288
|
|
|
'grabs' => $grabs, |
|
289
|
|
|
'size' => $size, |
|
290
|
|
|
'postdate' => $postedDate, |
|
291
|
|
|
'adddate' => $addedDate, |
|
292
|
|
|
'videos_id' => $videoId, |
|
293
|
|
|
'tv_episodes_id' => $episodeId, |
|
294
|
|
|
'imdbid' => $imDbId, |
|
295
|
|
|
'anidbid' => $aniDbId, |
|
296
|
|
|
'movieinfo_id' => $movieInfoId !== null ? $movieInfoId->id : $movieInfoId, |
|
297
|
|
|
] |
|
298
|
|
|
); |
|
299
|
|
|
|
|
300
|
|
|
if (config('nntmux.elasticsearch_enabled') === true) { |
|
301
|
|
|
(new ElasticSearchSiteSearch)->updateRelease($id); |
|
302
|
|
|
} else { |
|
303
|
|
|
(new ManticoreSearch)->updateRelease($id); |
|
304
|
|
|
} |
|
305
|
|
|
} |
|
306
|
|
|
|
|
307
|
|
|
/** |
|
308
|
|
|
* @throws \Exception |
|
309
|
|
|
*/ |
|
310
|
|
|
public static function updateGrab(string $guid): void |
|
311
|
|
|
{ |
|
312
|
|
|
$updateGrabs = ((int) Settings::settingValue('..grabstatus') !== 0); |
|
313
|
|
|
if ($updateGrabs) { |
|
314
|
|
|
self::whereGuid($guid)->increment('grabs'); |
|
315
|
|
|
} |
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
|
|
/** |
|
319
|
|
|
* @return Model|null|static |
|
320
|
|
|
*/ |
|
321
|
|
|
public static function getCatByRelId($id) |
|
322
|
|
|
{ |
|
323
|
|
|
return self::whereId($id)->first(['categories_id']); |
|
324
|
|
|
} |
|
325
|
|
|
|
|
326
|
|
|
public static function removeVideoIdFromReleases($videoId): int |
|
327
|
|
|
{ |
|
328
|
|
|
return self::whereVideosId($videoId)->update(['videos_id' => 0, 'tv_episodes_id' => 0]); |
|
329
|
|
|
} |
|
330
|
|
|
|
|
331
|
|
|
public static function removeAnidbIdFromReleases($anidbID): int |
|
332
|
|
|
{ |
|
333
|
|
|
return self::whereAnidbid($anidbID)->update(['anidbid' => -1]); |
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
|
|
/** |
|
337
|
|
|
* @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Query\Builder[]|\Illuminate\Support\Collection|mixed |
|
338
|
|
|
*/ |
|
339
|
|
|
public static function getReleases() |
|
340
|
|
|
{ |
|
341
|
|
|
$expiresAt = now()->addMinutes(config('nntmux.cache_expiry_long')); |
|
342
|
|
|
$releases = Cache::get(md5('releases')); |
|
343
|
|
|
if ($releases !== null) { |
|
344
|
|
|
return $releases; |
|
345
|
|
|
} |
|
346
|
|
|
|
|
347
|
|
|
$releases = self::query() |
|
348
|
|
|
|
|
349
|
|
|
->where('nzbstatus', '=', NZB::NZB_ADDED) |
|
350
|
|
|
->select(['releases.*', 'g.name as group_name', 'c.title as category_name']) |
|
351
|
|
|
->leftJoin('categories as c', 'c.id', '=', 'releases.categories_id') |
|
352
|
|
|
->leftJoin('usenet_groups as g', 'g.id', '=', 'releases.groups_id') |
|
353
|
|
|
->get(); |
|
354
|
|
|
|
|
355
|
|
|
Cache::put(md5('releases'), $releases, $expiresAt); |
|
356
|
|
|
|
|
357
|
|
|
return $releases; |
|
358
|
|
|
} |
|
359
|
|
|
|
|
360
|
|
|
/** |
|
361
|
|
|
* Used for admin page release-list. |
|
362
|
|
|
* |
|
363
|
|
|
* |
|
364
|
|
|
* @return LengthAwarePaginator|mixed |
|
365
|
|
|
*/ |
|
366
|
|
|
public static function getReleasesRange() |
|
367
|
|
|
{ |
|
368
|
|
|
$expiresAt = now()->addMinutes(config('nntmux.cache_expiry_long')); |
|
369
|
|
|
$releases = Cache::get(md5('releasesRange')); |
|
370
|
|
|
if ($releases !== null) { |
|
371
|
|
|
return $releases; |
|
372
|
|
|
} |
|
373
|
|
|
|
|
374
|
|
|
$releases = self::query() |
|
375
|
|
|
->where('nzbstatus', '=', NZB::NZB_ADDED) |
|
376
|
|
|
->select( |
|
377
|
|
|
[ |
|
378
|
|
|
'releases.id', |
|
379
|
|
|
'releases.name', |
|
380
|
|
|
'releases.searchname', |
|
381
|
|
|
'releases.size', |
|
382
|
|
|
'releases.guid', |
|
383
|
|
|
'releases.totalpart', |
|
384
|
|
|
'releases.postdate', |
|
385
|
|
|
'releases.adddate', |
|
386
|
|
|
'releases.grabs', |
|
387
|
|
|
'cp.title as parent_category', |
|
388
|
|
|
'c.title as sub_category', |
|
389
|
|
|
DB::raw('CONCAT(cp.title, ' > ', c.title) AS category_name'), |
|
390
|
|
|
] |
|
391
|
|
|
) |
|
392
|
|
|
->leftJoin('categories as c', 'c.id', '=', 'releases.categories_id') |
|
393
|
|
|
->leftJoin('root_categories as cp', 'cp.id', '=', 'c.root_categories_id') |
|
394
|
|
|
->orderByDesc('releases.postdate') |
|
|
|
|
|
|
395
|
|
|
->paginate(config('nntmux.items_per_page')); |
|
396
|
|
|
|
|
397
|
|
|
Cache::put(md5('releasesRange'), $releases, $expiresAt); |
|
398
|
|
|
|
|
399
|
|
|
return $releases; |
|
400
|
|
|
} |
|
401
|
|
|
|
|
402
|
|
|
/** |
|
403
|
|
|
* @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|\Illuminate\Support\Collection|null|static|static[] |
|
404
|
|
|
*/ |
|
405
|
|
|
public static function getByGuid($guid) |
|
406
|
|
|
{ |
|
407
|
|
|
$sql = self::query()->select( |
|
408
|
|
|
[ |
|
409
|
|
|
'releases.*', |
|
410
|
|
|
'g.name as group_name', |
|
411
|
|
|
'v.title as showtitle', |
|
412
|
|
|
'v.tvdb', |
|
413
|
|
|
'v.trakt', |
|
414
|
|
|
'v.tvrage', |
|
415
|
|
|
'v.tvmaze', |
|
416
|
|
|
'v.source', |
|
417
|
|
|
'tvi.summary', |
|
418
|
|
|
'tvi.image', |
|
419
|
|
|
'tve.title', |
|
420
|
|
|
'tve.firstaired', |
|
421
|
|
|
'tve.se_complete', |
|
422
|
|
|
'cp.title as parent_category', |
|
423
|
|
|
'c.title as sub_category', |
|
424
|
|
|
DB::raw("CONCAT(cp.title, ' > ', c.title) AS category_name, CONCAT(cp.id, ',', c.id) AS category_ids,GROUP_CONCAT(g2.name ORDER BY g2.name ASC SEPARATOR ',') AS group_names"), |
|
425
|
|
|
] |
|
426
|
|
|
) |
|
427
|
|
|
->leftJoin('usenet_groups as g', 'g.id', '=', 'releases.groups_id') |
|
428
|
|
|
->leftJoin('categories as c', 'c.id', '=', 'releases.categories_id') |
|
429
|
|
|
->leftJoin('root_categories as cp', 'cp.id', '=', 'c.root_categories_id') |
|
430
|
|
|
->leftJoin('videos as v', 'v.id', '=', 'releases.videos_id') |
|
431
|
|
|
->leftJoin('tv_info as tvi', 'tvi.videos_id', '=', 'releases.videos_id') |
|
432
|
|
|
->leftJoin('tv_episodes as tve', 'tve.id', '=', 'releases.tv_episodes_id') |
|
433
|
|
|
->leftJoin('releases_groups as rg', 'rg.releases_id', '=', 'releases.id') |
|
434
|
|
|
->leftJoin('usenet_groups as g2', 'rg.groups_id', '=', 'g2.id'); |
|
435
|
|
|
|
|
436
|
|
|
if (\is_array($guid)) { |
|
437
|
|
|
$tempGuids = []; |
|
438
|
|
|
foreach ($guid as $identifier) { |
|
439
|
|
|
$tempGuids[] = $identifier; |
|
440
|
|
|
} |
|
441
|
|
|
$sql->whereIn('releases.guid', $tempGuids); |
|
442
|
|
|
} else { |
|
443
|
|
|
$sql->where('releases.guid', $guid); |
|
444
|
|
|
} |
|
445
|
|
|
$sql->groupBy('releases.id'); |
|
446
|
|
|
|
|
447
|
|
|
return \is_array($guid) ? $sql->get() : $sql->first(); |
|
448
|
|
|
} |
|
449
|
|
|
|
|
450
|
|
|
/** |
|
451
|
|
|
* Get a range of releases. used in admin manage list. |
|
452
|
|
|
*/ |
|
453
|
|
|
public static function getFailedRange(): LengthAwarePaginator |
|
454
|
|
|
{ |
|
455
|
|
|
$failedList = self::query() |
|
456
|
|
|
->select(['name', 'searchname', 'size', 'guid', 'totalpart', 'postdate', 'adddate', 'grabs', 'cp.title as parent_category', 'c.title as sub_category', DB::raw("CONCAT(cp.title, ' > ', c.title) AS category_name")]) |
|
457
|
|
|
->rightJoin('dnzb_failures', 'dnzb_failures.release_id', '=', 'releases.id') |
|
458
|
|
|
->leftJoin('categories as c', 'c.id', '=', 'releases.categories_id') |
|
459
|
|
|
->leftJoin('root_categories as cp', 'cp.id', '=', 'c.root_categories_id') |
|
460
|
|
|
->orderByDesc('postdate'); |
|
|
|
|
|
|
461
|
|
|
|
|
462
|
|
|
return $failedList->paginate(config('nntmux.items_per_page')); |
|
463
|
|
|
} |
|
464
|
|
|
|
|
465
|
|
|
/** |
|
466
|
|
|
* @return Release|false|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|\Illuminate\Database\Query\Builder|object|null |
|
467
|
|
|
*/ |
|
468
|
|
|
public static function getAlternate(string $guid, int $userid) |
|
469
|
|
|
{ |
|
470
|
|
|
$rel = self::whereGuid($guid)->first(['id', 'searchname', 'categories_id']); |
|
471
|
|
|
|
|
472
|
|
|
if ($rel === null) { |
|
473
|
|
|
return false; |
|
474
|
|
|
} |
|
475
|
|
|
DnzbFailure::insertOrIgnore(['release_id' => $rel['id'], 'users_id' => $userid, 'failed' => 1]); |
|
476
|
|
|
|
|
477
|
|
|
preg_match('/(^\w+[-_. ].+?\.(\d+p)).+/i', $rel['searchname'], $similar); |
|
478
|
|
|
|
|
479
|
|
|
if (! empty($similar)) { |
|
480
|
|
|
if (config('nntmux.elasticsearch_enabled') === true) { |
|
481
|
|
|
$searchResult = (new ElasticSearchSiteSearch)->indexSearch($similar[1], 10); |
|
482
|
|
|
} else { |
|
483
|
|
|
$searchResult = (new ManticoreSearch)->searchIndexes('releases_rt', $similar[1]); |
|
484
|
|
|
if (! empty($searchResult)) { |
|
485
|
|
|
$searchResult = Arr::wrap(Arr::get($searchResult, 'id')); |
|
486
|
|
|
} |
|
487
|
|
|
} |
|
488
|
|
|
|
|
489
|
|
|
if (empty($searchResult)) { |
|
490
|
|
|
return false; |
|
491
|
|
|
} |
|
492
|
|
|
|
|
493
|
|
|
return self::query()->leftJoin('dnzb_failures as df', 'df.release_id', '=', 'releases.id')->whereIn('releases.id', $searchResult)->where('df.release_id', '=', null)->where('releases.categories_id', $rel['categories_id'])->where('id', '<>', $rel['id'])->orderByDesc('releases.postdate')->first(['guid']); |
|
|
|
|
|
|
494
|
|
|
} |
|
495
|
|
|
|
|
496
|
|
|
return false; |
|
497
|
|
|
} |
|
498
|
|
|
|
|
499
|
|
|
public static function checkGuidForApi($guid): bool |
|
500
|
|
|
{ |
|
501
|
|
|
$check = self::whereGuid($guid)->first(); |
|
502
|
|
|
|
|
503
|
|
|
return $check !== null; |
|
504
|
|
|
} |
|
505
|
|
|
} |
|
506
|
|
|
|