Programming Language PHP

Namespace Instagram\Model

Class Media

Method/Function setDisplaySrc

Total Examples 2

2 code examples of PHP Instagram\Model\Media::setDisplaySrc extracted from open source projects

Was this example useful?
0
                                                    /**
     * @return Media|MediaDetailed
     */
    public function mediaBaseHydrator(Media $media, \StdClass $node): Media
    {
        $media->setId((int) $node->id);
        $media->setShortCode($node->shortcode);
        if (property_exists($node, '__typename')) {
            $media->setTypeName($node->__typename);
        }

        if ($node->edge_media_to_caption->edges) {
            $media->setCaption($node->edge_media_to_caption->edges[0]->node->text);
            $media->setHashtags(InstagramHelper::buildHashtags($node->edge_media_to_caption->edges[0]->node->text));
        }

        $media->setHeight($node->dimensions->height);
        $media->setWidth($node->dimensions->width);

        $thumbnailSrc = property_exists($node, 'thumbnail_src') ? $node->thumbnail_src : $node->display_url;

        $media->setThumbnailSrc($thumbnailSrc);
        $media->setDisplaySrc($node->display_url);

        $date = new \DateTime();
        $date->setTimestamp($node->taken_at_timestamp);

        $media->setDate($date);

        if (property_exists($node, 'edge_media_to_comment')) {
            $commentsCount = $node->edge_media_to_comment->count;
        } else {
            $commentsCount = $node->edge_media_to_parent_comment->count;
        }

        $media->setComments($commentsCount);
        $media->setLikes($node->edge_media_preview_like->count);

        $media->setLink(InstagramHelper::URL_BASE . "p/{$node->shortcode}/");

        $thumbNails = [];
        if (property_exists($node, 'thumbnail_resources')) {
            $thumbNails = $node->thumbnail_resources;
        }

        $media->setThumbnails($thumbNails);

        if (isset($node->location)) {
            $media->setLocation($node->location);
        }

        $media->setVideo((bool) $node->is_video);

        if (property_exists($node, 'video_url')) {
            $media->setVideoUrl($node->video_url);
        }

        if (property_exists($node, 'video_view_count')) {
            $media->setVideoViewCount((int) $node->video_view_count);
        }

        if (property_exists($node, 'accessibility_caption')) {
            $media->setAccessibilityCaption($node->accessibility_caption);
        }

        if (property_exists($node, 'product_type')) {
            $media->setIgtv($node->product_type === 'igtv');
        }

        if (property_exists($node, 'owner')) {
            $media->setOwnerId((int) $node->owner->id);
        }

        return $media;
    }
                                            
Was this example useful?
0
                                                    /**
     * @return Media|MediaDetailed
     * @throws InstagramFetchException
     */
    public function mediaBaseHydrator(Media $media, \StdClass $node): Media
    {
        $media->setId((int) $node->pk);
        $media->setShortCode($node->code);

        $media->setTypeName($this->getTypeName($node->media_type));

        if ($node->caption) {
            $media->setCaption($node->caption->text);
            $media->setHashtags(InstagramHelper::buildHashtags($node->caption->text));

            $date = new \DateTime();
            $date->setTimestamp($node->caption->created_at);

            $media->setDate($date);
        } else {
            if ($node->taken_at) {
                $date = new \DateTime();
                $date->setTimestamp($node->taken_at);
                $media->setDate($date);
            }
        }

        $thumbnailSrc = $displaySrc = '';
        if (property_exists($node, 'image_versions2')) {
            foreach ($node->image_versions2->candidates as $img) {
                if ($img->width == 640) {
                    $thumbnailSrc = $img->url;
                }

                if ($img->width == $node->original_width) {
                    $displaySrc = $img->url;
                }
            }
        }

        $media->setThumbnailSrc($thumbnailSrc);
        $media->setDisplaySrc($displaySrc);

        $media->setComments($node->comment_count);
        $media->setLikes($node->like_count);

        $media->setLink(InstagramHelper::URL_BASE . "p/{$node->code}/");

        if (isset($node->location)) {
            $media->setLocation($node->location);
        }

        $media->setVideo($this->isVideo($node));

        if (property_exists($node, 'video_versions')) {
            foreach ($node->video_versions as $video) {
                if ($video->type == 101) {
                    $videoSrc = $video->url;
                }
            }
            $media->setVideoUrl($videoSrc ?? null);
        }

        if (property_exists($node, 'view_count')) {
            $media->setVideoViewCount((int) $node->view_count);
        }

        if (property_exists($node, 'product_type')) {
            $media->setIgtv($node->product_type === 'igtv');
        }

        $media->setOwnerId((int) $node->user->pk);

        return $media;
    }