@@ -14,6 +14,10 @@ class Media extends AbstractModel
14
14
const TYPE_VIDEO = 'video ' ;
15
15
const TYPE_SIDECAR = 'sidecar ' ;
16
16
const TYPE_CAROUSEL = 'carousel ' ;
17
+
18
+ const MEDIA_TYPE_IMAGE = 1 ;
19
+ const MEDIA_TYPE_VIDEO = 2 ;
20
+ const MEDIA_TYPE_CAROUSEL = 8 ;
17
21
18
22
/**
19
23
* @var string
@@ -197,6 +201,8 @@ class Media extends AbstractModel
197
201
* @var array
198
202
*/
199
203
protected $ taggedUsersIds =[];
204
+
205
+ private $ media_type ;
200
206
201
207
/**
202
208
* @param string $code
@@ -587,7 +593,6 @@ protected function initPropertiesCustom($value, $prop, $arr)
587
593
$ this ->commentsDisabled = $ value ;
588
594
break ;
589
595
case 'comments ' :
590
- $ this ->commentsCount = $ arr [$ prop ]['count ' ];
591
596
break ;
592
597
case 'edge_liked_by ' :
593
598
case 'edge_media_preview_like ' :
@@ -637,7 +642,7 @@ protected function initPropertiesCustom($value, $prop, $arr)
637
642
}
638
643
break ;
639
644
case 'caption ' :
640
- $ this ->caption = $ arr [ $ prop ] ;
645
+ $ this ->caption = $ value [ ' text ' ] ?? '' ;
641
646
break ;
642
647
case 'accessibility_caption ' :
643
648
$ this ->altText = $ value ;
@@ -666,10 +671,10 @@ protected function initPropertiesCustom($value, $prop, $arr)
666
671
break ;
667
672
case 'location ' :
668
673
if (isset ($ arr [$ prop ])) {
669
- $ this ->locationId = $ arr [$ prop ]['id ' ] ? $ arr [ $ prop ][ ' id ' ] : null ;
670
- $ this ->locationName = $ arr [$ prop ]['name ' ] ? $ arr [ $ prop ][ ' name ' ] : null ;
671
- $ this ->locationSlug = $ arr [$ prop ]['slug ' ] ? $ arr [ $ prop ][ ' slug ' ] : null ;
672
- $ this ->locationAddressJson = isset ( $ arr [$ prop ]['address_json ' ]) ? $ arr [ $ prop ][ ' address_json ' ] : null ;
674
+ $ this ->locationId = $ arr [$ prop ]['id ' ] ?? null ;
675
+ $ this ->locationName = $ arr [$ prop ]['name ' ] ?? null ;
676
+ $ this ->locationSlug = $ arr [$ prop ]['slug ' ] ?? null ;
677
+ $ this ->locationAddressJson = $ arr [$ prop ]['address_json ' ] ?? null ;
673
678
}
674
679
break ;
675
680
case 'owner ' :
@@ -684,6 +689,7 @@ protected function initPropertiesCustom($value, $prop, $arr)
684
689
case 'video_url ' :
685
690
$ this ->videoStandardResolutionUrl = $ value ;
686
691
break ;
692
+ case 'view_count ' :
687
693
case 'video_view_count ' :
688
694
$ this ->videoViews = $ value ;
689
695
break ;
@@ -777,6 +783,57 @@ protected function initPropertiesCustom($value, $prop, $arr)
777
783
}
778
784
}
779
785
break ;
786
+ case 'comment_count ' :
787
+ $ this ->commentsCount = $ value ;
788
+ break ;
789
+ case 'media_type ' :
790
+ $ this ->media_type = $ value ;
791
+ switch ($ value ){
792
+ case static ::MEDIA_TYPE_IMAGE :
793
+ $ this ->type = static ::TYPE_IMAGE ;
794
+ break ;
795
+ case static ::MEDIA_TYPE_VIDEO :
796
+ $ this ->type = static ::TYPE_VIDEO ;
797
+ break ;
798
+ case static ::MEDIA_TYPE_CAROUSEL :
799
+ $ this ->type = static ::TYPE_CAROUSEL ;
800
+ break ;
801
+ }
802
+ break ;
803
+ case 'image_versions2 ' :
804
+ foreach ($ value ['candidates ' ] as $ media ) {
805
+ $ mediasUrl [] = $ media ['url ' ];
806
+ switch ($ media ['width ' ]) {
807
+ case 150 :
808
+ $ this ->imageThumbnailUrl = $ media ['url ' ];
809
+ break ;
810
+ case 320 :
811
+ $ this ->imageLowResolutionUrl = $ media ['url ' ];
812
+ break ;
813
+ case 750 :
814
+ $ this ->imageStandardResolutionUrl = $ media ['url ' ];
815
+ break ;
816
+ case 1080 :
817
+ $ this ->imageHighResolutionUrl = $ media ['url ' ];
818
+ break ;
819
+ }
820
+ }
821
+ break ;
822
+ case 'video_versions ' :
823
+ foreach ($ value as $ media ) {
824
+ switch ($ media ['type ' ]) {
825
+ case 101 :
826
+ $ this ->videoStandardResolutionUrl = $ media ['url ' ];
827
+ break ;
828
+ case 102 :
829
+ $ this ->videoLowResolutionUrl = $ media ['url ' ];
830
+ break ;
831
+ case 103 :
832
+ $ this ->videoLowBandwidthUrl = $ media ['url ' ];
833
+ break ;
834
+ }
835
+ }
836
+ break ;
780
837
}
781
838
if (!$ this ->ownerId && !is_null ($ this ->owner )) {
782
839
$ this ->ownerId = $ this ->getOwner ()->getId ();
@@ -793,25 +850,76 @@ protected function initPropertiesCustom($value, $prop, $arr)
793
850
private static function setCarouselMedia ($ mediaArray , $ carouselArray , $ instance )
794
851
{
795
852
$ carouselMedia = new CarouselMedia ();
796
- $ carouselMedia ->setType ($ carouselArray ['type ' ]);
797
-
798
- if (isset ($ carouselArray ['images ' ])) {
799
- $ carouselImages = self ::getImageUrls ($ carouselArray ['images ' ]['standard_resolution ' ]['url ' ]);
800
- $ carouselMedia ->setImageLowResolutionUrl ($ carouselImages ['low ' ]);
801
- $ carouselMedia ->setImageThumbnailUrl ($ carouselImages ['thumbnail ' ]);
802
- $ carouselMedia ->setImageStandardResolutionUrl ($ carouselImages ['standard ' ]);
803
- $ carouselMedia ->setImageHighResolutionUrl ($ carouselImages ['high ' ]);
804
- }
853
+ if (isset ($ carouselArray ['type ' ])) {
854
+ $ carouselMedia ->setType ($ carouselArray ['type ' ]);
855
+
856
+ if (isset ($ carouselArray ['images ' ])) {
857
+ $ carouselImages = self ::getImageUrls ($ carouselArray ['images ' ]['standard_resolution ' ]['url ' ]);
858
+ $ carouselMedia ->setImageLowResolutionUrl ($ carouselImages ['low ' ]);
859
+ $ carouselMedia ->setImageThumbnailUrl ($ carouselImages ['thumbnail ' ]);
860
+ $ carouselMedia ->setImageStandardResolutionUrl ($ carouselImages ['standard ' ]);
861
+ $ carouselMedia ->setImageHighResolutionUrl ($ carouselImages ['high ' ]);
862
+ }
805
863
806
- if ($ carouselMedia ->getType () === self ::TYPE_VIDEO ) {
807
- if (isset ($ mediaArray ['video_views ' ])) {
808
- $ carouselMedia ->setVideoViews ($ carouselArray ['video_views ' ]);
864
+ if ($ carouselMedia ->getType () === self ::TYPE_VIDEO ) {
865
+ if (isset ($ mediaArray ['video_views ' ])) {
866
+ $ carouselMedia ->setVideoViews ($ carouselArray ['video_views ' ]);
867
+ }
868
+ if (isset ($ carouselArray ['videos ' ])) {
869
+ $ carouselMedia ->setVideoLowResolutionUrl ($ carouselArray ['videos ' ]['low_resolution ' ]['url ' ]);
870
+ $ carouselMedia ->setVideoStandardResolutionUrl ($ carouselArray ['videos ' ]['standard_resolution ' ]['url ' ]);
871
+ $ carouselMedia ->setVideoLowBandwidthUrl ($ carouselArray ['videos ' ]['low_bandwidth ' ]['url ' ]);
872
+ }
873
+ }
874
+ } elseif (isset ($ carouselArray ['media_type ' ])) {
875
+ switch ($ carouselArray ['media_type ' ]){
876
+ case static ::MEDIA_TYPE_IMAGE :
877
+ $ carouselMedia ->setType (static ::TYPE_IMAGE );
878
+ break ;
879
+ case static ::MEDIA_TYPE_VIDEO :
880
+ $ carouselMedia ->setType (static ::TYPE_VIDEO );
881
+ break ;
809
882
}
810
- if (isset ($ carouselArray ['videos ' ])) {
811
- $ carouselMedia ->setVideoLowResolutionUrl ($ carouselArray ['videos ' ]['low_resolution ' ]['url ' ]);
812
- $ carouselMedia ->setVideoStandardResolutionUrl ($ carouselArray ['videos ' ]['standard_resolution ' ]['url ' ]);
813
- $ carouselMedia ->setVideoLowBandwidthUrl ($ carouselArray ['videos ' ]['low_bandwidth ' ]['url ' ]);
883
+
884
+ if ($ carouselArray ['media_type ' ] == static ::MEDIA_TYPE_VIDEO && isset ($ carouselArray ['video_versions ' ])){
885
+ if (isset ($ mediaArray ['view_count ' ])) {
886
+ $ carouselMedia ->setVideoViews ($ carouselArray ['view_count ' ]);
887
+ }
888
+
889
+ foreach ($ carouselArray ['video_versions ' ] as $ media ) {
890
+ switch ($ media ['type ' ]) {
891
+ case 101 :
892
+ $ carouselMedia ->setVideoStandardResolutionUrl ($ media ['url ' ]);
893
+ break ;
894
+ case 102 :
895
+ $ carouselMedia ->setVideoLowResolutionUrl ($ media ['url ' ]);
896
+ break ;
897
+ case 103 :
898
+ $ carouselMedia ->setVideoLowBandwidthUrl ($ media ['url ' ]);
899
+ break ;
900
+ }
901
+ }
814
902
}
903
+
904
+ if ($ carouselArray ['media_type ' ] == static ::MEDIA_TYPE_IMAGE && isset ($ carouselArray ['image_versions2 ' ])){
905
+ foreach ($ carouselArray ['image_versions2 ' ]['candidates ' ] as $ media ) {
906
+ $ mediasUrl [] = $ media ['url ' ];
907
+ switch ($ media ['width ' ]) {
908
+ case 150 :
909
+ $ carouselMedia ->setImageThumbnailUrl ($ media ['url ' ]);
910
+ break ;
911
+ case 320 :
912
+ $ carouselMedia ->setImageLowResolutionUrl ($ media ['url ' ]);
913
+ break ;
914
+ case 750 :
915
+ $ carouselMedia ->setImageStandardResolutionUrl ($ media ['url ' ]);
916
+ break ;
917
+ case 1080 :
918
+ $ carouselMedia ->setImageHighResolutionUrl ($ media ['url ' ]);
919
+ break ;
920
+ }
921
+ }
922
+ }
815
923
}
816
924
array_push ($ instance ->carouselMedia , $ carouselMedia );
817
925
return $ mediaArray ;
0 commit comments