gumphp/parse-video

A PHP library to parse video information from various Chinese social media platforms

Installs: 6

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/gumphp/parse-video

v1.0.3 2025-11-07 01:53 UTC

This package is auto-updated.

Last update: 2025-11-07 02:01:02 UTC


README

A PHP library to parse video information from various Chinese social media platforms. This is the PHP equivalent of the popular Python parse-video-py library.

Features

  • Parse video information from 20+ Chinese social media platforms
  • Extract direct video URLs, thumbnails, titles, and author information
  • Support for both video and image album parsing where applicable
  • Modern PHP 8.1+ with strict typing
  • PSR-4 autoloading and composer support
  • Built with Guzzle HTTP client for reliable requests

Supported Platforms

  • Douyin (抖音) - including image albums and Live Photos
  • Kuaishou (快手)
  • Weibo (微博) - including image albums
  • Bilibili (哔哩哔哩)
  • Xiaohongshu (小红书)
  • PiPiXia (皮皮虾)
  • WeiShi (微视)
  • LvZhou (绿洲)
  • ZuiYou (最右)
  • QuanMin (度小视/原 全民小视频)
  • XiGua (西瓜视频)
  • LiShiPin (梨视频)
  • PiPiGaoXiao (皮皮搞笑)
  • HuYa (虎牙)
  • AcFun (A站)
  • DouPai (逗拍)
  • MeiPai (美拍)
  • QuanMinKGe (全民K歌)
  • SixRoom (六间房)
  • XinPianChang (新片场)
  • HaoKan (好看视频)

Installation

composer require gumphp/parse-video

Requirements

  • PHP >= 8.1
  • ext-json
  • ext-curl
  • guzzlehttp/guzzle

Usage

Basic Usage

<?php

require_once 'vendor/autoload.php';

use GumPHP\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";
}

Check if URL is Supported

$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";
}

Get All Supported Sources

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

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

Data Structures

VideoInfo

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
}

VideoAuthor

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

ImgInfo (for Image Albums)

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

Error Handling

The library throws specific exceptions for different error conditions:

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();
}

Development

Running Tests

composer test

Static Analysis

composer analyse

Architecture

The library follows a modular architecture similar to the Python version:

  • VideoParser - Main service class for parsing URLs
  • BaseParser - Abstract base class for platform-specific parsers
  • Platform Parsers - Individual parser classes for each platform
  • Models - Data classes for video information, author info, etc.
  • Enums - Enumerations for video sources
  • Exceptions - Custom exception classes

Adding New Platforms

  1. Create a new parser class extending BaseParser
  2. Add the source to the VideoSource enum
  3. Update the parser mapping in VideoParser.php
  4. Implement the required parseShareUrl() and parseVideoId() methods

Example:

<?php

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
    }
}

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Acknowledgments

This library is heavily inspired by and aims to provide PHP equivalent functionality to the parse-video-py Python library.