Using new RSS wrapper

This commit is contained in:
Pablo Ferreiro 2022-01-31 00:42:20 +01:00
parent 837f126021
commit df052dab36
No known key found for this signature in database
GPG key ID: 41FBCE65B779FA24
4 changed files with 124 additions and 79 deletions

View file

@ -58,8 +58,8 @@ location /proxitok/.env {
* Make video on /video fit screen and don't overflow * Make video on /video fit screen and don't overflow
## Credits ## Credits
* [TikTok-API-PHP](https://github.com/ssovit/TikTok-API-PHP) * [TikTok-API-PHP](https://github.com/ssovit/TikTok-API-PHP) (Currently using my personal fork)
* [bramus/router](https://github.com/bramus/router) * [bramus/router](https://github.com/bramus/router)
* [PHP dotenv](https://github.com/vlucas/phpdotenv) * [PHP dotenv](https://github.com/vlucas/phpdotenv)
* [Bulma](https://github.com/jgthms/bulma) * [Bulma](https://github.com/jgthms/bulma) and [Bulmaswatch](https://github.com/jenil/bulmaswatch)
* [Bulmaswatch](https://github.com/jenil/bulmaswatch) * [FeedWriter](https://github.com/mibe/FeedWriter)

View file

@ -1,36 +1,30 @@
<?php <?php
namespace App\Helpers; namespace App\Helpers;
use \Bhaktaraz\RSSGenerator\Feed; use \FeedWriter\RSS2;
use \Bhaktaraz\RSSGenerator\Channel;
use \Bhaktaraz\RSSGenerator\Item;
use \Sovit\TikTok\Download; use \Sovit\TikTok\Download;
class RSS { class RSS {
static public function build (string $endpoint, string $title, string $description, array $items): Feed { static public function build(string $endpoint, string $title, string $description, array $items): string {
$url = Misc::env('APP_URL', ''); $url = Misc::env('APP_URL', '');
$download = new Download(); $download = new Download();
$rss_feed = new Feed(); $rss = new RSS2();
$rss_channel = new Channel(); $rss->setTitle($title);
$rss_channel $rss->setDescription($description);
->title($title) $rss->setLink($url . $endpoint);
->description($description) $rss->setSelfLink($url . $endpoint . '/rss');
->url($url . $endpoint)
->atomLinkSelf($url . $endpoint . '/rss')
->appendTo($rss_feed);
foreach ($items as $item) { foreach ($items as $item) {
$rss_item = new Item(); $item_rss = $rss->createNewItem();
$video = $item->video->playAddr; $video = $item->video->playAddr;
$rss_item $item_rss->setTitle($item->desc);
->title($item->desc) $item_rss->setDescription($item->desc);
->description($item->desc) $item_rss->setLink($url . '/video/' . $item->id);
->url($url . '/video/' . $item->id) $item_rss->setDate((int) $item->createTime);
->pubDate((int)$item->createTime) $item_rss->setId($item->id, false);
->guid($item->id, false) $item_rss->addEnclosure($url . '/stream?url=' . urlencode($video), $download->file_size($video), 'video/mp4');
->enclosure($url . '/stream?url=' . urlencode($video), $download->file_size($video), 'video/mp4') $rss->addItem($item_rss);
->appendTo($rss_channel);
} }
return $rss_feed; return $rss->generateFeed();
} }
static public function setHeaders (string $filename) { static public function setHeaders (string $filename) {

View file

@ -1,7 +1,7 @@
{ {
"name": "pablouser1/proxitok", "name": "pablouser1/proxitok",
"description": "An alternative frontend for TikTok", "description": "An alternative frontend for TikTok",
"version": "1.3.1", "version": "1.3.2",
"license": "AGPL-3.0-or-later", "license": "AGPL-3.0-or-later",
"repositories": [ "repositories": [
{ {
@ -15,7 +15,7 @@
"latte/latte": "^2.10", "latte/latte": "^2.10",
"vlucas/phpdotenv": "^5.4", "vlucas/phpdotenv": "^5.4",
"bramus/router": "^1.6", "bramus/router": "^1.6",
"bhaktaraz/php-rss-generator": "dev-master" "mibe/feedwriter": "^1.1"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

155
composer.lock generated
View file

@ -4,57 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "1ecb565500ab6893126d60eeebcd7379", "content-hash": "bf98cf536ad098372082ff5899967548",
"packages": [ "packages": [
{
"name": "bhaktaraz/php-rss-generator",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/bhaktaraz/php-rss-generator.git",
"reference": "53cf11db18d87e65973e6df453fb8c1382e5a3bd"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/bhaktaraz/php-rss-generator/zipball/53cf11db18d87e65973e6df453fb8c1382e5a3bd",
"reference": "53cf11db18d87e65973e6df453fb8c1382e5a3bd",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"default-branch": true,
"type": "library",
"autoload": {
"psr-4": {
"Bhaktaraz\\RSSGenerator\\": "Source/Bhaktaraz/RSSGenerator/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Bhaktaraz Bhatta",
"email": "bhattabhakta@gmail.com"
}
],
"description": "Simple RSS generator library for PHP 5.5 or later.",
"homepage": "https://github.com/bhaktaraz/php-rss-generator",
"keywords": [
"Facebook product feed generator",
"feed",
"generator",
"rss",
"writer"
],
"support": {
"issues": "https://github.com/bhaktaraz/php-rss-generator/issues",
"source": "https://github.com/bhaktaraz/php-rss-generator/tree/master"
},
"time": "2021-03-15T10:59:47+00:00"
},
{ {
"name": "bramus/router", "name": "bramus/router",
"version": "1.6.1", "version": "1.6.1",
@ -252,6 +203,107 @@
}, },
"time": "2022-01-04T14:13:28+00:00" "time": "2022-01-04T14:13:28+00:00"
}, },
{
"name": "mibe/feedwriter",
"version": "v1.1.1",
"source": {
"type": "git",
"url": "https://github.com/mibe/FeedWriter.git",
"reference": "f4cc748ad8700e36663f08cfeebe7fd39b00eea2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mibe/FeedWriter/zipball/f4cc748ad8700e36663f08cfeebe7fd39b00eea2",
"reference": "f4cc748ad8700e36663f08cfeebe7fd39b00eea2",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.1.x-dev"
}
},
"autoload": {
"psr-4": {
"FeedWriter\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"GPL-3.0"
],
"authors": [
{
"name": "Michael Bemmerl",
"email": "mail@mx-server.de"
},
{
"name": "Phil Freo"
},
{
"name": "Paul Ferrett"
},
{
"name": "Brennen Bearnes"
},
{
"name": "Michael Robinson",
"email": "mike@pagesofinterest.net"
},
{
"name": "Baptiste Fontaine"
},
{
"name": "Kristián Valentín"
},
{
"name": "Brandtley McMinn"
},
{
"name": "Julian Bogdani"
},
{
"name": "Anis Uddin Ahmad",
"email": "anis.programmer@gmail.com"
},
{
"name": "Cedric Gampert"
},
{
"name": "Yamek"
},
{
"name": "thielj"
},
{
"name": "Pavel Khakhlou"
},
{
"name": "Daniel"
},
{
"name": "Tino Goratsch"
}
],
"description": "Generate feeds in either RSS 1.0, RSS 2.0 or ATOM formats",
"homepage": "https://github.com/mibe/FeedWriter",
"keywords": [
"RSS 1.0",
"atom",
"feed",
"rss",
"rss 2.0",
"rss2"
],
"support": {
"issues": "https://github.com/mibe/FeedWriter/issues",
"source": "https://github.com/mibe/FeedWriter/tree/master"
},
"time": "2016-11-19T20:47:44+00:00"
},
{ {
"name": "phpoption/phpoption", "name": "phpoption/phpoption",
"version": "1.8.1", "version": "1.8.1",
@ -708,8 +760,7 @@
"aliases": [], "aliases": [],
"minimum-stability": "stable", "minimum-stability": "stable",
"stability-flags": { "stability-flags": {
"ssovit/tiktok-api": 20, "ssovit/tiktok-api": 20
"bhaktaraz/php-rss-generator": 20
}, },
"prefer-stable": false, "prefer-stable": false,
"prefer-lowest": false, "prefer-lowest": false,