get-iplayer / get_iplayer

A utility for downloading TV and radio programmes from BBC iPlayer and BBC Sounds
https://github.com/get-iplayer/get_iplayer/wiki
GNU General Public License v3.0
2.12k stars 230 forks source link

Fix unneeded schedule downloads with refresh limit #349

Closed welwood08 closed 6 years ago

welwood08 commented 6 years ago

As mentioned here, when refresh limit is not a multiple of 7 days and depending on the current day, an unnecessary extra schedule page before the limit might be downloaded for each channel. Clamping to Mondays prevents this.

Tested on FreeBSD and Windows using get_iplayer --refresh --refresh-limit 30 confirming that 2017/w50, 2017/w51, 2017/w52, 2018/w01 and this_week schedules are downloaded and 2017/w49 are not.

dinkypumpkin commented 6 years ago

Thanks for the PR. There is a slightly simpler way to do this with Time::Piece:

my $timepiece = gmtime($limit);
my $stop = gmtime($now);
while ( $timepiece->week != $stop->week ) {
    ...
}
welwood08 commented 6 years ago

Silly me, that is much more obvious! I assume you can easily commit that yourself, closing.