1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Blacklight\http; |
4
|
|
|
|
5
|
|
|
use Blacklight\NZB; |
6
|
|
|
use App\Models\Release; |
7
|
|
|
use App\Models\Category; |
8
|
|
|
use Blacklight\Releases; |
9
|
|
|
use App\Models\UserMovie; |
10
|
|
|
use App\Models\UserSerie; |
11
|
|
|
use Illuminate\Support\Facades\DB; |
12
|
|
|
use Illuminate\Support\Facades\Cache; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class RSS -- contains specific functions for RSS. |
16
|
|
|
*/ |
17
|
|
|
class RSS extends Capabilities |
18
|
|
|
{ |
19
|
|
|
/** Releases class |
20
|
|
|
* @var Releases |
21
|
|
|
*/ |
22
|
|
|
public $releases; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param array $options |
26
|
|
|
* |
27
|
|
|
* @throws \Exception |
28
|
|
|
*/ |
29
|
|
|
public function __construct(array $options = []) |
30
|
|
|
{ |
31
|
|
|
parent::__construct($options); |
32
|
|
|
$defaults = [ |
33
|
|
|
'Settings' => null, |
34
|
|
|
'Releases' => null, |
35
|
|
|
]; |
36
|
|
|
$options += $defaults; |
37
|
|
|
|
38
|
|
|
$this->releases = ($options['Releases'] instanceof Releases ? $options['Releases'] : new Releases()); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Get releases for RSS. |
43
|
|
|
* |
44
|
|
|
* |
45
|
|
|
* @param $cat |
46
|
|
|
* @param int $offset |
47
|
|
|
* @param $videosId |
48
|
|
|
* @param $aniDbID |
49
|
|
|
* @param int $userID |
50
|
|
|
* @param int $airDate |
51
|
|
|
* |
52
|
|
|
* @param int $limit |
53
|
|
|
* |
54
|
|
|
* @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Query\Builder[]|\Illuminate\Support\Collection|mixed |
55
|
|
|
*/ |
56
|
|
|
public function getRss($cat, $videosId, $aniDbID, $userID = 0, $airDate = -1, int $limit = 100, int $offset = 0) |
57
|
|
|
{ |
58
|
|
|
$catSearch = $cartSearch = ''; |
59
|
|
|
$catLimit = 'AND r.categories_id BETWEEN '.Category::TV_ROOT.' AND '.Category::TV_OTHER; |
60
|
|
|
if (\count($cat)) { |
61
|
|
|
if ((int) $cat[0] === -2) { |
62
|
|
|
$cartSearch = sprintf( |
63
|
|
|
'INNER JOIN users_releases ON users_releases.users_id = %d AND users_releases.releases_id = r.id', |
64
|
|
|
$userID |
65
|
|
|
); |
66
|
|
|
} elseif ((int) $cat[0] !== -1) { |
67
|
|
|
$catSearch = Category::getCategorySearch($cat); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
$sql = |
71
|
|
|
sprintf( |
72
|
|
|
"SELECT r.searchname, r.guid, r.postdate, r.categories_id, r.size, r.totalpart, r.fromname, r.passwordstatus, r.grabs, r.comments, r.adddate, r.videos_id, r.tv_episodes_id, |
73
|
|
|
m.cover, m.imdbid, m.rating, m.plot, m.year, m.genre, m.director, m.actors, |
74
|
|
|
g.name AS group_name, |
75
|
|
|
CONCAT(cp.title, ' > ', c.title) AS category_name, |
76
|
|
|
COALESCE(cp.id,0) AS parentid, |
77
|
|
|
mu.title AS mu_title, mu.url AS mu_url, mu.artist AS mu_artist, |
78
|
|
|
mu.publisher AS mu_publisher, mu.releasedate AS mu_releasedate, |
79
|
|
|
mu.review AS mu_review, mu.tracks AS mu_tracks, mu.cover AS mu_cover, |
80
|
|
|
mug.title AS mu_genre, co.title AS co_title, co.url AS co_url, |
81
|
|
|
co.publisher AS co_publisher, co.releasedate AS co_releasedate, |
82
|
|
|
co.review AS co_review, co.cover AS co_cover, cog.title AS co_genre, |
83
|
|
|
bo.cover AS bo_cover |
84
|
|
|
FROM releases r |
85
|
|
|
LEFT JOIN categories c ON c.id = r.categories_id |
86
|
|
|
INNER JOIN root_categories cp ON cp.id = c.root_categories_id |
87
|
|
|
LEFT JOIN usenet_groups g ON g.id = r.groups_id |
88
|
|
|
LEFT OUTER JOIN musicinfo mu ON mu.id = r.musicinfo_id |
89
|
|
|
LEFT OUTER JOIN genres mug ON mug.id = mu.genres_id |
90
|
|
|
LEFT OUTER JOIN consoleinfo co ON co.id = r.consoleinfo_id |
91
|
|
|
LEFT JOIN movieinfo m ON m.id = r.movieinfo_id |
92
|
|
|
LEFT OUTER JOIN genres cog ON cog.id = co.genres_id %s |
93
|
|
|
LEFT OUTER JOIN tv_episodes tve ON tve.id = r.tv_episodes_id |
94
|
|
|
LEFT OUTER JOIN bookinfo bo ON bo.id = r.bookinfo_id |
95
|
|
|
WHERE r.passwordstatus %s |
96
|
|
|
AND r.nzbstatus = %d |
97
|
|
|
%s %s %s %s |
98
|
|
|
ORDER BY postdate DESC %s", |
99
|
|
|
$cartSearch, |
100
|
|
|
$this->releases->showPasswords(), |
101
|
|
|
NZB::NZB_ADDED, |
102
|
|
|
$catSearch, |
103
|
|
|
($videosId > 0 ? sprintf('AND r.videos_id = %d %s', $videosId, ($catSearch === '' ? $catLimit : '')) : ''), |
104
|
|
|
($aniDbID > 0 ? sprintf('AND r.anidbid = %d %s', $aniDbID, ($catSearch === '' ? $catLimit : '')) : ''), |
105
|
|
|
($airDate > -1 ? sprintf('AND tve.firstaired >= DATE_SUB(CURDATE(), INTERVAL %d DAY)', $airDate) : ''), |
106
|
|
|
$limit === -1 ? '' : ' LIMIT '.$limit.' OFFSET '.$offset |
107
|
|
|
); |
108
|
|
|
|
109
|
|
|
$expiresAt = now()->addMinutes(config('nntmux.cache_expiry_medium')); |
110
|
|
|
$result = Cache::get(md5($sql)); |
111
|
|
|
if ($result !== null) { |
112
|
|
|
return $result; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
$result = Release::fromQuery($sql); |
116
|
|
|
Cache::put(md5($sql), $result, $expiresAt); |
117
|
|
|
|
118
|
|
|
return $result; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @param int $limit |
123
|
|
|
* @param int $userID |
124
|
|
|
* @param array $excludedCats |
125
|
|
|
* @param int $airDate |
126
|
|
|
* |
127
|
|
|
* @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection |
128
|
|
|
* @throws \Exception |
129
|
|
|
*/ |
130
|
|
|
public function getShowsRss($limit, $userID = 0, array $excludedCats = [], $airDate = -1) |
131
|
|
|
{ |
132
|
|
|
$sql = sprintf( |
133
|
|
|
" |
134
|
|
|
SELECT r.searchname, r.guid, r.postdate, r.categories_id, r.size, r.totalpart, r.fromname, r.passwordstatus, r.grabs, r.comments, r.adddate, r.videos_id, r.tv_episodes_id, v.id, v.title, g.name AS group_name, |
135
|
|
|
CONCAT(cp.title, '-', c.title) AS category_name, |
136
|
|
|
COALESCE(cp.id,0) AS parentid |
137
|
|
|
FROM releases r |
138
|
|
|
LEFT JOIN categories c ON c.id = r.categories_id |
139
|
|
|
INNER JOIN root_categories cp ON cp.id = c.root_categories_id |
140
|
|
|
LEFT JOIN usenet_groups g ON g.id = r.groups_id |
141
|
|
|
LEFT OUTER JOIN videos v ON v.id = r.videos_id |
142
|
|
|
LEFT OUTER JOIN tv_episodes tve ON tve.id = r.tv_episodes_id |
143
|
|
|
WHERE %s %s %s |
144
|
|
|
AND r.nzbstatus = %d |
145
|
|
|
AND r.categories_id BETWEEN %d AND %d |
146
|
|
|
AND r.passwordstatus %s |
147
|
|
|
ORDER BY postdate DESC %s", |
148
|
|
|
$this->releases->uSQL( |
149
|
|
|
UserSerie::fromQuery( |
150
|
|
|
sprintf( |
151
|
|
|
' |
152
|
|
|
SELECT videos_id, categories |
153
|
|
|
FROM user_series |
154
|
|
|
WHERE users_id = %d', |
155
|
|
|
$userID |
156
|
|
|
) |
157
|
|
|
), |
158
|
|
|
'videos_id' |
159
|
|
|
), |
160
|
|
|
(\count($excludedCats) ? 'AND r.categories_id NOT IN ('.implode(',', $excludedCats).')' : ''), |
161
|
|
|
($airDate > -1 ? sprintf('AND tve.firstaired >= DATE_SUB(CURDATE(), INTERVAL %d DAY) ', $airDate) : ''), |
162
|
|
|
NZB::NZB_ADDED, |
163
|
|
|
Category::TV_ROOT, |
164
|
|
|
Category::TV_OTHER, |
165
|
|
|
$this->releases->showPasswords(), |
166
|
|
|
! empty($limit) ? sprintf(' LIMIT %d OFFSET 0', $limit > 100 ? 100 : $limit) : '' |
167
|
|
|
); |
168
|
|
|
|
169
|
|
|
$expiresAt = now()->addMinutes(config('nntmux.cache_expiry_medium')); |
170
|
|
|
$result = Cache::get(md5($sql)); |
171
|
|
|
if ($result !== null) { |
172
|
|
|
return $result; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
$result = Release::fromQuery($sql); |
176
|
|
|
Cache::put(md5($sql), $result, $expiresAt); |
177
|
|
|
|
178
|
|
|
return $result; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Get movies for RSS. |
183
|
|
|
* |
184
|
|
|
* |
185
|
|
|
* @param int $limit |
186
|
|
|
* @param int $userID |
187
|
|
|
* @param array $excludedCats |
188
|
|
|
* |
189
|
|
|
* @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection|mixed |
190
|
|
|
* @throws \Exception |
191
|
|
|
*/ |
192
|
|
|
public function getMyMoviesRss($limit, $userID = 0, array $excludedCats = []) |
193
|
|
|
{ |
194
|
|
|
$sql = sprintf( |
195
|
|
|
" |
196
|
|
|
SELECT r.searchname, r.guid, r.postdate, r.categories_id, r.size, r.totalpart, r.fromname, r.passwordstatus, r.grabs, r.comments, r.adddate, r.videos_id, r.tv_episodes_id, mi.title AS releasetitle, g.name AS group_name, |
197
|
|
|
CONCAT(cp.title, '-', c.title) AS category_name, |
198
|
|
|
COALESCE(cp.id,0) AS parentid |
199
|
|
|
FROM releases r |
200
|
|
|
LEFT JOIN categories c ON c.id = r.categories_id |
201
|
|
|
INNER JOIN root_categories cp ON cp.id = c.root_categories_id |
202
|
|
|
LEFT JOIN usenet_groups g ON g.id = r.groups_id |
203
|
|
|
LEFT JOIN movieinfo mi ON mi.id = r.movieinfo_id |
204
|
|
|
WHERE %s %s |
205
|
|
|
AND r.nzbstatus = %d |
206
|
|
|
AND r.categories_id BETWEEN %d AND %d |
207
|
|
|
AND r.passwordstatus %s |
208
|
|
|
ORDER BY postdate DESC %s", |
209
|
|
|
$this->releases->uSQL( |
210
|
|
|
UserMovie::fromQuery( |
211
|
|
|
sprintf( |
212
|
|
|
' |
213
|
|
|
SELECT imdbid, categories |
214
|
|
|
FROM user_movies |
215
|
|
|
WHERE users_id = %d', |
216
|
|
|
$userID |
217
|
|
|
) |
218
|
|
|
), |
219
|
|
|
'imdbid' |
220
|
|
|
), |
221
|
|
|
(\count($excludedCats) > 0 ? ' AND r.categories_id NOT IN ('.implode(',', $excludedCats).')' : ''), |
222
|
|
|
NZB::NZB_ADDED, |
223
|
|
|
Category::MOVIE_ROOT, |
224
|
|
|
Category::MOVIE_OTHER, |
225
|
|
|
$this->releases->showPasswords(), |
226
|
|
|
! empty($limit) ? sprintf(' LIMIT %d OFFSET 0', $limit > 100 ? 100 : $limit) : '' |
227
|
|
|
); |
228
|
|
|
|
229
|
|
|
$expiresAt = now()->addMinutes(config('nntmux.cache_expiry_medium')); |
230
|
|
|
$result = Cache::get(md5($sql)); |
231
|
|
|
if ($result !== null) { |
232
|
|
|
return $result; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
$result = Release::fromQuery($sql); |
236
|
|
|
|
237
|
|
|
Cache::put(md5($sql), $result, $expiresAt); |
238
|
|
|
|
239
|
|
|
return $result; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* @param $column |
244
|
|
|
* @param $table |
245
|
|
|
* @param $order |
246
|
|
|
* |
247
|
|
|
* @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Query\Builder|null |
248
|
|
|
*/ |
249
|
|
|
public function getFirstInstance($column, $table, $order) |
250
|
|
|
{ |
251
|
|
|
return DB::table($table) |
252
|
|
|
->select([$column]) |
253
|
|
|
->where($column, '>', 0) |
254
|
|
|
->orderBy($order, 'asc') |
255
|
|
|
->first(); |
256
|
|
|
} |
257
|
|
|
} |
258
|
|
|
|