das-l/youtube-dl-bundle

Symfony 扩展包,提供对 norkunas/youtube-dl-php 的服务注入和配置

安装: 9

依赖: 1

建议者: 0

安全性: 0

星标: 1

关注者: 1

分支: 0

开放问题: 0

类型:symfony-bundle

1.0.0 2023-05-22 05:54 UTC

This package is auto-updated.

Last update: 2024-09-22 09:08:23 UTC


README

Symfony 扩展包,提供对 norkunas/youtube-dl-php 的服务注入和配置,该包是 youtube-dl 或 yt-dlp 的 PHP 封装。

提供的服务配置

services:
    # ...
    das_l_youtube_dl:
        class: YoutubeDl\YoutubeDl
        arguments:
            - '@das_l_youtube_dl.process_builder'
            - '@das_l_youtube_dl.metadata_reader'
            - '@filesystem'
        calls:
            - setBinPath: ['%das_l_youtube_dl.binPath%']
            - setPythonPath: ['%das_l_youtube_dl.pythonPath%']

    das_l_youtube_dl.process_builder:
        class: YoutubeDl\Process\DefaultProcessBuilder

    das_l_youtube_dl.metadata_reader:
        class: YoutubeDl\Metadata\DefaultMetadataReader

服务使用

注意:有关库本身的使用更多详情,请查看 norkunas/youtube-dl-php 提供的文档。

services:
    # ...
    App\Foo\YouTubeFoo:
        arguments:
            - '@das_l_youtube_dl'
<?php

namespace App\Foo;

use YoutubeDl\Options;
use YoutubeDl\YoutubeDl;

class YouTubeFoo
{
    private $youtubeDl;

    public function __construct(YoutubeDl $youtubeDl)
    {
        $this->youtubeDl = $youtubeDl;
    }

    public function downloadVideo($downloadPath, $url)
    {
        $options = Options::create()
            ->downloadPath($downloadPath)
            ->url($url)
        ;

        $collection = $this->youtubeDl->download($options);

        // ...
    }
}

配置选项

das_l_youtube_dl:
    binPath: '/your/custom/bin/path/youtube-dl'
    pythonPath: '/your/custom/path/for/python'