|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* (c) Christian Gripp <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Core23\LastFm\Crawler; |
|
11
|
|
|
|
|
12
|
|
|
use Symfony\Component\DomCrawler\Crawler; |
|
13
|
|
|
|
|
14
|
|
|
final class EventInfoCrawler extends AbstractCrawler |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* Get all event information. |
|
18
|
|
|
* |
|
19
|
|
|
* @param int $id |
|
20
|
|
|
* |
|
21
|
|
|
* @return array|null |
|
22
|
|
|
*/ |
|
23
|
|
|
public function getEventInfo(int $id): ? array |
|
24
|
|
|
{ |
|
25
|
|
|
$node = $this->crawlEvent($id); |
|
26
|
|
|
|
|
27
|
|
|
if (null === $node) { |
|
28
|
|
|
return null; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
$timeNode = $node->filter('.qa-event-date'); |
|
32
|
|
|
|
|
33
|
|
|
return array( |
|
34
|
|
|
'title' => $this->parseString($node->filter('h1.header-title')), |
|
35
|
|
|
'image' => $this->parseImage($node->filter('.event-poster-preview')), |
|
36
|
|
|
'festival' => $node->filter('.namespace--events_festival_overview')->count() > 0, |
|
37
|
|
|
'startDate' => $this->parseDate($timeNode->filter('[itemprop="startDate"]')), |
|
38
|
|
|
'endDate' => $this->parseDate($timeNode->filter('[itemprop="endDate"]')), |
|
39
|
|
|
'description' => $this->parseString($node->filter('.qa-event-description'), true), |
|
40
|
|
|
'website' => $this->parseString($node->filter('.qa-event-link a')), |
|
41
|
|
|
'url' => $this->parseUrl($node->filter('link[rel="canonical"]')), |
|
42
|
|
|
'eventId' => $id, |
|
43
|
|
|
'venue' => $this->readVenues($node), |
|
44
|
|
|
'bands' => $this->readBands($node), |
|
45
|
|
|
); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param Crawler $node |
|
50
|
|
|
* |
|
51
|
|
|
* @return array |
|
52
|
|
|
*/ |
|
53
|
|
|
private function readBands(Crawler $node) : array |
|
54
|
|
|
{ |
|
55
|
|
|
$bandNode = $node->filter('.grid-items'); |
|
56
|
|
|
|
|
57
|
|
|
return $bandNode->filter('.grid-items-item')->each(function (Crawler $node): array { |
|
58
|
|
|
return array( |
|
59
|
|
|
'image' => $this->parseImage($node->filter('.grid-items-cover-image-image img')), |
|
60
|
|
|
'name' => $this->parseString($node->filter('.grid-items-item-main-text')), |
|
61
|
|
|
'url' => $this->parseUrl($node->filter('.grid-items-item-main-text a')), |
|
62
|
|
|
); |
|
63
|
|
|
}); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param Crawler $node |
|
68
|
|
|
* |
|
69
|
|
|
* @return array |
|
70
|
|
|
*/ |
|
71
|
|
|
private function readVenues(Crawler $node): array |
|
72
|
|
|
{ |
|
73
|
|
|
$venueNode = $node->filter('.event-detail'); |
|
74
|
|
|
$addressNode = $venueNode->filter('.event-detail-address'); |
|
75
|
|
|
|
|
76
|
|
|
return array( |
|
77
|
|
|
'name' => $this->parseString($venueNode->filter('[itemprop="name"]')), |
|
78
|
|
|
'telephone' => $this->parseString($venueNode->filter('.event-detail-tel span')), |
|
79
|
|
|
'url' => $this->parseUrl($venueNode->filter('.event-detail-web a')), |
|
80
|
|
|
'address' => array( |
|
81
|
|
|
'streetAddress' => $this->parseString($addressNode->filter('[itemprop="streetAddress"]')), |
|
82
|
|
|
'addressLocality' => $this->parseString($addressNode->filter('[itemprop="addressLocality"]')), |
|
83
|
|
|
'postalCode' => $this->parseString($addressNode->filter('[itemprop="postalCode"]')), |
|
84
|
|
|
'addressCountry' => $this->parseString($addressNode->filter('[itemprop="addressCountry"]')), |
|
85
|
|
|
), |
|
86
|
|
|
); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @param int $id |
|
91
|
|
|
* |
|
92
|
|
|
* @return Crawler|null |
|
93
|
|
|
*/ |
|
94
|
|
|
private function crawlEvent(int $id): ? Crawler |
|
95
|
|
|
{ |
|
96
|
|
|
$url = 'http://www.last.fm/de/event/'.$id; |
|
97
|
|
|
|
|
98
|
|
|
return $this->crawl($url); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|