定制 flatgreen/ytdl 二次开发

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

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

flatgreen/ytdl

最新稳定版本:v2.6

Composer 安装命令:

composer require flatgreen/ytdl

包简介

A PHP wrapper for youtube-dl or yt-dlp tool. Close to the command line, with a caching system.

README 文档

README

PHP wrapper for youtube-dl or yt-dlp.

Two goals:

  • be close to the command line of youtube-dl
  • minimize requests, while having the maximum amount of information

Prerequisites

Installation

  • Use the package manager composer to install Ytdl.
composer require flatgreen/ytdl
  • Optional: Create a 'cache' directory (with read|write permissions), by default the cache directory is inside the system temporary directory.

Usage

Load the two classes:

require_once 'vendor/autoload.php';
use Flatgreen\Ytdl\Options;
use Flatgreen\Ytdl\Ytdl;

Define the options:

All in array manner. No URL here.

see : options for youtube-dl or options for yt-dlp

$ytdl_options = new Options();
// merge with default options
$ytdl_options->addOptions(['-f' => '18/worst']);

// with a direct string commnd line
$ytdl_options->addRawOptions('--one_alone --with_value value --second_alone -t');

Instantiate and extract information:

Instantiate the class:

$ytdl = new Ytdl($ytdl_options);
// optional, change cache options
// default temporary cache directory and duration 3600 sec.
// no cache with ['duration' => 0]
$ytdl->setCache(['directory' => 'cache', 'duration' => 7200])

If you want to set the ytdl executable path, you need to pass the value like below. This will skip the automatic scan (in PATH) of the executable. It is your responsibility to set this path correctly.

$ytdl = new Ytdl($ytdl_options, null, 'usr/share/local/yt-dlp');

Define a video url:

$webpage_url = 'https://www.youtube.com/watch?v=DTi8wZ1a1TA';

Read the video informations

$info_dict = $ytdl->extractInfos($webpage_url);
$errors = $ytdl->getErrors();

With some format (like ['-f' => 'bv*+ba']), there is no $info_dict['url'], but the media can be downloaded with this $info_dict.

At this moment, $info_dict is in the cache.

Download a video

$info_dict = $ytdl->download($webpage_url);
// with a download directory
// $info_dict = $ytdl->download($webpage_url, $directory_to_download);
// with an explicit $info_dict
// $new_info_dict = $ytdl->download($webpage_url, $directory_to_download, $info_dict);
$errors = $ytdl->getErrors();

Examples

  • example-0 with just '--version' option
  • example-1 extract example
  • example-1-1 extract from a playlist
  • example-2 download a video (cache and download folders)
  • example-2-2 download with a change of options
  • example-3 download a playlist (no cache, not optimal)
  • example-4 extract all informations from a playlist and download some videos with cache system.

Versions

See CHANGELOG

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

ytdl is licensed under the MIT License (MIT). Please see the license file for more information.

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-08-21