Last active
July 28, 2023 14:00
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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