diff options
Diffstat (limited to 'config/services/web/rss')
| -rw-r--r-- | config/services/web/rss/DeutschLernenDeutscheWelleBridge.php | 39 | ||||
| -rw-r--r-- | config/services/web/rss/FipAlbumsBridge.php | 56 | ||||
| -rw-r--r-- | config/services/web/rss/MaisonDeLaRadioBridge.php | 137 | ||||
| -rw-r--r-- | config/services/web/rss/RandonavigoBridge.php | 33 | ||||
| -rw-r--r-- | config/services/web/rss/default.nix | 45 |
5 files changed, 310 insertions, 0 deletions
diff --git a/config/services/web/rss/DeutschLernenDeutscheWelleBridge.php b/config/services/web/rss/DeutschLernenDeutscheWelleBridge.php new file mode 100644 index 0000000..710f8e6 --- /dev/null +++ b/config/services/web/rss/DeutschLernenDeutscheWelleBridge.php @@ -0,0 +1,39 @@ +<?php + +class DeutschLernenDeutscheWelleBridge extends XPathAbstract { + const NAME = 'Deutsche Welle Lernen Bridge'; + const URI = 'https://learngerman.dw.com/de/'; + const DESCRIPTION = 'Cost-free German-learning material'; + const MAINTAINER = 'Quentin Aristote'; + const CACHE_TIMEOUT = 3600; // 24h + + const PARAMETERS = [ + '' => [ + 'id' => [ + 'name' => 'Identifier', + 'type' => 'text', + 'description' => 'An identifier of the shape [a-z]-[0-9]*. Found at the end of the target URL.', + 'exampleValue' => 's-60040484' + ] + ] + ]; + + const XPATH_EXPRESSION_ITEM = '//div[@class="teaser-wrap"]/a'; + const XPATH_EXPRESSION_ITEM_TITLE = './@title'; + const XPATH_EXPRESSION_ITEM_URI = './@href'; + // not given + // const XPATH_EXPRESSION_ITEM_AUTHOR = + const XPATH_EXPRESSION_ITEM_TIMESTAMP = './/time/@datetime'; + // requires javascript + // const XPATH_EXPRESSION_ITEM_ENCLOSURES = './figure/img[2]/@src'; + const XPATH_EXPRESSION_ITEM_CATEGORIES = './div[2]/span[1]/text()'; + + + public function getIcon() { + return 'https://learngerman.dw.com/favicon.png'; + } + + public function getSourceUrl() { + return self::URI . $this->getInput('id'); + } +} diff --git a/config/services/web/rss/FipAlbumsBridge.php b/config/services/web/rss/FipAlbumsBridge.php new file mode 100644 index 0000000..aa5e597 --- /dev/null +++ b/config/services/web/rss/FipAlbumsBridge.php @@ -0,0 +1,56 @@ +<?php + +$GLOBALS['DATE_FORMATTER'] = new IntlDateFormatter( + 'fr-FR', + IntlDateFormatter::FULL, + IntlDateFormatter::SHORT, + 'Etc/UTC', + IntlDateFormatter::GREGORIAN, + "d MMMM y" +); + +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, "CardSide ")]'; + const XPATH_EXPRESSION_ITEM_TITLE = './/a/@aria-label'; + const XPATH_EXPRESSION_ITEM_CONTENT = './/img/@alt'; + const XPATH_EXPRESSION_ITEM_URI = './/a/@href'; + const XPATH_EXPRESSION_ITEM_AUTHOR = './/div[starts-with(@class, "title-zone ")]/p[2]/text()'; + const XPATH_EXPRESSION_ITEM_TIMESTAMP = './/div[starts-with(@class, "AdditionalInfos ")]/p[1]/text()'; + const XPATH_EXPRESSION_ITEM_ENCLOSURES = './/img/@src'; + const XPATH_EXPRESSION_ITEM_CATEGORIES = './/div[starts-with(@class, "AdditionalInfos ")]/p[2]/text()'; + + 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) { + $monthyear = explode(": ", $value)[1]; + return $GLOBALS['DATE_FORMATTER']->parse('1 ' . $monthyear); + } + + # enclosure links don't have an extension + protected function cleanMediaUrl($mediaUrl) { + return $mediaUrl; + } +} diff --git a/config/services/web/rss/MaisonDeLaRadioBridge.php b/config/services/web/rss/MaisonDeLaRadioBridge.php new file mode 100644 index 0000000..7fd4b4f --- /dev/null +++ b/config/services/web/rss/MaisonDeLaRadioBridge.php @@ -0,0 +1,137 @@ +<?php + +$GLOBALS['DATE_FORMATTER'] = new IntlDateFormatter( + 'fr-FR', + IntlDateFormatter::FULL, + IntlDateFormatter::SHORT, + 'Etc/UTC', + IntlDateFormatter::GREGORIAN, + "dd MMMM y EEEE hh'h'mm" +); + +class MaisonDeLaRadioBridge extends XPathAbstract { + const NAME = 'Maison de la Radio Bridge'; + const URI = 'https://www.maisondelaradioetdelamusique.fr/agenda'; + const DESCRIPTION = 'Agenda of the Maison de la Radio et de la Musique.'; + const MAINTAINER = 'Quentin Aristote'; + const CACHE_TIMEOUT = 3600; // 1h + + const FEED_SOURCE_URL = 'https://www.maisondelaradioetdelamusique.fr/agenda'; + const XPATH_EXPRESSION_ITEM = '//div[@class="hero-header--agenda text-white"]'; + const XPATH_EXPRESSION_ITEM_TITLE = './/div[@class="Bolder-Large-XL mb-5 field_title"]'; + const XPATH_EXPRESSION_ITEM_URI = './/div[@class="d-flex"]//a/@href'; + const XPATH_EXPRESSION_ITEM_AUTHOR = './/div[@class="d-flex flex-column"]/div[2]'; + const XPATH_EXPRESSION_ITEM_TIMESTAMP = './/div[@class="date text-uppercase text-center"]'; + const XPATH_EXPRESSION_ITEM_ENCLOSURES = './/div[@class="bg-wrapper"]/img/@src'; + const XPATH_EXPRESSION_ITEM_CATEGORIES = './/div[@class="SurTitre mb-5 field_event_type"]/text()'; + + const PARAMETERS = array( + '' => array ( + 'type' => array( + 'name' => 'Type', + 'type' => 'list', + 'title' => 'Concert types.', + 'values' => array( + 'Tous' => 0, + 'Concert' => 2543, + 'Émission en public' => 1270, + 'Évènement' => 1273, + 'Rencontre' => 1272, + 'Exposition' => 1768, + 'Festival' => 2544, + 'Conert jeune public' => 1482 + ) + ), + 'genre' => array( + 'name' => 'Genre', + 'type' => 'list', + 'title' => 'Music genre.', + 'values' => array( + 'Tous' => 0, + 'Symphonique' => '1207', + 'Opéra' => '1212', + 'Musique baroque' => '1208', + 'Musique chorale' => '1211', + 'Musique de film' => '2542', + 'Récital et musique de chambre' => '1210', + 'Orgue' => '1214', + 'Jazz' => '1761', + 'Création contemporaine' => '1215', + 'Concert Jeune public' => '2584', + 'Tournée' => '2583', + 'Pop, rock et électro' => '2541', + 'Concert Fip' => '1225', + 'Atelier musical' => '1258', + 'Masterclasse' => '1251', + 'Concerts du soir et avant-concerts pour les scolaires' => '2560', + 'Concerts jeune public pour le champ social' =>'2581' + ) + ), + 'formation' => array( + 'name' => 'Formation', + 'type' => 'list', + 'title' => 'Performing formations.', + 'values' => array( + 'Tous' => 0, + 'Orchestre Philharmonique de Radio France' => '864%2B2660%2B3333', + 'Orchestre National de France' => '861%2B1786', + 'Chœur de Radio France' => '703%2B2946', + 'Maîtrise de Radio France' => '832%2B2947' + ) + ), + 'chef' => array( + 'name' => 'Chef', + 'type' => 'number', + 'title' => 'ID of the conductor (optional).', + 'exampleValue' => '53', + ), + 'compositeur' => array( + 'name' => 'Compositeur', + 'type' => 'number', + 'title' => 'ID of the composer (optional).', + 'exampleValue' => '131', + ), + 'soliste' => array( + 'name' => 'Soliste', + 'type' => 'number', + 'title' => 'ID of the solist (optional).', + 'exampleValue' => '3064', + ) + ) + ); + + public function getSourceUrl() { + $query = 'layout=row' . '&a-partir=' . date('Y-m-d'); + foreach(self::PARAMETERS[''] as $param => $paramSpec) { + $val = $this->getInput($param); + if($val != 0 && !is_null($val)) { + if($paramSpec['type'] == 'list') { + $assignmentOp = '[]='; + } else { + $assignmentOp = '='; + } + $query = $query . '&' . $param . $assignmentOp . $val; + } + } + return self::URI . '?' . $query; + } + + public function getIcon() { + return 'https://rf-maisondelaradio-production.s3.eu-west-3.amazonaws.com/s3fs-public/mdlrfavicon22.ico'; + } + + protected function getExpressionItemContent() { + return 'string(.//div[contains(@class, "Serif-small")])'; + } + protected function formatItemContent($value) { + $normalizedWhitespace = preg_replace('/\s\s+/m', ' ', $value); + return preg_replace('/\s*,/', ',', $normalizedWhitespace); + } + + protected function getExpressionItemTimestamp() { + return 'normalize-space(concat(string(' . self::XPATH_EXPRESSION_ITEM_TIMESTAMP . '), .//div[@class="d-flex flex-column"]/div[1]))'; + } + protected function formatItemTimestamp($value) { + return $GLOBALS['DATE_FORMATTER']->parse($value); + } +} diff --git a/config/services/web/rss/RandonavigoBridge.php b/config/services/web/rss/RandonavigoBridge.php new file mode 100644 index 0000000..ebc64c2 --- /dev/null +++ b/config/services/web/rss/RandonavigoBridge.php @@ -0,0 +1,33 @@ +<?php + +class RandonavigoBridge extends XPathAbstract { + const NAME = 'Randonavigo Bridge'; + const URI = 'https://www.randonavigo.fr/'; + const DESCRIPTION = 'Hiking trails in Île-de-France.'; + const MAINTAINER = 'Quentin Aristote'; + const CACHE_TIMEOUT = 86400; // 24h + + const FEED_SOURCE_URL = 'https://www.randonavigo.fr/'; + const XPATH_EXPRESSION_ITEM = '//article'; + const XPATH_EXPRESSION_ITEM_TITLE = './/h2/a/text()'; + const XPATH_EXPRESSION_ITEM_CONTENT = './div/div[1]/div[2]/text()'; + const XPATH_EXPRESSION_ITEM_URI = './a/@href'; + const XPATH_EXPRESSION_ITEM_AUTHOR = './div/div[1]/div[1]/div/text()'; + const XPATH_EXPRESSION_ITEM_TIMESTAMP = './a/@href'; + const XPATH_EXPRESSION_ITEM_ENCLOSURES = './a//img/@src'; + const XPATH_EXPRESSION_ITEM_CATEGORIES = './div/div[2]//a/@title'; + + public function getIcon() { + return 'https://www.randonavigo.fr/apple-touch-icon.png'; + } + + protected function formatItemTimestamp($value) { + $pattern = "/\/([0-9]+)/"; + preg_match_all($pattern, $value, $matches); + return strtotime(join('-', $matches[1])); + } + + protected function cleanMediaUrl($value) { + return $value; + } +} diff --git a/config/services/web/rss/default.nix b/config/services/web/rss/default.nix new file mode 100644 index 0000000..8884aee --- /dev/null +++ b/config/services/web/rss/default.nix @@ -0,0 +1,45 @@ +{ + config, + lib, + ... +}: +let + cfg = config.services.rss-bridge; +in +{ + services.rss-bridge = { + enable = true; + config.system.enabled_bridges = [ "Instagram" ]; + extraBridges = [ + { + name = "Randonavigo"; + source = ./RandonavigoBridge.php; + } + { + name = "DeutschLernenDeutscheWelle"; + source = ./DeutschLernenDeutscheWelleBridge.php; + } + # Music + { + name = "FipAlbums"; + source = ./FipAlbumsBridge.php; + } + ## Concerts + { + name = "MaisonDeLaRadio"; + source = ./MaisonDeLaRadioBridge.php; + } + ]; + virtualHost = "rss"; + }; + + services.nginx = lib.mkIf (cfg.virtualHost != null) { + virtualHosts.${cfg.virtualHost} = { + serverName = "rss.${config.networking.domain}"; + forceSSL = true; + enableACME = true; + }; + }; + + systemd.services.phpfpm-rss-bridge.personal.monitor = true; +} |
