X-Git-Url: https://git.jacobcasper.com/?p=Marketplaylister.git;a=blobdiff_plain;f=mpfuncs.php;h=051619a1dedcb87339dbb391ef4258352d2b11a5;hp=a35c89f3b61a4810751542f96836e4be20672b9c;hb=168896268ee9a19bce7125b029a37c34437aeb52;hpb=bed05b1a3c4b40cb71564fbebb2cb41242163dbd diff --git a/mpfuncs.php b/mpfuncs.php index a35c89f..051619a 100644 --- a/mpfuncs.php +++ b/mpfuncs.php @@ -1,12 +1,12 @@ hasAttribute('class') && $div->getAttribute('class') === 'episode-music') { - if (!$numDays) { - break; - } $songs = []; foreach ($div->childNodes as $row) { $children = $row->childNodes[0]->childNodes; @@ -15,7 +15,6 @@ 'artist' => $children[1]->nodeValue ]; } - $numDays--; $episodePage[] = $songs; } @@ -23,4 +22,29 @@ return $episodePage; + } + + /** + * Go through the DOM elements provided and pull out the Dates of all marketplace + * pod episodes in the provided list. + * + * @param DomNodeList $headers The elements with a header tag from the DOM + * @param DateTime $lastDate The date of the most recent episode from the DB + */ + function parseEpisodeDate(DomNodeList $headers, DateTime $lastDate): array { + $episodeDates = []; + foreach ($headers as $header) { + if ($header->hasAttribute('class') && $header->getAttribute('class') === 'river--hed') { + $dateStringParts = explode('/', explode(':', $header->nodeValue)[0]); + if ( strlen($dateStringParts[2]) === 2 ) { + $dateStringParts[2] = '20' . $dateStringParts[2]; + } + $episodeDate = DateTime::createFromFormat(DATE_FORM, implode("/", $dateStringParts)); + if ($episodeDate < $lastDate) { + break; + } + $episodeDates[] = $episodeDate; + } + } + return $episodeDates; } \ No newline at end of file