diff options
Diffstat (limited to 'config/services/web/rss')
| -rw-r--r-- | config/services/web/rss/FipAlbumsBridge.php | 41 | ||||
| -rw-r--r-- | config/services/web/rss/ParisCineInfoBridge.php | 98 | ||||
| -rw-r--r-- | config/services/web/rss/WhatsOnMubiBridge.php | 49 | ||||
| -rw-r--r-- | config/services/web/rss/default.nix | 40 |
4 files changed, 214 insertions, 14 deletions
diff --git a/config/services/web/rss/FipAlbumsBridge.php b/config/services/web/rss/FipAlbumsBridge.php new file mode 100644 index 0000000..b8ec64d --- /dev/null +++ b/config/services/web/rss/FipAlbumsBridge.php @@ -0,0 +1,41 @@ +<?php + +class FipAlbumsBridge extends XPathAbstract { + const NAME = 'Fip Albums Bridge'; + const URI = 'https://www.radiofrance.fr/fip/albums/'; + const DESCRIPTION = 'Albums promoted by Fip.'; + const MAINTAINER = 'Quentin Aristote'; + const CACHE_TIMEOUT = 86400; // 6h + + const PARAMETERS = [ + '' => [ + 'category' => [ + 'name' => 'Category', + 'type' => 'text', + 'description' => 'See examples for available options.', + 'exampleValue' => 'can be empty, "selections" or "album-jazz-de-la-semaine"' + ] + ] + ]; + + const XPATH_EXPRESSION_ITEM = '//div[starts-with(@class, "CardAlbum ")]'; + const XPATH_EXPRESSION_ITEM_TITLE = './/a/@title'; + const XPATH_EXPRESSION_ITEM_CONTENT = './/img/@alt'; + const XPATH_EXPRESSION_ITEM_URI = './/a/@href'; + const XPATH_EXPRESSION_ITEM_AUTHOR = './/div[starts-with(@class, "CardAlbum-details ")]/div[2]'; + const XPATH_EXPRESSION_ITEM_TIMESTAMP = './/time/@datetime'; + const XPATH_EXPRESSION_ITEM_ENCLOSURES = './/img/@src'; + const XPATH_EXPRESSION_ITEM_CATEGORIES = './/div[starts-with(@class, "CardDetails-label ")]/span[2]'; + + public function getSourceUrl() { + return self::URI . $this->getInput('category'); + } + + public function getIcon() { + return 'https://www.radiofrance.fr/dist/favicons/fip/favicon.png'; + } + + protected function formatItemTimestamp($value) { + return strtotime('today +' . $value); + } +} diff --git a/config/services/web/rss/ParisCineInfoBridge.php b/config/services/web/rss/ParisCineInfoBridge.php new file mode 100644 index 0000000..5e418b4 --- /dev/null +++ b/config/services/web/rss/ParisCineInfoBridge.php @@ -0,0 +1,98 @@ +<?php + +class ParisCineInfoBridge extends BridgeAbstract { + const NAME = 'Paris-ciné.info Bridge'; + const URI = 'https://paris-cine.info/'; + const DESCRIPTION = 'Movies playing in Paris'; + const MAINTAINER = 'Quentin Aristote'; + const CACHE_TIMEOUT = 86400; // 24h + + const PARAMETERS = [ + 'Filters' => [ + // TODO add an option for choosing the reviewer + 'card' => [ + 'name' => 'Card', + 'type' => 'text', + 'title' => 'Fidelity / subscription card.', + 'exampleValue' => 'ugc', + 'defaultValue' => 'all' + ], + 'dayid' => [ + 'name' => 'Day of the week', + 'type' => 'text', + 'title' => 'Comma-separated list of integers (0 means everyday, 1 means Sunday, etc.)/', + 'exampleValue' => '1,3,6', + 'defaultValue' => '0' + ], + 'time' => [ + 'name' => 'Time of day', + 'type' => 'text', + 'title' => 'Morning (8AM-12AM), Afternoon (12AM-18PM), Evening (18PM-12PM).', + 'exampleValue' => 'soir', + 'defaultValue' => 'all' + ], + 'addr' => [ + 'name' => 'Location', + 'type' => 'text', + 'title' => 'Comma-separated list of districts or cities.', + 'exampleValue' => '13e,Châtillon', + 'defaultValue' => 'Paris' + ], + 'cine' => [ + 'name' => 'Theater', + 'type' => 'text', + 'title' => 'ID of a movie theater.', + 'exampleValue' => 'C0150', + ], + 'format' => [ + 'name' => 'Format', + 'type' => 'text', + 'title' => 'Movie format.', + 'exampleValue' => '3D' + ] + ] + ]; + + public function getSourceUrl() { + $query = ''; + foreach(self::PARAMETERS['Filters'] as $param => $val) { + $value = $this->getInput($param); + if ($value != '') { + $query = $query . 'sel' . $param . '=' . $value . '&'; + } + } + $selday = ['week', 'dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi'][$this->getInput('dayid')]; + return self::URI . 'get_pcimovies.php?' . $query . 'selday=' . $selday; + } + + private function fetchData() { + return json_decode(getSimpleHTMLDOMCached($this->getSourceUrl()))->data; + } + + public function getIcon() { + return 'https://paris-cine.info/resources/img/favicon-16x16.png'; + } + + public function collectData() { + $data = $this->fetchData(); + foreach($data as $film) { + $item = [ + 'uri' => str_replace('\\/', '/', $film->sc_url), + 'title' => $film->title, + 'timestamp' => str_replace('/', '-', $film->released), + 'author' => $film->dir, + 'content' => ( + $film->year . ' - ' . + 'with ' . str_replace(',', ', ', $film->actors) . ' - ' . + $film->duration . ' - ' . + 'SC: ' . $film->sc_rating . '/10 - ' . + 'IMDB: ' . $film->imdbr . '/10' . ' ' + ), + 'enclosures' => [ $film->poster_url ], + 'categories' => explode(',', $film->genre), + 'id' => $film->id + ]; + $this->items[] = $item; + } + } +} diff --git a/config/services/web/rss/WhatsOnMubiBridge.php b/config/services/web/rss/WhatsOnMubiBridge.php new file mode 100644 index 0000000..4cf7718 --- /dev/null +++ b/config/services/web/rss/WhatsOnMubiBridge.php @@ -0,0 +1,49 @@ +<?php + +class WhatsOnMubiBridge extends XPathAbstract { + const NAME = 'What\'s on Mubi Bridge'; + const URI = 'https://whatsonmubi.com/?catalogue=ns&sort=expires-desc'; + const DESCRIPTION = 'Movies currently showing on Mubi.'; + const MAINTAINER = 'Quentin Aristote'; + const CACHE_TIMEOUT = 21800; // 6h + + const PARAMETERS = [ + '' => [ + 'country' => [ + 'name' => 'Country', + 'type' => 'text', + 'exampleValue' => 'fr', + 'defaultValue' => 'fr', + ] + ] + ]; + + const XPATH_EXPRESSION_ITEM = '//div[@class="film"]'; + const XPATH_EXPRESSION_ITEM_TITLE = './/h2'; + const XPATH_EXPRESSION_ITEM_CONTENT = './/div[@class="film_details flex flex-col flex-1"]'; + const XPATH_EXPRESSION_ITEM_URI = './/a[@class="relative film_thumbnail"]/@href'; + const XPATH_EXPRESSION_ITEM_AUTHOR = './@data-directors'; + const XPATH_EXPRESSION_ITEM_TIMESTAMP = './/p[@class="hidden film-expires"]'; + const XPATH_EXPRESSION_ITEM_ENCLOSURES = './/a[@class="relative film_thumbnail"]/img/@src'; + const XPATH_EXPRESSION_ITEM_CATEGORIES = './/div[@class="film_details flex flex-col flex-1"]//div[@class="mt-3 flex flex-wrap"]'; + + public function getSourceUrl() { + return self::URI . '&showing=' . $this->getInput('country'); + } + + public function getIcon() { + return 'https://whatsonmubi.com/favicon.ico'; + } + + protected function formatItemTimestamp($value) { + return strtotime('today +' . $value); + } + + protected function formatItemContent($value) { + $text = preg_replace("/\s{2}\s+/", "\n", $value); + $lines = array_map("trim", explode("\n", $text)); + $title = $lines[0]; + $director = $lines[1]; + return $director . ' ' . $title; + } +} diff --git a/config/services/web/rss/default.nix b/config/services/web/rss/default.nix index 4d7dd18..f2b667b 100644 --- a/config/services/web/rss/default.nix +++ b/config/services/web/rss/default.nix @@ -1,28 +1,40 @@ { config, lib, pkgs, ... }: -let - cfg = config.services.rss-bridge; - debug = false; - rss-bridge = pkgs.rss-bridge.overrideAttrs (oldAttrs: - oldAttrs // { - installPhase = oldAttrs.installPhase + '' - ln -sf ${./ParisJazzClubBridge.php} $out/bridges/ParisJazzClubBridge.php - ln -sf ${./MaisonDeLaRadioBridge.php} $out/bridges/MaisonDeLaRadioBridge.php - '' + lib.optionalString debug '' - touch $out/DEBUG - ''; - }); +let cfg = config.services.rss-bridge; in { services.rss-bridge = { enable = true; - whitelist = [ "ParisJazzClub" "MaisonDeLaRadio" ]; + extraBridges = [ + # Music + { + name = "FipAlbums"; + source = ./FipAlbumsBridge.php; + } + ## Concerts + { + name = "ParisJazzClub"; + source = ./ParisJazzClubBridge.php; + } + { + name = "MaisonDeLaRadio"; + source = ./MaisonDeLaRadioBridge.php; + } + # Cinema + { + name = "WhatsOnMubi"; + source = ./WhatsOnMubiBridge.php; + } + { + name = "ParisCineInfo"; + source = ./ParisCineInfoBridge.php; + } + ]; virtualHost = "rss"; }; services.nginx = lib.mkIf (cfg.virtualHost != null) { virtualHosts.${cfg.virtualHost} = { serverName = "rss.${config.networking.domain}"; - root = lib.mkForce "${rss-bridge}"; forceSSL = true; enableACME = true; }; |
