diff --git a/src/Domain/Calendar/PostProcess/Season2024PostProcessor.php b/src/Domain/Calendar/PostProcess/Season2024PostProcessor.php index 6631dd0..0e6a375 100644 --- a/src/Domain/Calendar/PostProcess/Season2024PostProcessor.php +++ b/src/Domain/Calendar/PostProcess/Season2024PostProcessor.php @@ -14,6 +14,7 @@ use nicoSWD\IfscCalendar\Domain\Round\IFSCRoundProviderInterface; use nicoSWD\IfscCalendar\Domain\Round\IFSCRoundStatus; use nicoSWD\IfscCalendar\Domain\Schedule\IFSCSchedule; +use nicoSWD\IfscCalendar\Domain\Stream\LiveStream; final readonly class Season2024PostProcessor { @@ -21,6 +22,7 @@ private const string WUJIAN_POSTER_URL = 'https://res.dasheng.top/227/pro/ctms_tool/20240323/jpg/d7f6d496a71d4dc785c8d0e51169d17b.jpg'; private const int OLYMPIC_QUALIFIERS_SHANGHAI_ID = 1384; private const string OLYMPIC_QUALIFIERS_SHANGHAI_INFO_SHEET = 'https://images.ifsc-climbing.org/ifsc/image/private/t_q_good/prd/yg3cqznmay12orsv9hpa.pdf'; + private const string OLYMPIC_QUALIFIERS_SHANGHAI_LIVE_STREAM = 'https://olympics.com/en/sport-events/olympic-qualifier-series-2024-shanghai/broadcasting-schedule'; public function __construct( private IFSCRoundProviderInterface $roundProvider, @@ -72,6 +74,7 @@ private function fetchOlympicQualifiersShanghaiRounds(IFSCEvent $event): array startTime: $schedule->startsAt, endTime: $schedule->endsAt, status: IFSCRoundStatus::PROVISIONAL, + liveStream: new LiveStream(self::OLYMPIC_QUALIFIERS_SHANGHAI_LIVE_STREAM), ); } diff --git a/src/Domain/Round/IFSCRoundFactory.php b/src/Domain/Round/IFSCRoundFactory.php index cce7a37..0141105 100644 --- a/src/Domain/Round/IFSCRoundFactory.php +++ b/src/Domain/Round/IFSCRoundFactory.php @@ -31,9 +31,13 @@ public function create( DateTimeImmutable $startTime, ?DateTimeImmutable $endTime, IFSCRoundStatus $status, + ?LiveStream $liveStream = null, ): IFSCRound { $tags = $this->getTags($roundName); - $liveStream = $this->findLiveStream($event, $roundName); + + if (!$liveStream) { + $liveStream = $this->findLiveStream($event, $roundName); + } if ($liveStream->scheduledStartTime) { $youTubeStartTime = $this->buildStartTime($liveStream, $event); diff --git a/src/Infrastructure/Schedule/HTMLNormalizer.php b/src/Infrastructure/Schedule/HTMLNormalizer.php index 6f5308b..bc0fa75 100644 --- a/src/Infrastructure/Schedule/HTMLNormalizer.php +++ b/src/Infrastructure/Schedule/HTMLNormalizer.php @@ -12,7 +12,7 @@ public function normalize(string $html): string { $html = str_replace(["<br/>", "<b> </b>"], ["\n", ''], $html); - $html = preg_replace(['~<([ai])\s?[^>]*>.*?</\\1>~', '~<(?:img|hr)[^>]+>~'], '', $html); + $html = preg_replace(['~<(a)\s?[^>]*>.*?</a>~', '~<(?:img|hr)[^>]+>~'], '', $html); $html = str_replace(["–", "–"], "-", $html); $html = str_replace(" ", " ", $html); $html = preg_replace("~,\s+20\d\d~", '', $html); @@ -24,7 +24,7 @@ public function normalize(string $html): string $html, ); $html = html_entity_decode($html); - $offset = $this->cutOffOffset2($html); + $offset = $this->cutOffOffset($html); $html = substr($html, $offset); $lines = preg_split('~\n~', $html, -1, PREG_SPLIT_NO_EMPTY); $lines = array_map('trim', $lines); @@ -42,17 +42,6 @@ public function normalizeTime(string $schedule): string return preg_replace('~(\d\d:\d\d)\s*\n(\d\d:\d\d)\s*~', "\$1 - \$2\n", $schedule); } - private function cutOffOffset2(string $html): int - { - $pos = strpos($html, 'PROGRAMME'); - - if ($pos === false) { - $pos = strpos($html, 'Schedule'); - } - - return $pos ?: 0; - } - private function fixOqsShanghai(string $html): string { // Remove line-break @@ -62,6 +51,20 @@ private function fixOqsShanghai(string $html): string $html ); + // Fix round names + $html = preg_replace_callback( + '~(?<category>Women|Men)\'s Boulder & Lead Final - <i>(?<discipline>Boulder|Lead) stage</i>~', + static fn (array $matches): string => sprintf("%s's %s Final", $matches['category'], $matches['discipline']), + $html, + ); + + // Fix round name + $html = str_replace( + 'followed by <b>Men’s Speed Qualification </b>', + "<b>Women's & Men's Speed Qualification", + $html + ); + // Re-order lines return preg_replace_callback( '~(([^\n]+\n){2})(<b>(?:Thursday|Friday) 1\d May\s*[^\n]+\n)~', diff --git a/tests/unit/Infrastructure/Schedule/PDFScheduleProviderTest.php b/tests/unit/Infrastructure/Schedule/PDFScheduleProviderTest.php index e3b2f38..1654e22 100644 --- a/tests/unit/Infrastructure/Schedule/PDFScheduleProviderTest.php +++ b/tests/unit/Infrastructure/Schedule/PDFScheduleProviderTest.php @@ -274,7 +274,7 @@ final class PDFScheduleProviderTest extends TestCase $this->assertSameDate("2024-05-17T10:00:00+08:00", $schedule[1]->startsAt); $this->assertNull($schedule[1]->endsAt); - $this->assertSame("Men's Speed Qualification", $schedule[2]->name); + $this->assertSame("Men's & Women's Speed Qualification", $schedule[2]->name); $this->assertSameDate("2024-05-17T16:50:00+08:00", $schedule[2]->startsAt); $this->assertNull($schedule[2]->endsAt); @@ -290,17 +290,21 @@ final class PDFScheduleProviderTest extends TestCase $this->assertSameDate("2024-05-18T17:00:00+08:00", $schedule[5]->startsAt); $this->assertNull($schedule[5]->endsAt); - $this->assertSame("Men's Boulder & Lead Final", $schedule[6]->name); + $this->assertSame("Men's Boulder Final", $schedule[6]->name); $this->assertSameDate("2024-05-18T10:00:00+08:00", $schedule[6]->startsAt); $this->assertNull($schedule[6]->endsAt); - $this->assertSame("Men's Boulder & Lead Final", $schedule[7]->name); + $this->assertSame("Men's Lead Final", $schedule[7]->name); $this->assertSameDate("2024-05-18T12:05:00+08:00", $schedule[7]->startsAt); $this->assertNull($schedule[7]->endsAt); - $this->assertSame("Women's Boulder & Lead Final", $schedule[8]->name); + $this->assertSame("Women's Boulder Final", $schedule[8]->name); $this->assertSameDate("2024-05-19T15:25:00+08:00", $schedule[8]->startsAt); $this->assertNull($schedule[8]->endsAt); + + $this->assertSame("Women's Lead Final", $schedule[9]->name); + $this->assertSameDate("2024-05-19T17:30:00+08:00", $schedule[9]->startsAt); + $this->assertNull($schedule[9]->endsAt); } private function assertSameDate(string $expected, DateTimeImmutable $actual): void