MP3-PodcastFetch

 view release on metacpan or  search on metacpan

lib/MP3/PodcastFetch.pm  view on Meta::CPAN

episodes successfully fetched by the proceeding call to fetch_pods().

=cut

sub fetched_files {
  return @{shift->{files_fetched}}
}

=item @files = $feed->deleted_files

This method will return the complete paths to each of the podcast
episodes successfully deleted by the proceeding call to fetch_pods().

=cut

sub deleted_files {
  return @{shift->{files_deleted}}
}

=item $feed->fetched

The number of episodes fetched/refreshed.

=item $feed->skipped

The number of episodes skipped.

=item $feed->deleted

The number of episodes deleted because they are either no longer
mentioned in the subscription file or exceed the per-feed limit.

=item $feed->errors

The number of episodes not fetched because of an error.

=back

=cut

sub fetched { shift->{stats}{fetched} ||= 0 }
sub errors  { shift->{stats}{error}   ||= 0 }
sub deleted { shift->{stats}{deleted} ||= 0 }
sub skipped { shift->{stats}{skipped} ||= 0 }

=head2 Internal Methods

These methods are intended for internal use cut can be overridden in
subclasses in order to change their behavior.

=over 4

=item $feed->update($channel)

Update all episodes contained in the indicated
MP3::PodcastFetch::Feed::Channel object (this object is generated by
podcast_fetch() in the course of downloading and parsing the RSS file.

=cut

sub update {
  my $self    = shift;
  my $channel = shift;
  my $title        = $channel->title;
  my $description  = $channel->description;
  my $dir          = $self->generate_directory($channel);
  my @items        = sort {$b->timestamp <=> $a->timestamp} grep {$_->url} $channel->items;
  my $total        = @items;

  # if there are more items than we want, then remove the oldest ones
  if (my $max = $self->max) {
    splice(@items,$max) if @items > $max;
  }

  $self->log("$title: $total podcasts available. Mirroring ",scalar @items,"...");
  {
    $self->{tabs}++; # for formatting
    $self->mirror($dir,\@items,$channel);
    $self->{tabs}--; # for formatting
  }
  1;
}

=item $feed->bump_fetched($value)

=item $feed->bump_error($value)

=item $feed->bump_deleted($value)

=item $feed->bump_skipped($value)

Increase the fetched, error, deleted and skipped counters by $value,
or by 1 if not specified.

=cut

sub bump_fetched {shift->{stats}{fetched} += (@_ ? shift : 1)}
sub bump_error  {shift->{stats}{error} += (@_ ? shift : 1)}
sub bump_deleted {shift->{stats}{deleted} += (@_ ? shift : 1)}
sub bump_skipped {shift->{stats}{skipped} += (@_ ? shift : 1)}

=item $feed->mirror($dir,$items,$channel)

Mirror a list of podcast episodes into the indicated directory. $dir
is the absolute path to the directory to mirror the episodes into,
$items is an array ref of MP3::PodcastFetch::Feed::Item objects, and
$channel is a MP3::PodcastFetch::Feed::Channel object.

=cut

sub mirror {
  my $self = shift;
  my ($dir,$items,$channel) = @_;

  # generate a directory listing of the directory
  my %current_files;
  my $curdir = getcwd();
  chdir($dir) or croak "Couldn't changedir to $dir: $!";
  my $d = IO::Dir->new('.') or croak "Couldn't open directory $dir for reading: $!";
  while (my $file = $d->read) {
    next if $file eq '..';



( run in 2.851 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )