File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed
src/Sseffa/VideoApi/Services Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change 11<?php namespace Sseffa \VideoApi \Services ;
22
3+ use DateTimeImmutable ;
4+ use DateInterval ;
5+
36/**
47 * Youtube
58 *
@@ -59,7 +62,7 @@ public function getVideoDetail($id)
5962 'description ' => $ data ->items [0 ]->snippet ->description ,
6063 'thumbnail_small ' => $ data ->items [0 ]->snippet ->thumbnails ->default ->url ,
6164 'thumbnail_large ' => $ data ->items [0 ]->snippet ->thumbnails ->high ->url ,
62- 'duration ' => $ data ->items [0 ]->contentDetails ->duration ,
65+ 'duration ' => static :: _convert_time ( $ data ->items [0 ]->contentDetails ->duration ) ,
6366 'upload_date ' => $ data ->items [0 ]->snippet ->publishedAt ,
6467 'like_count ' => isset ($ data ->items [0 ]->statistics ->likeCount ) ? $ data ->items [0 ]->statistics ->likeCount : 0 ,
6568 'view_count ' => isset ($ data ->items [0 ]->statistics ->viewCount ) ? $ data ->items [0 ]->statistics ->viewCount : 0 ,
@@ -179,5 +182,17 @@ public static function _parse_url_query($url)
179182
180183 return $ params ;
181184 }
182- }
183185
186+ /**
187+ * Parse the YouTube timestamp to seconds
188+ * @param string $time YouTube format timestamp
189+ * @return integer Seconds
190+ */
191+ public static function _convert_time ($ time )
192+ {
193+ $ reference = new DateTimeImmutable ;
194+ $ endTime = $ reference ->add (new DateInterval ($ time ));
195+
196+ return $ endTime ->getTimestamp () - $ reference ->getTimestamp ();
197+ }
198+ }
You can’t perform that action at this time.
0 commit comments