PHP code example of gumphp / parse-video

1. Go to this page and download the library: Download gumphp/parse-video 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/ */

    

gumphp / parse-video example snippets




umPHP\VideoParser\VideoParser;
use GumPHP\VideoParser\Enum\VideoSource;

$parser = new VideoParser();

// Parse from share URL
try {
    $videoInfo = $parser->parseShareUrl('https://v.douyin.com/abc123');

    echo "Video URL: " . $videoInfo->getVideoUrl() . "\n";
    echo "Cover URL: " . $videoInfo->getCoverUrl() . "\n";
    echo "Title: " . $videoInfo->getTitle() . "\n";
    echo "Author: " . $videoInfo->getAuthor()->getName() . "\n";

    // For image albums
    foreach ($videoInfo->getImages() as $image) {
        echo "Image URL: " . $image->getUrl() . "\n";
        if ($image->getLivePhotoUrl()) {
            echo "Live Photo URL: " . $image->getLivePhotoUrl() . "\n";
        }
    }
} catch (\Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}

// Parse from video ID
try {
    $videoInfo = $parser->parseVideoId(VideoSource::DOUYIN, 'abc123');
    // ... same usage as above
} catch (\Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}

$parser = new VideoParser();

if ($parser->isUrlSupported('https://v.douyin.com/abc123')) {
    echo "URL is supported!\n";
}

$source = $parser->detectVideoSource('https://v.douyin.com/abc123');
if ($source) {
    echo "Detected source: " . $source->value . "\n";
}

$parser = new VideoParser();
$sources = $parser->getSupportedSources();

foreach ($sources as $source => $domains) {
    echo "Source: {$source}, Domains: " . implode(', ', $domains) . "\n";
}

class VideoInfo
{
    public string $videoUrl;      // Direct video URL
    public string $coverUrl;      // Video thumbnail
    public string $title;         // Video title
    public string $musicUrl;      // Background music URL
    public array $images;         // Array of ImgInfo for image albums
    public VideoAuthor $author;   // Author information
}

class VideoAuthor
{
    public string $uid;      // Author ID
    public string $name;     // Author name
    public string $avatar;   // Author avatar URL
}

class ImgInfo
{
    public string $url;            // Image URL
    public string $livePhotoUrl;   // Live Photo video URL (if available)
}

use GumPHP\VideoParser\Exception\ParseException;
use GumPHP\VideoParser\Exception\UnsupportedSourceException;

try {
    $videoInfo = $parser->parseShareUrl($url);
} catch (UnsupportedSourceException $e) {
    // URL is from an unsupported platform
    echo "Unsupported platform: " . $e->getMessage();
} catch (ParseException $e) {
    // Parsing failed (video not found, API changed, etc.)
    echo "Parsing failed: " . $e->getMessage();
} catch (\Exception $e) {
    // Other errors (network issues, etc.)
    echo "Error: " . $e->getMessage();
}



namespace GumPHP\VideoParser\Parser;

use GumPHP\VideoParser\Exception\ParseException;
use GumPHP\VideoParser\Model\VideoInfo;

class NewPlatform extends BaseParser
{
    public function parseShareUrl(string $shareUrl): VideoInfo
    {
        // Implementation here
    }

    public function parseVideoId(string $videoId): VideoInfo
    {
        // Implementation here
    }
}
bash
composer analyse