Tiny Tiny RSS: Community

Plugin for NASA Astronomy Picture of the Day


#1

Hi There,

as I stumbled upon NASA Astronomy Picture of the Day (http://apod.nasa.gov/) and wondered about them having a RSS feed, I subscribed to it in my tt-rss instance (which really works like a charm). As I realised, they just integrate a very small thumbnail in their feed, I created my first plugin to fetch the bigger image from the linked site, based on the jp_stuttman and the af_feedmod plugins. If someone is interested:

  1. create a folder large_apod in the plugins.local directory of your tt-rss instance

  2. create a file init.php and paste the following into it:

     <?php
     class large_apod extends Plugin {
    
         private $host;
    
         function about() {
             return array(1.0,
                     "Display large images in NASA APOD feed",
                     "t0t4");
         }
    
         function init($host) {
             $this->host = $host;
             $host->add_hook($host::HOOK_ARTICLE_FILTER, $this);
         }
    
         function hook_article_filter($article) {
             global $fetch_last_content_type;
    
             if (strpos($article['link'], 'apod.nasa.gov') === false) return $article; // skip other URLs
             if (isset($article['stored']['content'])) {
                     $article['content'] = $article['stored']['content'];
                     return $article; // skip already stored content
             }
    
             $doc = new DOMDocument();
             $link = trim($article['link']);
    
             $html = fetch_file_contents($link);
             $content_type = $fetch_last_content_type;
    
             $charset = false;
             if ($content_type) {
                     preg_match('/charset=(\S+)/', $content_type, $matches);
                     if (isset($matches[1]) && !empty($matches[1])) $charset = $matches[1];
             }
    
             if ($charset) {
                     $html = iconv($charset, 'utf-8', $html);
                     $charset = 'utf-8';
                     $html = '<?xml encoding="' . $charset . '">' . $html;
             }
    
             @$doc->loadHTML($html);
    
             if ($doc) {
                     $basenode = false;
                     $xpath = new DOMXPath($doc);
                     $entries = $xpath->query('(//img)');
    
                     if ($entries->length > 0) $basenode = $entries->item(0);
    
                     if ($basenode) {
                             $article['content'] = $doc->saveXML($basenode);
                     }
             }
    
             return $article;
         }
    
         function api_version() {
           return 2;
         }
     }
     ?>
    
  3. activate it in the preferences and resubscribe to the feed.

Please feel free to use it and please don’t slap me if it’s not working at your installation, suggestions to improve it are welcome.

Regards
T0t4


#2

:slight_smile: Many thanks indeed. I just tried it and it worked for me.

Is there a chance of you expending this to allow for a fixed size of the image & support the NASA image of the day? Their photos are generally huge in RSS.


#3

t0t4:
Thanks for plugin! it work’s great!

Kierun: NASA image of the day look OK in my TTRSS ( https://www.nasa.gov/rss/dyn/lg_image_of_the_day.rss ) - in widescreen mode.


#4

@mrflible

This is what I see:

Which is the full sized image.


#5

I can see it this way:

Only disadvantage is image size to download - for this image 2,6MB


#6

default CSS has images limited to maximum width, not sure why it doesn’t work for you @Kierun


#7

I removed all the custom CSS I had just in case and that made no difference. Then used inspector to get the CSS of the image.

I am using git commit ecab435420438e355d45a4adea33aeee26b9ca0d.


#8

ah the image is probably sourced from attachments, i guess the built-in css doesn’t cover those

you can try adding this to user css as a temporary workaround

div.cdmIntermediate img,
div.cdmIntermediate video {
	border-width : 0px;
	max-width : 98%;
	height : auto;
}

#9

@fox … and your black voodoo CSS incantation worked like a charm. :grinning:


#10

should be fixed in trunk now


#11

@fox I pulled the latest git, removed the custom CSS, and it’s all fine. Many thanks indeed.


#12

Nice plugin, thanks @t0t4! I put this up on github if anybody is interested.