proxitok/app/Helpers/RSS.php

35 lines
1.3 KiB
PHP
Raw Normal View History

2022-01-28 09:54:09 -05:00
<?php
2022-01-30 18:02:52 -05:00
namespace App\Helpers;
2022-01-28 09:54:09 -05:00
2022-01-30 18:42:20 -05:00
use \FeedWriter\RSS2;
2022-02-13 17:40:56 -05:00
use TikScraper\Download;
2022-01-28 09:54:09 -05:00
class RSS {
2022-01-30 18:42:20 -05:00
static public function build(string $endpoint, string $title, string $description, array $items): string {
2022-01-28 09:54:09 -05:00
$url = Misc::env('APP_URL', '');
$download = new Download();
2022-01-30 18:42:20 -05:00
$rss = new RSS2();
$rss->setTitle($title);
$rss->setDescription($description);
$rss->setLink($url . $endpoint);
$rss->setSelfLink($url . $endpoint . '/rss');
2022-01-28 09:54:09 -05:00
foreach ($items as $item) {
2022-01-30 18:42:20 -05:00
$item_rss = $rss->createNewItem();
2022-01-28 09:54:09 -05:00
$video = $item->video->playAddr;
2022-01-30 18:42:20 -05:00
$item_rss->setTitle($item->desc);
$item_rss->setDescription($item->desc);
$item_rss->setLink($url . '/video/' . $item->id);
$item_rss->setDate((int) $item->createTime);
$item_rss->setId($item->id, false);
$item_rss->addEnclosure($url . '/stream?url=' . urlencode($video), $download->file_size($video), 'video/mp4');
$rss->addItem($item_rss);
2022-01-28 09:54:09 -05:00
}
2022-01-30 18:42:20 -05:00
return $rss->generateFeed();
2022-01-28 09:54:09 -05:00
}
static public function setHeaders (string $filename) {
header('Content-Type: application/rss+xml');
header('Content-Disposition: attachment; filename="' . $filename . '"');
}
}