lwindolf / liferea

Liferea (Linux Feed Reader), a news reader for GTK/GNOME
https://lzone.de/liferea
GNU General Public License v2.0
807 stars 132 forks source link

Convert YouTube Channel URL to Feed URL #813

Open antistress opened 4 years ago

antistress commented 4 years ago

Hi,

At present time I use 2 extensions within Firefox to discover RSS feeds on websites : Awesome RSS (general) and YouTube RSS Finder (YouTube-specific).

Someone who is using FreshRSS explains me that he doesn't need any of these extensions since copy/pasting the website URL directly in its feed reader did the job. I tried with different websites and I'm delighted to see that ideed copy/pasting the website URL into Liferea did work. However copy/pasting a YouTube video URL into Liferea didn't work.

It would be great if Liferea could be smart enough to detect YouTube channels RSS feed like FreshRSS does.

Thanks !

PS : Maybe https://github.com/FreshRSS/FreshRSS/issues/2172 could be help ?

rich-coe commented 4 years ago

I'm not sure how this could be scripted within liferea, perhaps in parsing a youtube video page to get the channel id.

When I click on the owner of a YouTube video, it takes me to a url that looks like this: https://www.youtube.com/channel/UCWOkEnXxXXXxxxxXXX92jgg

I then construct a feed url like this: https://www.youtube.com/feeds/videos.xml?channel_id=UCWOkEnXxXXXxxxxXXX92jgg

This is the same URL that is returned if you subscribe to a channel and do a 'checkout' of all your subscriptions.

antistress commented 4 years ago

Sorry my above description is wrong : functionality would be to allow user to paste YouTube Channel URL directly into Liferea so that Liferea can convert it into an RSS feed.

Pasting a YouTube video URL into Liferea to get channel RSS feed would be more complicated or impossible (and would be another bug anyway)

Adding a trick into Liferea to automatically detect YouTube channel URL (they seem to all start with www.youtube.com/channel/ as you've pointed) and then turning them into proper RSS feed would be awesome :)

antistress commented 4 years ago

Maybe later we could open another bug that allow user to paste even a YouTube video URL to get the Youtube channel feed into Liferea. I've checked and YouTube RSS Finder webextension (which is publihed under a Licence MIT/X11) allows that (it even supports playlists which has been added to v 1.3.0) https://github.com/teddy-gustiaux/youtube-rss-finder But that would be a far more complex one I guess.

ao2 commented 3 years ago

That would be useful indeed, @lwindolf would it be hard to change the URL on the fly when adding a new youtube source? Could that be done in a liferea plugin?

lwindolf commented 3 years ago

@ao2 The current code base has no way to intercept and "translate" the URL. The only workaround is to write a filter script and make it proxy to the proper feed.

ao2 commented 3 years ago

Thanks @lwindolf using a filter might be a little overkill as the target URL never changes, but yeah the URL conversion can be easily handled outside of liferea.

Here is a possible solution to get the feed URL to use it in filerea, just for reference:

#!/bin/sh

set -e

check_dependency() {
  command -v "$1" 2>/dev/null 1>&2 || { echo "Missing dependency '$1' $2" 1>&2; exit 1; }
}

is_youtube_channel() {
  printf '%s' "$1" | grep -q -E '^https://www.youtube.com/(c|channel|user)/?*'
}

get_canonical_url() {
  curl -s "$1" | xmllint --html --xmlout --xpath 'string(//link[@rel="canonical"]/@href)' - 2>/dev/null
}

check_dependency 'curl'
check_dependency 'xmllint' 'from libxml2'

is_youtube_channel "$1" || { echo "usage: $(basename "$0") <youtube_channel_url>" 1>&2; exit 1; }

CANONICAL_URL=$(get_canonical_url "$1")

FEED_URL=$(printf '%s' "$CANONICAL_URL" | sed -e 's@https://www.youtube.com/channel/\([^?#]*\).*$@https://www.youtube.com/feeds/videos.xml?channel_id=\1@')

echo "$FEED_URL"

# Use this if you want to add the feed url as is to liferea.
#liferea-add-feed "$FEED_URL"

# Use this instead if you want to use the script as a filter.
#curl -s "$FEED_URL"

Ciao, Antonio

lwindolf commented 3 years ago

Cool script!

@ao2 When thinking about a plugin based solution. Let's say a type of "feed discovery plugin". How would you envision the API for such a plugin to hook into? The UI would still be an URL entered by the user. What would happen in the background?

ao2 commented 3 years ago

@lwindolf I guess a possible entry point for a "feed discovery plugin" could be in feed_parse: https://github.com/lwindolf/liferea/blob/4e07f6c52c72d1f182cee5be686ed7a0117b100e/src/feed_parser.c#L230

The input could be just the source URL, and depending on other Liferea APIs the output could be another URL, or a pair (target URL, feed content).

I am not sure if Liferea itself would have to match some rules against the source URL to decide what "feed discovery plugin" to call, of if that could be delegated to the plugins.

I imagine that in some cases the plugin would have to parse the content at the source URL (like in the script above), so if the parsing utilities from Liferea could be made available (e.g. xpath or regex helpers) the plugin implementation would benefit from those.

Whether this is worth or not it depends of how may users want it and/or how many sites need this, but in case it's done maybe the <link rel="alternate" /> discovery can become a plugin too?

Just words, I know :sweat_smile:, I cannot promise any code contribution for now.

Thanks, Antonio

RashadBrowne commented 3 years ago

Can there be a function to parse playlist IDs as well? So from this https://www.youtube.com/watch?v=JGwWNGJdvx8&list=PLMC9KNkIncKtPzgY-5rmhvj7fax8fdxoj

To this https://www.youtube.com/feeds/videos.xml?playlist_id=PLMC9KNkIncKtPzgY-5rmhvj7fax8fdxoj

Using the format https://www.youtube.com/feeds/videos.xml?playlist_id=@PLAYLIST_ID@

Though large playlists wouldn't show the newest videos......

antistress commented 1 year ago

I don't know if that php api file can help https://api.warriordudimanche.net/youtubeRSS/ If not, sorry for the noise