PHP code example of aronpc / youtube-comments

1. Go to this page and download the library: Download aronpc/youtube-comments library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

aronpc / youtube-comments example snippets


use AronPC\YouTubeComments\Facades\YouTubeComments;

// Fetch comments from a YouTube video
$commentsFile = YouTubeComments::fetchComments('dQw4w9WgXcQ');

// Fetch live chat from a YouTube video
$liveChatFile = YouTubeComments::fetchLiveChat('dQw4w9WgXcQ');

// Fetch both comments and live chat
$results = YouTubeComments::fetchCommentsAndLiveChat('dQw4w9WgXcQ');
$commentsFile = $results['comments'];
$liveChatFile = $results['livechat'];

// Download comments only (returns path to JSON file)
$jsonFile = YouTubeComments::downloadComments('dQw4w9WgXcQ');

// Parse comments from a JSON file
$outputFile = YouTubeComments::parseComments('dQw4w9WgXcQ', $jsonFile);

return [
    // Directory where downloaded comments and live chat messages will be saved
    'output_directory' => env('YOUTUBE_COMMENTS_OUTPUT_DIR', storage_path('app/youtube-comments')),

    // Path to the youtube-dl or yt-dlp executable
    'youtube_dl_path' => env('YOUTUBE_DL_PATH', 'yt-dlp'),

    // Maximum time (in seconds) to wait for a command to complete
    'command_timeout' => env('YOUTUBE_COMMENTS_TIMEOUT', 300),
];
bash
   php artisan vendor:publish --provider="AronPC\YouTubeComments\YouTubeCommentsServiceProvider" --tag="config"
   
bash
php artisan youtube:fetch-comments VIDEO_ID
bash
php artisan youtube:fetch-comments dQw4w9WgXcQ
bash
php artisan youtube:fetch-livechat VIDEO_ID
bash
php artisan youtube:download-comments VIDEO_ID
bash
php artisan youtube:parse-comments VIDEO_ID
bash
  php artisan youtube:fetch-comments -- -6oKXN8D6BI