@@ -8,95 +8,95 @@ |
||
8 | 8 | class MysqlYouTubeRepository implements YouTubeRepositoryInterface |
9 | 9 | { |
10 | 10 | |
11 | - /** @var ConnectionLocator */ |
|
12 | - protected $connections; |
|
11 | + /** @var ConnectionLocator */ |
|
12 | + protected $connections; |
|
13 | 13 | |
14 | - /** |
|
15 | - * @param ConnectonLocator $connections |
|
16 | - */ |
|
17 | - public function __construct(ConnectionLocator $connections) |
|
18 | - { |
|
19 | - $this->connections = $connections; |
|
20 | - } |
|
14 | + /** |
|
15 | + * @param ConnectonLocator $connections |
|
16 | + */ |
|
17 | + public function __construct(ConnectionLocator $connections) |
|
18 | + { |
|
19 | + $this->connections = $connections; |
|
20 | + } |
|
21 | 21 | |
22 | - public function getYouTubes($limit = null, $offset = 0) |
|
23 | - { |
|
24 | - $query = " |
|
22 | + public function getYouTubes($limit = null, $offset = 0) |
|
23 | + { |
|
24 | + $query = " |
|
25 | 25 | SELECT `id`, `video_id`, `datetime` |
26 | 26 | FROM `jpemeric_stream`.`youtube` |
27 | 27 | ORDER BY `datetime` DESC"; |
28 | - if (!is_null($limit)) { |
|
29 | - $query .= " |
|
28 | + if (!is_null($limit)) { |
|
29 | + $query .= " |
|
30 | 30 | LIMIT {$offset}, {$limit}"; |
31 | - } |
|
31 | + } |
|
32 | 32 | |
33 | - return $this |
|
34 | - ->connections |
|
35 | - ->getRead() |
|
36 | - ->fetchAll($query); |
|
37 | - } |
|
33 | + return $this |
|
34 | + ->connections |
|
35 | + ->getRead() |
|
36 | + ->fetchAll($query); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param integer $id |
|
41 | - * |
|
42 | - * @return array|false |
|
43 | - */ |
|
44 | - public function getYouTubeById($id) |
|
45 | - { |
|
46 | - $query = " |
|
39 | + /** |
|
40 | + * @param integer $id |
|
41 | + * |
|
42 | + * @return array|false |
|
43 | + */ |
|
44 | + public function getYouTubeById($id) |
|
45 | + { |
|
46 | + $query = " |
|
47 | 47 | SELECT * |
48 | 48 | FROM `jpemeric_stream`.`youtube` |
49 | 49 | WHERE `id` = :id |
50 | 50 | LIMIT 1"; |
51 | - $bindings = [ |
|
52 | - 'id' => $id, |
|
53 | - ]; |
|
51 | + $bindings = [ |
|
52 | + 'id' => $id, |
|
53 | + ]; |
|
54 | 54 | |
55 | - return $this |
|
56 | - ->connections |
|
57 | - ->getRead() |
|
58 | - ->fetchOne($query, $bindings); |
|
59 | - } |
|
55 | + return $this |
|
56 | + ->connections |
|
57 | + ->getRead() |
|
58 | + ->fetchOne($query, $bindings); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @param string $title |
|
63 | - * |
|
64 | - * @return array|false |
|
65 | - */ |
|
66 | - public function getYouTubeByVideoId($videoId) |
|
67 | - { |
|
68 | - $query = " |
|
61 | + /** |
|
62 | + * @param string $title |
|
63 | + * |
|
64 | + * @return array|false |
|
65 | + */ |
|
66 | + public function getYouTubeByVideoId($videoId) |
|
67 | + { |
|
68 | + $query = " |
|
69 | 69 | SELECT * |
70 | 70 | FROM `jpemeric_stream`.`youtube` |
71 | 71 | WHERE `video_id` = :video_id |
72 | 72 | LIMIT 1"; |
73 | - $bindings = [ |
|
74 | - 'video_id' => $videoId, |
|
75 | - ]; |
|
73 | + $bindings = [ |
|
74 | + 'video_id' => $videoId, |
|
75 | + ]; |
|
76 | 76 | |
77 | - return $this |
|
78 | - ->connections |
|
79 | - ->getRead() |
|
80 | - ->fetchOne($query, $bindings); |
|
81 | - } |
|
77 | + return $this |
|
78 | + ->connections |
|
79 | + ->getRead() |
|
80 | + ->fetchOne($query, $bindings); |
|
81 | + } |
|
82 | 82 | |
83 | - public function insertVideo($videoId, DateTime $datetime, array $metadata) |
|
84 | - { |
|
85 | - $query = " |
|
83 | + public function insertVideo($videoId, DateTime $datetime, array $metadata) |
|
84 | + { |
|
85 | + $query = " |
|
86 | 86 | INSERT INTO `jpemeric_stream`.`youtube` |
87 | 87 | (`video_id`, `datetime`, `metadata`) |
88 | 88 | VALUES |
89 | 89 | (:video_id, :datetime, :metadata)"; |
90 | 90 | |
91 | - $bindings = [ |
|
92 | - 'video_id' => $videoId, |
|
93 | - 'datetime' => $datetime->format('Y-m-d H:i:s'), |
|
94 | - 'metadata' => json_encode($metadata), |
|
95 | - ]; |
|
91 | + $bindings = [ |
|
92 | + 'video_id' => $videoId, |
|
93 | + 'datetime' => $datetime->format('Y-m-d H:i:s'), |
|
94 | + 'metadata' => json_encode($metadata), |
|
95 | + ]; |
|
96 | 96 | |
97 | - return $this |
|
98 | - ->connections |
|
99 | - ->getWrite() |
|
100 | - ->perform($query, $bindings); |
|
101 | - } |
|
97 | + return $this |
|
98 | + ->connections |
|
99 | + ->getWrite() |
|
100 | + ->perform($query, $bindings); |
|
101 | + } |
|
102 | 102 | } |
@@ -4,6 +4,6 @@ |
||
4 | 4 | |
5 | 5 | interface YouTubeRepositoryInterface |
6 | 6 | { |
7 | - public function getYouTubeById($id); |
|
8 | - public function getYouTubeByVideoId($videoId); |
|
7 | + public function getYouTubeById($id); |
|
8 | + public function getYouTubeByVideoId($videoId); |
|
9 | 9 | } |
@@ -16,23 +16,23 @@ |
||
16 | 16 | $playlist = $client->getPlaylistItemsByPlaylistId($config->youtube->favorites_playlist, 10); |
17 | 17 | |
18 | 18 | foreach ($playlist as $playlistItem) { |
19 | - $datetime = new DateTime($playlistItem->snippet->publishedAt); |
|
20 | - if ($datetime <= $mostRecentVideoDateTime) { |
|
21 | - break; |
|
22 | - } |
|
23 | - |
|
24 | - $videoId = $playlistItem->contentDetails->videoId; |
|
25 | - $uniqueVideoCheck = $youTubeRepository->getYouTubeByVideoId($videoId); |
|
26 | - if ($uniqueVideoCheck !== false) { |
|
27 | - continue; |
|
28 | - } |
|
29 | - |
|
30 | - $datetime->setTimezone($container['default_timezone']); |
|
31 | - $metadata = json_decode(json_encode($playlistItem), true); |
|
32 | - |
|
33 | - $youTubeRepository->insertVideo( |
|
34 | - $videoId, |
|
35 | - $datetime, |
|
36 | - $metadata |
|
37 | - ); |
|
19 | + $datetime = new DateTime($playlistItem->snippet->publishedAt); |
|
20 | + if ($datetime <= $mostRecentVideoDateTime) { |
|
21 | + break; |
|
22 | + } |
|
23 | + |
|
24 | + $videoId = $playlistItem->contentDetails->videoId; |
|
25 | + $uniqueVideoCheck = $youTubeRepository->getYouTubeByVideoId($videoId); |
|
26 | + if ($uniqueVideoCheck !== false) { |
|
27 | + continue; |
|
28 | + } |
|
29 | + |
|
30 | + $datetime->setTimezone($container['default_timezone']); |
|
31 | + $metadata = json_decode(json_encode($playlistItem), true); |
|
32 | + |
|
33 | + $youTubeRepository->insertVideo( |
|
34 | + $videoId, |
|
35 | + $datetime, |
|
36 | + $metadata |
|
37 | + ); |
|
38 | 38 | } |