Skip to content

Commit

Permalink
Bring the "More" menu item to subscribed podcast feeds.
Browse files Browse the repository at this point in the history
This required a change in `Slim::Control::XMLBrowser`: if an item has a variable (eg. URL) pointing at a code ref, we must ignore it. These items can't be dealt with by Squeezeplay. In the Podcasts plugin this would eg. be the Search menu item. There's no "More" info menu for such items, which is ok.
  • Loading branch information
mherger committed Jun 30, 2021
1 parent 2cf8826 commit 78176cb
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 31 deletions.
8 changes: 7 additions & 1 deletion Slim/Control/XMLBrowser.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1309,9 +1309,15 @@ sub _cliQuery_done {
my %params;
my @vars = @{$actionParamsNeeded{$key}};
for (my $i = 0; $i < scalar @vars; $i += 2) {
# ignore items whose URL points to a code ref - Squeezeplay can't handle them
if (ref $item->{$vars[$i+1]}) {
%params = ();
last;
}

$params{$vars[$i]} = $item->{$vars[$i+1]};
}
$hash{$key} = \%params;
$hash{$key} = \%params if keys %params;
}
}

Expand Down
14 changes: 11 additions & 3 deletions Slim/Formats/XML.pm
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ sub getFeedAsync {
$handler->explodePlaylist($params->{client}, $url, sub {
my ($tracks) = @_;

# explode playlist might return a full opml list
# explode playlist might return a full opml list
return $cb->($tracks, $params) if ref $tracks eq 'HASH';

# if not, this is just an array of url
Expand Down Expand Up @@ -147,8 +147,8 @@ sub getFeedAsync {

if ( $url =~ IS_TUNEIN_RE ) {
# Add the TuneIn username
if ( $url !~ /username/ && $url =~ /(?:presets|title)/
&& Slim::Utils::PluginManager->isEnabled('Slim::Plugin::InternetRadio::Plugin')
if ( $url !~ /username/ && $url =~ /(?:presets|title)/
&& Slim::Utils::PluginManager->isEnabled('Slim::Plugin::InternetRadio::Plugin')
&& ( my $username = Slim::Plugin::InternetRadio::TuneIn->getUsername($params->{client}) )
) {
$url .= '&username=' . uri_escape_utf8($username);
Expand Down Expand Up @@ -439,6 +439,14 @@ sub parseRSS {
$feed{'image'} = $href unless ref $href;
}

if (my $language = $xml->{'channel'}->{'language'}) {
$feed{language} = unescapeAndTrim($language);
}

if (my $author = $xml->{'channel'}->{'author'} || $xml->{'channel'}->{'itunes:author'}) {
$feed{author} = unescapeAndTrim($author);
}

# some feeds (slashdot) have items at same level as channel
my $items;

Expand Down
76 changes: 49 additions & 27 deletions Slim/Plugin/Podcast/Plugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -177,38 +177,37 @@ sub handleFeed {
name => $_->{name},
url => $url,
favorites_url => $url,
favorites_type => 'link',
parser => 'Slim::Plugin::Podcast::Parser',
image => $image || __PACKAGE__->_pluginDataFor('icon'),
playlist => $url,
};

unless ($image) {
# always cache image avoid sending a flood of requests
$cache->set('podcast-rss-' . $url, __PACKAGE__->_pluginDataFor('icon'), '1days');

Slim::Networking::SimpleAsyncHTTP->new(
unless ($image && $cache->get('podcast_moreInfo_' . $url)) {
Slim::Formats::XML->getFeedAsync(
sub {
eval {
my $xml = XMLin(shift->content);
my $image = $xml->{channel}->{image}->{url} || $xml->{channel}->{'itunes:image'}->{href};
$cache->set('podcast-rss-' . $url, $image, '90days') if $image;
};

$log->warn("can't parse $url RSS for feed icon: ", $@) if $@;
_precacheShowDetails($url, $_[0]);
},
sub {
$log->warn("can't get $url RSS feed icon: ", shift->error);
$log->warn("can't get $url RSS feed information: ", $_[0]);
},
{
cache => 1,
expires => 86400,
},
)->get($_->{value});
parser => 'Slim::Plugin::Podcast::Parser',
url => $_->{value},
expires => 86400
}
);
}
}

$cb->({
items => $items,
actions => {
info => {
command => ['podcastinfo', 'items'],
variables => [ 'url', 'url', 'name', 'name', 'image', 'image' ],
},
}
});
}

Expand Down Expand Up @@ -284,16 +283,7 @@ sub searchHandler {
$feed->{parser} ||= 'Slim::Plugin::Podcast::Parser';
push @$items, $feed;

# pre-cache some additional information to be shown in feed info menu
my %moreInfo;

foreach (qw(language author description)) {
if (my $value = $feed->{$_}) {
$moreInfo{$_} = $value;
}
}

$cache->set('podcast_moreInfo_' . $feed->{url}, \%moreInfo);
_precacheShowDetails($feed->{url}, $feed);
}

push @$items, { name => cstring($client, 'EMPTY') } if !scalar @$items;
Expand Down Expand Up @@ -322,6 +312,29 @@ sub searchHandler {
)->get($url, @$headers);
}

sub _precacheShowDetails {
my ($url, $feed) = @_;

if (my $image = $feed->{image}) {
$cache->set('podcast-rss-' . $url, $image, '90days');
}
else {
# always cache image to avoid sending a flood of requests
$cache->set('podcast-rss-' . $url, __PACKAGE__->_pluginDataFor('icon'), '1days');
}

# pre-cache some additional information to be shown in feed info menu
my %moreInfo;

foreach (qw(language author description)) {
if (my $value = $feed->{$_}) {
$moreInfo{$_} = $value;
}
}

$cache->set('podcast_moreInfo_' . $url, \%moreInfo);
}

sub registerProvider {
my ($class, $force) = @_;

Expand Down Expand Up @@ -417,6 +430,15 @@ sub showInfo {
$name = $client->pluginData('showName');
}

if (ref $url || $url !~ /^http/) {
return Slim::Control::XMLBrowser::cliQuery('podcastinfo', {
name => $name,
items => [{
name => $name
}]
}, $request);
}

my $menuTitle = cstring($client, 'PLUGIN_PODCAST_SUBSCRIBE', Slim::Utils::Unicode::utf8decode($name));
my $menuAction = 'addshow';

Expand Down

0 comments on commit 78176cb

Please sign in to comment.