Get the list of videos from YouTube

@param string $channelId
@throws \Mcfedr\YouTube\LiveStreamsBundle\Exception\MissingChannelIdException
@return array
554700
public function getStreams($channelId = null)
    {
        if (!$channelId) {
            $channelId = $this->channelId;
        }

        if (!$channelId) {
            throw new MissingChannelIdException("You must specify the channel id");
        }

        if ($this->cache) {
            $data = $this->cache->fetch($this->getCacheKey($channelId));
            if ($data !== false) {
                return $data;
            }
        }

        $searchResponse = $this->client->get(
            'search',
            [
                'query' => [
                    'part' => 'id',
                    'channelId' => $channelId,
                    'eventType' => 'live',
                    'type' => 'video',
                    'maxResults' => 50
                ]
            ]
        );

        $searchData = json_decode($searchResponse->getBody()->getContents(), true);

        $videosResponse = $this->client->get(
            'videos',
            [
                'query' => [
                    'part' => 'id,snippet,liveStreamingDetails',
                    'id' => implode(
                        ',',
                        array_map(
                            function ($video) {
                                return $video['id']['videoId'];
                            },
                            $searchData['items']
                        )
                    )
                ]
            ]
        );

        $videosData = json_decode($videosResponse->getBody()->getContents(), true);

        $streams = array_map(
            function ($video) {
                return [
                    'name' => $video['snippet']['title'],
                    'thumb' => $video['snippet']['thumbnails']['high']['url'],
                    'videoId' => $video['id']
                ];
            },
            array_values(
                array_filter(
                    $videosData['items'],
                    function ($video) {
                        return !isset($video['liveStreamingDetails']['actualEndTime']);
                    }
                )
            )
        );

        if ($this->cache && $this->cacheTimeout > 0) {
            $this->cache->save($this->getCacheKey($channelId), $streams, $this->cacheTimeout);
        }

        return $streams;
    }
744744
public function getChildById($processId)
    {
        if (false === $this->hasChildById($processId)) {
            throw new MissingChildException('The child process does not exist');
        }

        return $this->children->get($processId)->get();
    }
975032
public function getUploads($maxResults=50)
	{
		$channelsResponse = $this->youtube->channels->listChannels('contentDetails', array(
			'mine' => 'true',
		));

		foreach ($channelsResponse['items'] as $channel)
		{
			$uploadsListId = $channel['contentDetails']['relatedPlaylists']['uploads'];

			$playlistItemsResponse = $this->youtube->playlistItems->listPlaylistItems('snippet', array(
																									'playlistId' => $uploadsListId,
																									'maxResults' => $maxResults
																								));

			$items = [];
			foreach ($playlistItemsResponse['items'] as $playlistItem) 
			{
				$video = [];
				$video['videoId'] 		= $playlistItem['snippet']['resourceId']['videoId'];
				$video['title'] 		= $playlistItem['snippet']['title'];
				$video['publishedAt'] 	= $playlistItem['snippet']['publishedAt'];

				array_push($items, $video);
			}
		}

		return $items;
	}
1110782
public function parseStreamMap($video_html, $video_id)
    {
        $stream_map = array();
        $result = array();

        // http://stackoverflow.com/questions/35608686/how-can-i-get-the-actual-video-url-of-a-youtube-live-stream
        if (preg_match('@url_encoded_fmt_stream_map["\']:\s*["\']([^"\'\s]*)@', $video_html, $matches)) {
            $stream_map = $matches[1];
        } else {

            $gvi = $this->curl("https://www.youtube.com/get_video_info?el=embedded&eurl=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D" . urlencode($video_id) . "&video_id={$video_id}");

            if (preg_match('@url_encoded_fmt_stream_map=([^\&\s]+)@', $gvi, $matches_gvi)) {
                $stream_map = urldecode($matches_gvi[1]);
            }
        }

        if ($stream_map) {
            $parts = explode(",", $stream_map);

            foreach ($parts as $p) {
                $query = str_replace('\u0026', '&', $p);
                parse_str($query, $arr);

                $result[] = $arr;
            }

            return $result;
        }

        // TODO:
        // elseif (strpos($html, 'player-age-gate-content') !== false) { // age-gate
        // youtube must have changed something
        return $result;
    }
215769
public function findPageUidsWithContentsFromPid(int $pageId) : array
    {
        $queryBuilder = $this->getQueryBuilder();
        $queryBuilder->getRestrictions()->removeAll();
        $queryBuilder->getRestrictions()->add(GeneralUtility::makeInstance(DeletedRestriction::class));

        $queryBuilder
            ->select('uid')
            ->from($this->table)
            ->add('where',
                $queryBuilder->expr()->eq('content_from_pid', $queryBuilder->createNamedParameter($pageId, \PDO::PARAM_INT))
            );

        $this->addDefaultLanguageUidConstraint($queryBuilder);

        return $queryBuilder->execute()->fetchAll();
    }
805956
public function getDownloadLinks($video_id, $selector = false)
    {
        // you can input HTML of /watch? page directory instead of id
        $video_id = $this->extractVideoId($video_id);

        $video_html = $this->curl("https://www.youtube.com/watch?v={$video_id}");

        $result = array();
        $url_map = $this->parseStreamMap($video_html, $video_id);

        foreach ($url_map as $arr) {
            $url = $arr['url'];

            if (isset($arr['sig'])) {
                $url = $url . '&signature=' . $arr['sig'];

            } elseif (isset($arr['signature'])) {
                $url = $url . '&signature=' . $arr['signature'];

            } elseif (isset($arr['s'])) {

                $signature = $this->decodeSignature($arr['s'], $video_html);
                $url = $url . '&signature=' . $signature;
            }

            // redirector.googlevideo.com
            //$url = preg_replace('@(\/\/)[^\.]+(\.googlevideo\.com)@', '$1redirector$2', $url);

            $itag = $arr['itag'];
            $format = isset($this->itag_info[$itag]) ? $this->itag_info[$itag] : 'Unknown';

            $result[$itag] = array(
                'url' => $url,
                'format' => $format
            );
        }

        // do we want all links or just select few?
        if ($selector) {
            return $this->selectFirst($result, $selector);
        }

        return $result;
    }
1234931
public function getAllVideos()
    {
        $videos = new ArrayList();
        if ($this->hasHeroVideo()) {
            $videos->push($this->HeroVideo());
        }
        if ($this->hasGalleryVideos()) {
            $videos->merge($this->VideoGallery());
        }
        $videos->removeDuplicates('HailID');

        return $videos;
    }
414243
public function getEvents($brandId = null)
    {
        $params = array(
            'method' => 'sp.event.get_list'
        );

        if (strlen($brandId) > 0) {
            $params['brand_id'] = $brandId;
        }

        return $this->_makeApiRequest($params);
    }
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;
    }
21192
def by_youtube_id(cls, youtube_id):
        
        qset = cls.objects.filter(
            encoded_videos__profile__profile_name='youtube',
            encoded_videos__url=youtube_id
        ).prefetch_related('encoded_videos', 'courses')
        return qset
1326501
public function actionCreateVideo($id)
    {
        $video_gallery = $this->findModel($id);

        $model = $this->module->manager->createVideoGalleryItem(['scenario' => 'create']);

        $model->loadDefaultValues();

        if ($model->load(\Yii::$app->request->post())) {
            $model->video_gallery_id = $video_gallery->id;
            if($model->create()) {
                \Yii::$app->getSession()->setFlash('video_gallery.success', \Yii::t('video_gallery', 'Video has been created'));
                return $this->redirect(['videos', 'id' => $id]);
            }
        }

        return $this->render('video/create', [
            'video_gallery' => $video_gallery,
            'model' => $model
        ]);
    }
576346
public function channelVideos($channel, $options = [])
    {
        $availableOptions = ['limit', 'offset', 'broadcasts', 'hls'];

        return $this->sendRequest('GET', 'channels/'.$channel.'/videos', false, $options, $availableOptions);
    }
233900
public function findByFolderId($folderId)
    {
        $qb = $this->createQueryBuilder();

        $qb->field('mediaFolder.id')->equals($folderId);

        return $qb->getQuery()->execute();
    }
720893
public function getAvailableRelatedContentAction($productId, $folderId)
    {
        $result = array();

        $folders = FolderQuery::create()->filterById($folderId)->find();

        if ($folders !== null) {
            $list = ContentQuery::create()
                ->joinWithI18n($this->getCurrentEditionLocale())
                ->filterByFolder($folders, Criteria::IN)
                ->filterById(ProductAssociatedContentQuery::create()->filterByProductId($productId)->select('content_id')->find(), Criteria::NOT_IN)
                ->find();
            ;

            if ($list !== null) {
                /** @var Content $item */
                foreach ($list as $item) {
                    $result[] = array('id' => $item->getId(), 'title' => $item->getTitle());
                }
            }
        }

        return $this->jsonResponse(json_encode($result));
    }
667481
public function getSiteWidePluginsList($siteId)
    {
        $queryBuilder = $this->_em->createQueryBuilder();
        $queryBuilder->select('partial site.{siteId}, plugins')
            ->from(\Rcm\Entity\Site::class, 'site')
            ->join('site.sitePlugins', 'plugins')
            ->where('site.siteId = :siteId')
            ->setParameter('siteId', $siteId);

        $result = $queryBuilder->getQuery()->getSingleResult(
            \Doctrine\ORM\Query::HYDRATE_ARRAY
        );

        if (empty($result) || empty($result['sitePlugins'])) {
            return [];
        }

        return $result['sitePlugins'];
    }
275350
public function getRedirectEntityList($siteId)
    {
        try {
            $result = $this->getRedirectQuery($siteId)->getResult();
        } catch (NoResultException $e) {
            $result = [];
        }

        return $result;
    }
84076
public function getChannelList()
    {
        $entityList = $this->_getEntityList('Channels');
        $result = [];

        foreach ($entityList as $channel) {
            $result[] = Channel::createFromOptions($channel);
        }

        return $result;
    }