Source

dlpodget / dlpodget

The branch 'f/201210-conf' does not exist.
#!/usr/bin/perl -w

package main;
use LWP::Simple qw(get);
use XML::Feed;
use Data::Dumper;
use strict;
use warnings;
use diagnostics;

sub FileFromURI($)
{
	my $Url = shift;
	my @uri_parts = split('/', $Url);
	return $uri_parts[-1];
}

sub ReadStream($)
{
	my $Url = shift;

	my $feed = XML::Feed->parse(URI->new($Url));

	foreach my $podcast ($feed->entries) {
		my $data;
		my $filename = FileFromURI($podcast->link);
		my $local_podcast = LOCAL_STORE_PATH() . '/' . $filename;
		if ( -f $local_podcast ) {
			printf(STDERR "%s already exists\n", $local_podcast);
			next;
		}
		printf(STDERR "Downloading %s ... ", $podcast->link);
		$data = get($podcast->link);
		print(STDERR "done.\n");

		printf(STDERR "\nWriting %s ... ", $local_podcast);
		if ( open(my $f, '>', $local_podcast) ) {
			binmode($f);
			print($f $data);
			close($f);
			print(STDERR "done.\n");
		} else {
			printf(STDERR "Failed -- %s\n", $!);
		}
	}

}

sub main()
{
	ReadStream(URL());
	return 0;
}

exit(main());