程序 youtube-dl
本身支持文件名中的非ASCII字符,它在root用户和www-data用户下在我的Web服务器上完美工作,但是当我尝试使用YouTube下载视频时DL具有PHP,非ASCII字符完全跳过。
eg:Stromae - bâtard
将保存为Stromae - btard.mp4
或البث الحي
,为.mp4
我正在使用此代码运行CLI命令
function cmd($string) {
$descriptorspec = array(
0 => array("pipe", "r"), // stdin
1 => array("pipe", "w"), // stdout
2 => array("pipe", "w"), // stderr
);
$process = proc_open($string, $descriptorspec, $pipes);
$stdout = stream_get_contents($pipes[1]);
fclose($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[2]);
$ret = proc_close($process);
return $stdout;
}
$value = ('youtube-dl https://some.valid/link');
echo cmd($value);
请建议我应该做什么解决此问题。
检查您的phpinfo();LC_ALL或LC_LANG设置的输出。我怀疑它与PHP无关,但是与您使用的Shell环境相比,您的Web服务器正在使用的Shell环境。
$value = ('LC_ALL=en_US.UTF-8 youtube-dl https://some.valid/link');
echo cmd($value);
默认情况下,PHP使用ISO-8859-1 charset。配置PHP以使用UTF-8。您可以通过添加
来解决这个mb_internal_encoding("UTF-8");
在您的脚本开始时