Return cached youtube video API data or fetch if not cached
@param string $videoId
@param bool $dl
@return null|\stdClass https://developers.google.com/youtube/v3/docs/search#resource
334555
protected function _cache($videoId, $dl = false)
    {
        if ((!array_key_exists($videoId, static::$_cachedVideoData) || $dl)) {
            if ($videoId) {
                $videoData = BlockVideoCache::where('videoId', '=', $videoId)->first() ?: new BlockVideoCache;
                if (!$videoData->exists() || $dl) {
                    if ($videoInfo = $this->_dl('videos', ['id' => $videoId, 'part' => 'id,snippet'])) {
                        $videoData->videoId = $videoId;
                        $videoData->videoInfo = serialize($videoInfo);
                        $videoData->save();
                    }
                } else {
                    $videoInfo = unserialize($videoData->videoInfo);
                }
            } else {
                $videoInfo = null;
            }
            static::$_cachedVideoData[$videoId] = $videoInfo;
        }
        return static::$_cachedVideoData[$videoId];
    }
758151
public function regenerateVideoPreview (string $id)
    {
        $resource = HCResources::findOrFail ($id);

        //TODO check if resource is video

        $storagePath = storage_path ('app/');
        $previewPath = str_replace ('-', '/', $resource->id);

        if (file_exists($storagePath . 'video-previews/'. $previewPath))
            removeDirectory ($storagePath . 'video-previews/'. $previewPath);

        if (file_exists($storagePath . 'cache/' . $previewPath))
            removeDirectory ($storagePath  . 'cache/' . $previewPath);

        $this->generateVideoPreview ($resource, $storagePath, $previewPath);

        return ["success" => true];
    }
1066128
public function getData($cacheId)
    {
        if (!isset($this->data[$cacheId])) {
            $this->data[$cacheId] = $this->loadData($cacheId);
        }

        return $this->data[$cacheId];
    }
215933
public function getShowByTvdbId($tvdbId)
  {
    $response = $this->request('/GetShowByTVDBID/' . $tvdbId);
    if ( $response->response->status == 'false' )
      return null;
    $show     = $this->formatShow($response->response);

    return $show;
  }
473376
public function openidVideo($media_id = '', $openids = [], $title = '', $description = '')
    {
        $queryStr                      = [];
        $queryStr['touser']            = $openids;
        $queryStr['video']['media_id'] = $media_id;

        if (!empty($title)) {
            $queryStr['video']['title'] = $title;
        }

        if (!empty($description)) {
            $queryStr['video']['description'] = $description;
        }

        $queryStr['msgtype'] = 'video';

        $this->module = 'message';

        $res = $this->_post('mass/send', $queryStr);

        return $res;
    }
397478
public function getVideoRawData($id)
    {
        $this->setId($id);

        $data = $this->getData(str_replace('{key}', $this->key, $this->baseVideoUrl));

        if(isset($data->error))
        {
            throw new \Exception("Video not found");
        }

        return $data;
    }
1170885
public ResultList<Video> getSeasonVideos(int tvID, int seasonNumber, String language) throws MovieDbException {
        return tmdbSeasons.getSeasonVideos(tvID, seasonNumber, language);
    }
768394
public static function fetch_subscription_cache($forumid, $userid) {
        if (isset(self::$forumcache[$userid]) && isset(self::$forumcache[$userid][$forumid])) {
            return self::$forumcache[$userid][$forumid];
        }
        self::fill_subscription_cache($forumid, $userid);

        if (!isset(self::$forumcache[$userid]) || !isset(self::$forumcache[$userid][$forumid])) {
            return false;
        }

        return self::$forumcache[$userid][$forumid];
    }
823977
def last_video(self):
        """"""
        if self._cached_videos is None:
            self.make_video_cache()

        if self._cached_videos:
            return self._cached_videos[0]
        return None
1318521
public function actionUpdateVideo($id)
    {
        $model = $this->module->manager->findVideoGalleryItemById($id);
        if ($model === null) {
            throw new NotFoundHttpException('The requested video does not exist');
        }
        $model->scenario = 'update';

        $video_gallery = $this->findModel($model->video_gallery_id);

        if ($model->load(\Yii::$app->request->post()) && $model->save()) {
            if(\Yii::$app->request->get('returnUrl')){
                $back = urldecode(\Yii::$app->request->get('returnUrl'));
                return $this->redirect($back);
            }

            \Yii::$app->getSession()->setFlash('video_gallery.success', \Yii::t('video_gallery', 'Video has been updated'));
            return $this->refresh();
        }

        return $this->render('video/update', [
            'model' => $model,
            'video_gallery' => $video_gallery
        ]);
    }
1333752
public function getVideoList($id)
    {
        $this->setId($id);

        $list = array();
        $data = $this->getData(str_replace('{key}', $this->key, $this->baseChannelUrl));

        if(!isset($data->items))
        {
            throw new \Exception("Video channel not found");
        }

        foreach($data->items as $value)
        {
            $list[] = $this->getVideoDetail($value->contentDetails->videoId);
        }

        return $list;
    }
619253
public function fetchPermanentVideo ($mediaID, $into = null)
    {
        $stream = $this->doPermanentFetchToStream($mediaID, null);
        $json = json_decode(stream_get_contents($stream));

        $body = $this->client->send(
            new Request(
                'GET',
                $json->down_url
            ),
            [
                RequestOptions::SINK => $this->createWritableStream($into),
            ]
        )->getBody();
        if ($body->isSeekable()) {
            $body->seek(0);
        }

        return (new Downloaded\Video($mediaID, $body->detach()))
            ->withTitle($json->title)
            ->withDescription($json->description);
    }
414935
public function getVideoList($id)
    {

        $this->setId($id);

        $list = array();
        $data = $this->getData($this->baseChannelUrl);

        if(!$data) {
            throw new \Exception("Video channel not found");
        }

        foreach ($data as $value) {
            $list[$value->id] = array(
                'id'              => $value->id,
                'title'           => $value->title,
                'description'     => $value->description,
                'thumbnail_small' => $value->thumbnail_small,
                'thumbnail_large' => $value->thumbnail_large,
                'duration'        => $value->duration,
                'upload_date'     => $value->upload_date,
                'like_count'      => isset($value->stats_number_of_likes) ? $value->stats_number_of_likes : 0,
                'view_count'      => isset($value->stats_number_of_plays) ? $value->stats_number_of_plays : 0,
                'comment_count'   => isset($value->stats_number_of_comments) ? $value->stats_number_of_comments : 0
            );
        }
        return $list;
    }
333382
function getVideos(auth, youtube, channel_id, count, callback) {
  youtube.search.list( // Call the Youtube API
  {
    auth: auth,
    part: "snippet",
    order: "date",
    maxResults : count, //integer 0-50, default 5
    channelId: channel_id
  },
  function(err, res) {
    if (err) {
      console.log("The API returned an error: " + err);
    } else {
      if (res.data.items !== undefined) { // Check if a result was found
        getVideoStatistics(auth, youtube, res.data.items, count, callback); // Get video statistics
      } else {
        callback([]);
      }
    }
  });
}
939043
async function fetchDetails(id, fetch, gAuthKey) {
  try {
    const res = await fetch(
      `https://www.googleapis.com/youtube/v3/videos?id=${id}&key=${gAuthKey}&part=snippet,statistics`
    )
    const data = await res.json()
    return data.items[0]
  } catch (e) {
    console.log(e)
    return {}
  }
}
903072
public function getVideoId($url)
    {
        // looks like there are, now let's only do this for YouTube and Vimeo
        if($this->getInfo($url)->type == 'video' && ($this->isYouTube($url) || $this->isVimeo($url)))
        {
            if ($this->isYouTube($url))
            {
                return $this->getYouTubeId($url);
            }
            else if ($this->isVimeo($url))
            {
                return $this->getVimeoId($url);
            }
        }
        else
        {
            // return empty string
            return '';
        }
    }
806246
public function delete($video_id)
	{
		$accessToken = $this->client->getAccessToken();

		if (is_null($accessToken))
		{
			throw new \Exception('You need an access token to delete.');
		}

		// Attempt to refresh the access token if it's expired and save the new one in the database
		if ($this->client->isAccessTokenExpired())
		{
			$accessToken = json_decode($accessToken);
			$refreshToken = $accessToken->refresh_token;
			$this->client->refreshToken($refreshToken);
			$newAccessToken = $this->client->getAccessToken();
			$this->saveAccessTokenToDB($newAccessToken);
		}

		$result = $this->youtube->videos->delete($video_id);

		if (!$result)
		{
			throw new \Exception("Couldn't delete the video from the youtube account.");
		}

		return $result->getId();

	}