From 738e3ce2750cb7f995308d00aefd2b8502807b1e Mon Sep 17 00:00:00 2001 From: Roberto Polverelli Monti Date: Sat, 16 Jan 2021 18:49:45 +0100 Subject: [PATCH] additionally extract from xml files Before this, rssadd only accepted a URL as argument. Now, if given an xml file, it will parse it and extract the proper url. This lets it be used in conjunction with firefox for quickly adding RSS feeds (as firefox would give it the file rather than its origin URL). This works on a majority of RSS feeds, but fails on some that miss the proper link tags. The original behaviour is still mantained alongside the new. --- .local/bin/rssadd | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/.local/bin/rssadd b/.local/bin/rssadd index 2ce421bd..81d9267c 100755 --- a/.local/bin/rssadd +++ b/.local/bin/rssadd @@ -1,10 +1,20 @@ #!/bin/sh -! echo "$1" | grep "https*://\S\+\.[A-Za-z]\+\S*" >/dev/null && - notify-send "That doesn't look like a full URL." && exit +if echo "$1" | grep "https*://\S\+\.[A-Za-z]\+\S*" >/dev/null; then + url="$1" +else + url="$(grep 'rel="self"' "$1" | + grep xml | + sed -E 's_^.*href="(https?://[^"]+)".*$_\1_')" + + ! grep "https*://\S\+\.[A-Za-z]\+\S*" <<<"$url" && + notify-send "That doesn't look like a full URL." && exit + exit 1 +fi + RSSFILE="${XDG_CONFIG_HOME:-$HOME/.config}/newsboat/urls" -if awk '{print $1}' "$RSSFILE" | grep "^$1$" >/dev/null; then +if awk '{print $1}' "$RSSFILE" | grep "^$url$" >/dev/null; then notify-send "You already have this RSS feed." else - echo "$1" >> "$RSSFILE" && notify-send "RSS feed added." + echo "$url" >> "$RSSFILE" && notify-send "RSS feed added." fi