Skip to content

Instantly share code, notes, and snippets.

@snipe
Last active July 28, 2023 14:00
Show Gist options
  • Save snipe/4758106 to your computer and use it in GitHub Desktop.
Save snipe/4758106 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