norkunas/youtube-dl-php
Composer 安装命令:
composer require norkunas/youtube-dl-php
包简介
youtube-dl / yt-dlp wrapper for php
关键字:
README 文档
README
A PHP wrapper for youtube-dl or yt-dlp.
Install
First step is to download the youtube-dl or yt-dlp.
Second step is to install the wrapper using Composer:
composer require norkunas/youtube-dl-php:dev-master
Download video
<?php declare(strict_types=1); require __DIR__ . '/vendor/autoload.php'; use YoutubeDl\Options; use YoutubeDl\YoutubeDl; $yt = new YoutubeDl(); $collection = $yt->download( Options::create() ->downloadPath('/path/to/downloads') ->url('https://www.youtube.com/watch?v=oDAw7vW7H0c') ); foreach ($collection->getVideos() as $video) { if ($video->getError() !== null) { echo "Error downloading video: {$video->getError()}."; } else { echo $video->getTitle(); // Will return Phonebloks // $video->getFile(); // \SplFileInfo instance of downloaded file } }
Download only audio (requires ffmpeg or avconv and ffprobe or avprobe)
<?php declare(strict_types=1); require __DIR__ . '/vendor/autoload.php'; use YoutubeDl\Options; use YoutubeDl\YoutubeDl; $yt = new YoutubeDl(); $collection = $yt->download( Options::create() ->downloadPath('/path/to/downloads') ->extractAudio(true) ->audioFormat('mp3') ->audioQuality('0') // best ->output('%(title)s.%(ext)s') ->url('https://www.youtube.com/watch?v=oDAw7vW7H0c') ); foreach ($collection->getVideos() as $video) { if ($video->getError() !== null) { echo "Error downloading video: {$video->getError()}."; } else { $video->getFile(); // audio file } }
Download progress
<?php declare(strict_types=1); require __DIR__ . '/vendor/autoload.php'; use YoutubeDl\YoutubeDl; $yt = new YoutubeDl(); $yt->onProgress(static function (?string $progressTarget, string $percentage, string $size, string $speed, string $eta, ?string $totalTime): void { echo "Download file: $progressTarget; Percentage: $percentage; Size: $size"; if ($speed) { echo "; Speed: $speed"; } if ($eta) { echo "; ETA: $eta"; } if ($totalTime !== null) { echo "; Downloaded in: $totalTime"; } });
Custom Process Instantiation
<?php declare(strict_types=1); namespace App\YoutubeDl; use Symfony\Component\Process\Process; use YoutubeDl\Process\ProcessBuilderInterface; class ProcessBuilder implements ProcessBuilderInterface { public function build(?string $binPath, ?string $pythonPath, array $arguments = []): Process { $process = new Process([$binPath, $pythonPath, ...$arguments]); // Set custom timeout or customize other things.. $process->setTimeout(60); return $process; } }
<?php declare(strict_types=1); use App\YoutubeDl\ProcessBuilder; use YoutubeDl\YoutubeDl; $processBuilder = new ProcessBuilder(); // Provide your custom process builder as the first argument. $yt = new YoutubeDl($processBuilder);
Questions?
If you have any questions please open a discussion.
License
This library is released under the MIT License. See the bundled LICENSE file for details.
norkunas/youtube-dl-php 适用场景与选型建议
norkunas/youtube-dl-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 351.36k 次下载、GitHub Stars 达 505, 最近一次更新时间为 2015 年 03 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「youtube」 「youtube-dl」 「yt-dlp」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 norkunas/youtube-dl-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 norkunas/youtube-dl-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 norkunas/youtube-dl-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easy to use SDK with grabber for multiple platforms at once like YouTube, Dailymotion, Facebook and more.
♺ Laravel Nova Hashids card. Convert your ids.
A Laravel package for downloading videos from the net by simply passing a URL
A PHP wrapper for youtube-dl or yt-dlp tool. Close to the command line, with a caching system.
Generate short, unique, non-sequential ids (like YouTube and Bitly) from numbers
TYPO3 Plugin that displays YouTube-videos faster by loading the video-player on demand while displaying a cacheable preview picture.
统计信息
- 总下载量: 351.36k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 514
- 点击次数: 28
- 依赖项目数: 19
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-03-28