proxitok/app/Helpers/RSS.php

35 lines
1.3 KiB
PHP
Raw Normal View History

2022-01-28 14:54:09 +00:00
<?php
2022-01-30 23:02:52 +00:00
namespace App\Helpers;
2022-01-28 14:54:09 +00:00
2022-01-30 23:42:20 +00:00
use \FeedWriter\RSS2;
2022-03-11 22:37:12 +00:00
use \TikScraper\Download;
2022-01-28 14:54:09 +00:00
class RSS {
2022-01-30 23:42:20 +00:00
static public function build(string $endpoint, string $title, string $description, array $items): string {
2022-01-28 14:54:09 +00:00
$url = Misc::env('APP_URL', '');
$download = new Download();
2022-01-30 23:42:20 +00:00
$rss = new RSS2();
$rss->setTitle($title);
$rss->setDescription($description);
$rss->setLink($url . $endpoint);
$rss->setSelfLink($url . $endpoint . '/rss');
2022-01-28 14:54:09 +00:00
foreach ($items as $item) {
2022-01-30 23:42:20 +00:00
$item_rss = $rss->createNewItem();
2022-01-28 14:54:09 +00:00
$video = $item->video->playAddr;
2022-01-30 23:42:20 +00: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 14:54:09 +00:00
}
2022-01-30 23:42:20 +00:00
return $rss->generateFeed();
2022-01-28 14:54:09 +00:00
}
static public function setHeaders (string $filename) {
header('Content-Type: application/rss+xml');
header('Content-Disposition: attachment; filename="' . $filename . '"');
}
}