Commit | Line | Data |
---|---|---|
bed05b1a | 1 | <?php\r |
16889626 JC |
2 | \r |
3 | const DATE_FORM = 'm/d/Y';\r | |
4 | \r | |
bed05b1a | 5 | \r |
16889626 | 6 | function parseEpisodePage(DomNodeList $divs): array {\r |
bed05b1a JC |
7 | $episodePage = [];\r |
8 | foreach ($divs as $div) {\r | |
9 | if ($div->hasAttribute('class') && $div->getAttribute('class') === 'episode-music') {\r | |
bed05b1a JC |
10 | $songs = [];\r |
11 | foreach ($div->childNodes as $row) {\r | |
12 | $children = $row->childNodes[0]->childNodes;\r | |
13 | $songs[] = [\r | |
14 | 'title' => $children[0]->nodeValue,\r | |
15 | 'artist' => $children[1]->nodeValue\r | |
16 | ];\r | |
17 | }\r | |
bed05b1a JC |
18 | $episodePage[] = $songs;\r |
19 | }\r | |
20 | \r | |
21 | }\r | |
22 | \r | |
23 | return $episodePage;\r | |
24 | \r | |
16889626 JC |
25 | }\r |
26 | \r | |
27 | /**\r | |
28 | * Go through the DOM elements provided and pull out the Dates of all marketplace\r | |
29 | * pod episodes in the provided list.\r | |
30 | * \r | |
31 | * @param DomNodeList $headers The elements with a header tag from the DOM\r | |
32 | * @param DateTime $lastDate The date of the most recent episode from the DB\r | |
33 | */\r | |
34 | function parseEpisodeDate(DomNodeList $headers, DateTime $lastDate): array {\r | |
35 | $episodeDates = [];\r | |
36 | foreach ($headers as $header) {\r | |
37 | if ($header->hasAttribute('class') && $header->getAttribute('class') === 'river--hed') {\r | |
38 | $dateStringParts = explode('/', explode(':', $header->nodeValue)[0]);\r | |
39 | if ( strlen($dateStringParts[2]) === 2 ) {\r | |
40 | $dateStringParts[2] = '20' . $dateStringParts[2];\r | |
41 | }\r | |
42 | $episodeDate = DateTime::createFromFormat(DATE_FORM, implode("/", $dateStringParts));\r | |
43 | if ($episodeDate < $lastDate) {\r | |
44 | break;\r | |
45 | }\r | |
46 | $episodeDates[] = $episodeDate;\r | |
47 | }\r | |
48 | }\r | |
49 | return $episodeDates;\r | |
bed05b1a | 50 | } |