定制 commandstring/yt-dlp 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

commandstring/yt-dlp

最新稳定版本:v3.0.0

Composer 安装命令:

composer require commandstring/yt-dlp

包简介

A PHP wrapper for yt-dlp

README 文档

README

A promised-based PHP wrapper for YtDlp built off ReactPHP

NOTE BEFORE USING YOU WILL NEED TO START A REACT/PROMISE LOOP OR THE SCRIPT WILL DIE BEFORE THE COMMAND FINISHES EXECUTING!!!

Creating YtDlp

$yt = new YtDlp();

You can supply a path to your Yt-Dlp as well if it's not in your path.

CommandBuilder

You can use the command builder to create commands programmatically, all options for YtDlp exist inside \Yt\Dlp\Options (if I'm missing anything please open an issue)

You can create a new CommandBuilder with your YtDlp instance

$command = $yt->newCommand($url)->addOption(Options::SKIP_DOWNLOAD)->addOption(Options::DUMP_JSON);

You can then use the execute method to execute. With the then method following that you can check the handle a success/failed command execution

$command->execute()->then(function (string $result) {
    echo $result;
}, function (CommandExecutionFailed $e) {
    echo (string)$e;
});

Already implemented commands

public function downloadVideo(string $url, string $outputPath, string $customName, string $format = "mp4"): PromiseInterface;
public function downloadAudio(string $url, string $outputPath, string $customName, string $format = "mp3"): PromiseInterface;

returns the full path of where the audio/video was downloaded

public function getInfo(string $url): PromiseInterface

returns an stdClass with the video info Available Fields

public function search(string $query, int $results = 1): PromiseInterface

Returns an array of all the results, each item has a structure similar to the getInfo method

Basic Usage

This code will download the first videos from the query

<?php

use React\EventLoop\Loop;
use Yt\Dlp\Exceptions\CommandExecutionFailed;
use Yt\Dlp\YtDlp;

require_once "vendor/autoload.php";

$yt = new YtDlp();

$errHandler = function (CommandExecutionFailed $e) {
    echo (string)$e;
};

$query = "amalee the worlds continuation";

$yt->search($query, 5)->then(function ($results) use ($yt, $errHandler) {
    foreach ($results as $video) {
        $id = $video->id;

        $yt->downloadVideo($id, __DIR__, $id)->then(null, $errHandler);
    }
});

Loop::get()->run();

统计信息

  • 总下载量: 92
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-01-04