From aa368ea88bc7c7481ba52a1efc4ea1219bd6e932 Mon Sep 17 00:00:00 2001 From: Tyler Starr Date: Mon, 27 Nov 2023 23:53:27 -0800 Subject: [PATCH] package rss-bridge with patches to hack Youtube feeds --- provision/overlays/default.nix | 1 + provision/pkgs/rss-bridge/default.nix | 31 ++++++++ provision/pkgs/rss-bridge/paths.patch | 44 +++++++++++ .../pkgs/rss-bridge/youtube_time_hack.patch | 74 +++++++++++++++++++ 4 files changed, 150 insertions(+) create mode 100644 provision/pkgs/rss-bridge/default.nix create mode 100644 provision/pkgs/rss-bridge/paths.patch create mode 100644 provision/pkgs/rss-bridge/youtube_time_hack.patch diff --git a/provision/overlays/default.nix b/provision/overlays/default.nix index 904db249..b68d15de 100644 --- a/provision/overlays/default.nix +++ b/provision/overlays/default.nix @@ -5,4 +5,5 @@ final: prev: { sway-scratchpad = final.callPackage ../pkgs/sway-scratchpad.nix {}; advcpmv = final.callPackage ../pkgs/advcpmv.nix {}; taskopen = final.callPackage ../pkgs/taskopen.nix {}; + rss-bridge = final.callPackage ../pkgs/rss-bridge {}; } diff --git a/provision/pkgs/rss-bridge/default.nix b/provision/pkgs/rss-bridge/default.nix new file mode 100644 index 00000000..86e71626 --- /dev/null +++ b/provision/pkgs/rss-bridge/default.nix @@ -0,0 +1,31 @@ +{ stdenv, lib, fetchFromGitHub }: + +stdenv.mkDerivation rec { + pname = "rss-bridge"; + version = "b037d1b4d1f0b0f422e21125ddef00a58e185ed1"; + + src = fetchFromGitHub { + owner = "starr-dusT"; + repo = "rss-bridge"; + rev = version; + sha256 = "sha256-zyWnjSYE2NFK/OJLnsFsE5oEyf+yrJe8TT6MH4roBwU="; + }; + + patches = [ + ./paths.patch + ./youtube_time_hack.patch + ]; + + installPhase = '' + mkdir $out/ + cp -R ./* $out + ''; + + meta = with lib; { + description = "The RSS feed for websites missing it"; + homepage = "https://github.com/starr-dusT/rss-bridge"; + license = licenses.unlicense; + maintainers = with maintainers; [ starr-dusT ]; + platforms = platforms.all; + }; +} diff --git a/provision/pkgs/rss-bridge/paths.patch b/provision/pkgs/rss-bridge/paths.patch new file mode 100644 index 00000000..db4a617c --- /dev/null +++ b/provision/pkgs/rss-bridge/paths.patch @@ -0,0 +1,44 @@ +diff --git a/index.php b/index.php +index 123f6ecd..69071aa2 100644 +--- a/index.php ++++ b/index.php +@@ -8,8 +8,8 @@ require_once __DIR__ . '/lib/bootstrap.php'; + + Configuration::verifyInstallation(); + $customConfig = []; +-if (file_exists(__DIR__ . '/config.ini.php')) { +- $customConfig = parse_ini_file(__DIR__ . '/config.ini.php', true, INI_SCANNER_TYPED); ++if (file_exists(getenv('RSSBRIDGE_DATA') . '/config.ini.php')) { ++ $customConfig = parse_ini_file(getenv('RSSBRIDGE_DATA') . '/config.ini.php', true, INI_SCANNER_TYPED); + } + Configuration::loadConfiguration($customConfig, getenv()); + +diff --git a/lib/Configuration.php b/lib/Configuration.php +index d699178f..5431f345 100644 +--- a/lib/Configuration.php ++++ b/lib/Configuration.php +@@ -91,9 +91,8 @@ final class Configuration + self::setConfig('system', 'debug_mode_whitelist', explode("\n", str_replace("\r", '', $debug))); + } + } +- +- if (file_exists(__DIR__ . '/../whitelist.txt')) { +- $enabledBridges = trim(file_get_contents(__DIR__ . '/../whitelist.txt')); ++ if (file_exists(getenv('RSSBRIDGE_DATA') . '/whitelist.txt')) { ++ $enabledBridges = trim(file_get_contents(getenv('RSSBRIDGE_DATA') . '/whitelist.txt')); + if ($enabledBridges === '*') { + self::setConfig('system', 'enabled_bridges', ['*']); + } else { +diff --git a/lib/bootstrap.php b/lib/bootstrap.php +index a95de9dd..78153a65 100644 +--- a/lib/bootstrap.php ++++ b/lib/bootstrap.php +@@ -7,7 +7,7 @@ const PATH_LIB_FORMATS = __DIR__ . '/../formats/'; + const PATH_LIB_CACHES = __DIR__ . '/../caches/'; + + /** Path to the cache folder */ +-const PATH_CACHE = __DIR__ . '/../cache/'; ++define('PATH_CACHE', getenv('RSSBRIDGE_DATA') . '/cache/'); + + /** URL to the RSS-Bridge repository */ + const REPOSITORY = 'https://github.com/RSS-Bridge/rss-bridge/'; diff --git a/provision/pkgs/rss-bridge/youtube_time_hack.patch b/provision/pkgs/rss-bridge/youtube_time_hack.patch new file mode 100644 index 00000000..59fbf12c --- /dev/null +++ b/provision/pkgs/rss-bridge/youtube_time_hack.patch @@ -0,0 +1,74 @@ +diff --git a/bridges/YoutubeBridge.php b/bridges/YoutubeBridge.php +index 993f8c90..b000a9ff 100644 +--- a/bridges/YoutubeBridge.php ++++ b/bridges/YoutubeBridge.php +@@ -134,26 +134,20 @@ class YoutubeBridge extends BridgeAbstract + $url_feed = $jsonData->metadata->channelMetadataRenderer->rssUrl; + $this->feedIconUrl = $jsonData->metadata->channelMetadataRenderer->avatar->thumbnails[0]->url; + } +- if ($filterByDuration) { +- if (!$custom) { +- // Fetch the html page +- $html = $this->fetch($url_listing); +- $jsonData = $this->extractJsonFromHtml($html); +- } +- $channel_id = ''; +- if (isset($jsonData->contents)) { +- $channel_id = $jsonData->metadata->channelMetadataRenderer->externalId; +- $jsonData = $jsonData->contents->twoColumnBrowseResultsRenderer->tabs[1]; +- $jsonData = $jsonData->tabRenderer->content->richGridRenderer->contents; +- // $jsonData = $jsonData->itemSectionRenderer->contents[0]->gridRenderer->items; +- $this->fetchItemsFromFromJsonData($jsonData); +- } else { +- returnServerError('Unable to get data from YouTube'); +- } ++ if (!$custom) { ++ // Fetch the html page ++ $html = $this->fetch($url_listing); ++ $jsonData = $this->extractJsonFromHtml($html); ++ } ++ $channel_id = ''; ++ if (isset($jsonData->contents)) { ++ $channel_id = $jsonData->metadata->channelMetadataRenderer->externalId; ++ $jsonData = $jsonData->contents->twoColumnBrowseResultsRenderer->tabs[1]; ++ $jsonData = $jsonData->tabRenderer->content->richGridRenderer->contents; ++ // $jsonData = $jsonData->itemSectionRenderer->contents[0]->gridRenderer->items; ++ $this->fetchItemsFromFromJsonData($jsonData); + } else { +- // Fetch the xml feed +- $html = $this->fetch($url_feed); +- $this->extractItemsFromXmlFeed($html); ++ returnServerError('Unable to get data from YouTube'); + } + $this->feedName = str_replace(' - YouTube', '', $html->find('title', 0)->plaintext); + } elseif ($playlist) { +@@ -496,24 +490,23 @@ class YoutubeBridge extends BridgeAbstract + continue; + } + } +- if (!$description || !$timestamp) { +- $this->fetchVideoDetails($videoId, $author, $description, $timestamp); +- } +- $this->addItem($videoId, $title, $author, $description, $timestamp); ++ # Re-fetch better details from xml ++ $this->fetchVideoDetails($videoId, $author, $description, $timestamp); ++ $this->addItem($videoId, $title, $author, $description, $timestamp, $durationText); + if (count($this->items) >= 99) { + break; + } + } + } + +- private function addItem($videoId, $title, $author, $description, $timestamp, $thumbnail = '') ++ private function addItem($videoId, $title, $author, $description, $timestamp, $durationText, $thumbnail = '') + { + $description = nl2br($description); + + $item = []; + // This should probably be uid? + $item['id'] = $videoId; +- $item['title'] = $title; ++ $item['title'] = $title . " [" . $durationText . "]"; + $item['author'] = $author ?? ''; + $item['timestamp'] = $timestamp; + $item['uri'] = self::URI . '/watch?v=' . $videoId;