Skip to content

Commit f73bddd

Browse files
committed
repaired series/brand downloading for CBeebies/CBBC programmes
Was broken by changes to iPlayer page structure Closes #441 Closes #442
1 parent 46135c6 commit f73bddd

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

get_iplayer

+19-14
Original file line numberDiff line numberDiff line change
@@ -5644,17 +5644,22 @@ sub fetch_episodes_recursive {
56445644
$title =~ s/^BBC[-\s]+[^-]+[-\s]+//g;
56455645
$title =~ s/[-\s]+[^-]+[-\s]+BBC$//g;
56465646
}
5647-
my @episodes = $dom->findnodes('//div[@data-pid]');
5647+
my @episodes = $dom->findnodes('//*[@data-pid]');
56485648
if ( @episodes ) {
56495649
for my $episode ( @episodes ) {
56505650
my $pid = $episode->findvalue('@data-pid');
56515651
next unless $pid;
56525652
next if $seen{$pid};
56535653
$seen{$pid} = 1;
5654-
my $prog_episode = $episode->findvalue('.//span[contains(@class,"programme__title")]/span');
5655-
my $name2 = $episode->findvalue('.//span[contains(@class,"programme__subtitle")]');
5654+
my $prog_episode;
5655+
my $name2;
5656+
my @prog_titles = $episode->findnodes('.//*[contains(@class,"programme__titles")]');
5657+
for my $prog_title ( @prog_titles ) {
5658+
$prog_episode = $prog_title->findvalue('.//*[contains(@class,"programme__title")]');
5659+
$name2 = $prog_title->findvalue('.//*[contains(@class,"programme__subtitle")]');
5660+
}
56565661
my $prog_name = $name2 ? "$title: $name2" : $title;
5657-
my $prog_desc = $episode->findvalue('.//p[contains(@class,"programme__synopsis")]/span');
5662+
my $prog_desc = $episode->findvalue('.//*[contains(@class,"programme__synopsis")]/*');
56585663
unless ( $name2 ) {
56595664
if ( $prog_episode =~ s/((?:Series|Cyfres) \d+(\s+Reversions)?)[, :]+// ) {
56605665
$prog_name .= ": $1";
@@ -5664,7 +5669,7 @@ sub fetch_episodes_recursive {
56645669
}
56655670
}
56665671
unless ( $last_page ) {
5667-
$last_page = $dom->findvalue('//li[contains(@class,"pagination__page--last")]/a');
5672+
$last_page = $dom->findvalue('//*[contains(@class,"pagination__page--last")]//a');
56685673
}
56695674
last unless $last_page;
56705675
$last_page =~ s/(^\s+|\s+$)//g;
@@ -5687,16 +5692,16 @@ sub fetch_episodes_recursive {
56875692
last unless $html;
56885693
my $dom = XML::LibXML->load_html(string => $html, recover => 1, suppress_errors => 1);
56895694
if ( ! $check_series_nav ) {
5690-
my @hrefs = $dom->findnodes('//nav[contains(@class,"series-nav")]/ul/li/a/@href');
5695+
my @hrefs = $dom->findnodes('//*[contains(@class,"series-nav")]//a/@href');
56915696
push @urls, "https://www.bbc.co.uk".$_->findvalue('.') for @hrefs;
56925697
$has_series_nav = @hrefs;
56935698
$check_series_nav = 1;
56945699
}
56955700
unless ( $channel ) {
5696-
$channel = $dom->findvalue('//div[contains(@class,"hero-header__label")]');
5701+
$channel = $dom->findvalue('//*[contains(@class,"hero-header__label")]');
56975702
}
56985703
unless ( $title ) {
5699-
$title = $dom->findvalue('//h1[contains(@class,"hero-header__title")]');
5704+
$title = $dom->findvalue('//*[contains(@class,"hero-header__title")]');
57005705
unless ( $title ) {
57015706
$title = $dom->findvalue('//title');
57025707
}
@@ -5705,18 +5710,18 @@ sub fetch_episodes_recursive {
57055710
$title =~ s/^BBC[-\s]+[^-]+[-\s]+//g;
57065711
$title =~ s/[-\s]+[^-]+[-\s]+BBC$//g;
57075712
}
5708-
my @episodes = $dom->findnodes('//div[contains(@class,"list__grid")]/ul/li');
5713+
my $name2 = $dom->findvalue('//*[contains(@class,"series-nav")]//*[contains(@class,"series-nav__button--active")]/*');
5714+
my @episodes = $dom->findnodes('//*[contains(@class,"list__grid")]//*[contains(@class,"grid__item")]');
57095715
if ( @episodes ){
57105716
for my $episode ( @episodes ) {
5711-
my $item = $episode->findvalue('.//div[contains(@class,"content-item")]/a/@href');
5717+
my $item = $episode->findvalue('.//a[contains(@class,"content-item-root")]/@href');
57125718
my $pid = $1 if $item =~ m{/episode/([a-z0-9]+)};
57135719
next unless $pid;
57145720
next if $seen{$pid};
57155721
$seen{$pid} = 1;
5716-
my $prog_episode = $episode->findvalue('.//div[contains(@class,"content-item__title")]');
5717-
my $name2 = $episode->findvalue('.//div[contains(@class,"content-item__title")]/span[1]');
5722+
my $prog_episode = $episode->findvalue('.//*[contains(@class,"content-item-root__meta--with-label")]');
57185723
my $prog_name = $name2 ? "$title: $name2" : $title;
5719-
my $prog_desc = $episode->findvalue('.//div[contains(@class,"content-item__info__secondary")]/div[contains(@class,"content-item__description")]');
5724+
my $prog_desc = $episode->findvalue('.//*[contains(@class,"content-item-root__meta-label")][1]');
57205725
unless ( $name2 ) {
57215726
if ( $prog_episode =~ s/((?:Series|Cyfres) \d+(\s+Reversions)?)[, :]+// ) {
57225727
$prog_name .= ": $1";
@@ -5726,7 +5731,7 @@ sub fetch_episodes_recursive {
57265731
}
57275732
}
57285733
unless ( $last_page ) {
5729-
$last_page = $dom->findvalue('//div[contains(@class,"list__pagination")]//ol[contains(@class,"pagination__list")]/li[contains(@class,"pagination__number")][last()]//a/span/span[1]');
5734+
$last_page = $dom->findvalue('//*[contains(@class,"list__pagination")]//*[contains(@class,"pagination__list")]//*[contains(@class,"pagination__number")][last()]//*[contains(@class,"button__text")]/*[1]');
57305735
}
57315736
last unless $last_page;
57325737
$last_page =~ s/(^\s+|\s+$)//g;

0 commit comments

Comments
 (0)