Skip to content

Instantly share code, notes, and snippets.

@GeoWebDevCom
Forked from snipe/rss_img_ripper.php
Created May 16, 2017 10:01
Show Gist options
  • Save GeoWebDevCom/73a9ac8a4b2a2c8913ca58efc961c15a to your computer and use it in GitHub Desktop.
Save GeoWebDevCom/73a9ac8a4b2a2c8913ca58efc961c15a to your computer and use it in GitHub Desktop.
Quick and dirty script to download thumbnail and fullsize images from RSS feed. The RSS feed can be remote, but this was a one-off I needed to throw together, so I just downloaded the RSS feed to my local drive.
<?php
$feed = 'recent.rss';
$xml = new SimpleXMLElement(file_get_contents($feed));
$xml->registerXPathNamespace('media', $feed);
$images = $xml->xpath('/rss/channel/item/media:content/@url');
foreach ( $xml->channel->item as $item ) {
$namespaces = $item->getNameSpaces(true);
$media = $item->children($namespaces['media']);
if ($media->thumbnail->count() > 0) {
$thumb_url = $media->thumbnail->attributes()->url;
$thumb = file_get_contents($thumb_url);
file_put_contents('thumbs/'.basename($thumb_url),$thumb);
}
if ($media->content->count() > 0) {
$img_url = $media->content->attributes()->url;
$img = file_get_contents($img_url);
file_put_contents('full/'.basename($img_url),$img);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment