Commit 3a87e87b authored by John Long's avatar John Long

Standardize premium calculation, ignore feeds requiring authentication

Ticket: N/A
parent 79f743de
Pipeline #63172690 passed with stages
in 1 minute and 49 seconds
......@@ -33,10 +33,7 @@ class RefreshShow
$response = $this->fetch($query);
$is_premium = $response->feed['premium']->__toString();
$is_requested = (int)$response->feed['id'] == $feed->id;
if ($is_premium && $is_requested) {
if (Feed::isPremium($response->feed)) {
$episodes = $response->episodes->episode;
$seasons = $this->extractSeasons($response->feed->season);
$this->processItems($feed, $episodes, $seasons);
......@@ -70,16 +67,10 @@ class RefreshShow
protected function processFeed(Feed $feed, \SimpleXMLElement $response)
{
if ((int)$response['id'] != $feed->id) {
$is_premium = 0;
} else {
$is_premium = (int)$response['premium']->__toString();
}
$feed->title = (string)$response->name;
$feed->description = (string)$response->description;
$feed->image_url = (string)$response['imageURL'];
$feed->is_premium = $is_premium;
$feed->is_premium = Feed::isPremium($response);
$feed->last_refresh = Carbon::now();
$feed->save();
......
......@@ -42,4 +42,19 @@ class Feed extends Model
{
return $this->hasMany(Item::class);
}
public static function isPremium(
\SimpleXMLElement $element,
?Feed $feed = null
): bool {
if ($feed !== null && (int)$element['id'] != $feed->id) {
$is_premium = false;
} elseif ($element['authRequired'] && $element['authRequired']->__toString()) {
$is_premium = false;
} else {
$is_premium = (bool)$element['premium']->__toString();
}
return $is_premium;
}
}
......@@ -77,7 +77,7 @@ class ShowController extends Controller
$feeds = [];
foreach ($xml->feed as $feed) {
if (!(bool)$feed['premium']->__toString()) {
if (!Feed::isPremium($feed)) {
continue;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment