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.
- 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
- 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 (好看视频)
composer require gumphp/parse-video- PHP >= 8.1
- ext-json
- ext-curl
- guzzlehttp/guzzle
<?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";
}$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)
}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();
}composer testcomposer analyseThe 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
- Create a new parser class extending
BaseParser - Add the source to the
VideoSourceenum - Update the parser mapping in
VideoParser.php - Implement the required
parseShareUrl()andparseVideoId()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
}
}MIT License
Contributions are welcome! Please feel free to submit a Pull Request.
This library is heavily inspired by and aims to provide PHP equivalent functionality to the parse-video-py Python library.