passiomatic / coldsweat

Web RSS aggregator and reader compatible with the Fever API
MIT License
145 stars 21 forks source link

Videos are removed from feed entries #75

Closed Pablo2m closed 11 months ago

Pablo2m commented 10 years ago

Currently youtube videos do not appear

I think it is not bad, but it would be nice to choose from:

passiomatic commented 10 years ago

Actually videos - and embedded contents in general - are removed by Feedparser due to its sanitization process.

Removing sanitization altogether is not an option, since there are to many things that could go wrong while having to deal with unsafe HTML code. Instead, one could write a plugin that disable Feedparser sanitization only for iframe elements, thus allowing embedded videos to slip thru and than parse the entry again to remove any iframe which doesn't point to YouTube, Vimeo or any other popular whitelisted video streaming services.

As today iframe element seems the primary suggested way to embed videos into web pages. For example:

Vimeo

<iframe src="//player.vimeo.com/video/69649037" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> <p><a href="http://vimeo.com/69649037">Treo Fiskur</a> from <a href="http://vimeo.com/treofiskur">Treo Fiskur</a> on <a href="https://vimeo.com">Vimeo</a>.</p>

YouTube

<iframe width="560" height="315" src="//www.youtube.com/embed/c3IS9q6pwb4" frameborder="0" allowfullscreen></iframe>

Feedparser could be tamed to accept iframe elements with:

>>> import feedparser as p
>>> p._HTMLSanitizer.acceptable_elements.update(['iframe'])

So it looks feasible, but it isn't trivial. ;^)

passiomatic commented 1 year ago

I've managed to implement this feature in 5738caeda8d5060cbd5260c2856d9d95d9c74eff. At the moment the only allowed domains as sources for iframe videos are:

www.youtube.com
www.youtube-nocookie.com
player.vimeo.com

It would be good to have a more precise list.

Note: this commit doesn't fix the YT-generated RSS feeds. Currently the YT feeds do not contain embeds but only a thumbnail image and a link to the of the video. This will be handled in another way in the future UI.