1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

youtube-dl でファイル名を IDで保存する方法

Last updated at Posted at 2021-02-18

youtube-dl でファイル名を IDで保存する方法です。

まずは youtube-dl のインストール方法

sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl ;
sudo chmod a+rx /usr/local/bin/youtube-dl ;

コマンドラインからファイル名を IDで保存

youtube-dl -o "~/%(id)s.%(ext)s" "https://www.youtube.com/watch?v=XayoaxJQ_hA"

ちなみに php と apache で web から叩く場合は

youtube_dl_id.php
<?php

set_time_limit( 0 );

$url = 'https://www.youtube.com/watch?v=XayoaxJQ_hA';
$cmd = 'youtube-dl -o "/home/myusername/work/%(id)s.%(ext)s" ' . escapeshellarg($url);
exec($cmd, $output, $ret);

echo 'output: ';
var_export($output);
echo "\nret: ";
var_export($ret);

もしくは chdir で作業フォルダを移動して実行

youtube_dl_id.php
<?php

set_time_limit( 0 );

echo getcwd() . "\n";
chdir("/home/myusername/work/");
echo getcwd() . "\n";

$url = 'https://www.youtube.com/watch?v=XayoaxJQ_hA';
$cmd = 'youtube-dl -o "%(id)s.%(ext)s" ' . escapeshellarg($url);
exec($cmd, $output, $ret);

echo 'output: ';
var_export($output);
echo "\nret: ";
var_export($ret);

####参考リンク

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?