Skip to content

Commit

Permalink
[InstagramBridge] Remove redundant data collection for sidecar and vi…
Browse files Browse the repository at this point in the history
…deo (#1920)

getInstagramSidecarData and getInstagramVideoData were unnecessarily calling getSinglePostData to retrieve data already present in collectData's call of getInstagramJSON. getSinglePostData sometimes doesn't retrieve data properly resulting in incomplete post information. Since the information needed is already present, pass it from collectData instead, eliminating the redundant data collection and improving reliability.
  • Loading branch information
JimDog546 authored Jan 10, 2021
1 parent 1edec1a commit 5ed1619
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions bridges/InstagramBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function collectData(){

switch($media->__typename) {
case 'GraphSidecar':
$data = $this->getInstagramSidecarData($item['uri'], $item['title']);
$data = $this->getInstagramSidecarData($item['uri'], $item['title'], $media, $textContent);
$item['content'] = $data[0];
$item['enclosures'] = $data[1];
break;
Expand All @@ -142,7 +142,7 @@ public function collectData(){
$item['enclosures'] = array($mediaURI);
break;
case 'GraphVideo':
$data = $this->getInstagramVideoData($item['uri'], $mediaURI);
$data = $this->getInstagramVideoData($item['uri'], $mediaURI, $media, $textContent);
$item['content'] = $data[0];
if($directLink) {
$item['enclosures'] = $data[1];
Expand All @@ -160,11 +160,7 @@ public function collectData(){
}

// returns Sidecar(a post which has multiple media)'s contents and enclosures
protected function getInstagramSidecarData($uri, $postTitle) {
$mediaInfo = $this->getSinglePostData($uri);

$textContent = $this->getTextContent($mediaInfo);

protected function getInstagramSidecarData($uri, $postTitle, $mediaInfo, $textContent) {
$enclosures = array();
$content = '';
foreach($mediaInfo->edge_sidecar_to_children->edges as $singleMedia) {
Expand All @@ -187,10 +183,7 @@ protected function getInstagramSidecarData($uri, $postTitle) {
}

// returns Video post's contents and enclosures
protected function getInstagramVideoData($uri, $mediaURI) {
$mediaInfo = $this->getSinglePostData($uri);

$textContent = $this->getTextContent($mediaInfo);
protected function getInstagramVideoData($uri, $mediaURI, $mediaInfo, $textContent) {
$content = '<video controls>';
$content .= '<source src="' . $mediaInfo->video_url . '" poster="' . $mediaURI . '" type="video/mp4">';
$content .= '<img src="' . $mediaURI . '" alt="">';
Expand Down

0 comments on commit 5ed1619

Please sign in to comment.