4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

laravel 7.15 で youtube の RSS を取得しようぜ

Last updated at Posted at 2020-10-07

インストールするよ


composer require vedmant/laravel-feed-reader

ちなみに、
composer require awjudd/feed-reader はインスコできなかった。

コントローラーで使うよ

HogeController.php

use FeedReader;//classの最上部に
$tmp = FeedReader::read('https://www.youtube.com/feeds/videos.xml?channel_id=UCZf__ehlCEBPop-_sldpBUQ');


ヒカキンのRSS読み込みOK

解析開始

HogeController.php

//ひかきん
$tmp = FeedReader::read('https://www.youtube.com/feeds/videos.xml?channel_id=UCZf__ehlCEBPop-_sldpBUQ');


$data = $tmp->data['child']['http://www.w3.org/2005/Atom']['feed'][0]['child']['http://www.w3.org/2005/Atom']['entry'];

$res = [];
foreach ($data as $v) {

    $img = array_shift($v['child']['http://search.yahoo.com/mrss/']['group'][0]['child']['http://search.yahoo.com/mrss/']['thumbnail'][0]['attribs']);
    $title = $v['child']['http://www.w3.org/2005/Atom']['title'][0]['data'];
    $link = array_shift($v['child']['http://www.w3.org/2005/Atom']['link'][0]['attribs']);
    $updated = $v['child']['http://www.w3.org/2005/Atom']['updated'][0]['data'];

    $res[] = [
        'title' => $title,
        'img' => $img,
        'link' => $link,
        'updated' => $updated
    ];

            
}


print_r($res);

結果


Array
(
    [0] => Array
        (
            [title] => 【激辛ラーメン】蒙古タンメン中本を自宅で再現したらウマすぎ辛すぎw【ヒカキン&セイキン】
            [img] => Array
                (
                    [url] => https://i1.ytimg.com/vi/XXDofNaZUaM/hqdefault.jpg
                    [width] => 480
                    [height] => 360
                )

            [link] => Array
                (
                    [rel] => alternate
                    [href] => https://www.youtube.com/watch?v=XXDofNaZUaM
                )

            [updated] => 2020-10-04T10:16:03+00:00
        )

    [1] => Array
        (
            [title] => ヴィレヴァンで『この店で値段高いものTOP3全部ください!』って言ったらまさかの事態にwww【高額商品】
            [img] => Array
                (
                    [url] => https://i4.ytimg.com/vi/cAkA25csaJM/hqdefault.jpg
                    [width] => 480
                    [height] => 360
                )

            [link] => Array
                (
                    [rel] => alternate
                    [href] => https://www.youtube.com/watch?v=cAkA25csaJM
                )

            [updated] => 2020-10-02T11:03:51+00:00
        )

    [2] => Array
        (
            [title] => ブロックされたので本当に許さないことにしました。【悪質な詐欺・偽物・なりすましについて】
            [img] => Array
                (
                    [url] => https://i2.ytimg.com/vi/1WJYAHbrpGA/hqdefault.jpg
                    [width] => 480
                    [height] => 360
                )

            [link] => Array
                (
                    [rel] => alternate
                    [href] => https://www.youtube.com/watch?v=1WJYAHbrpGA
                )

            [updated] => 2020-09-30T09:33:26+00:00
        )


はい、OK!

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?