【发布时间】:2014-01-05 00:00:14
【问题描述】:
所以我想将 youtubevideos 作为 mp3 下载到我的服务器上,这样我就可以轻松地将它们作为 mp3 收听。
我在 PHP 方面有一些经验,在 youtube API 方面首屈一指,但如果我理解正确,youtubevideos 会以块的形式加载,其中 1 个是视频的 mp3 配乐。
如果不正确,您能否建议其他方式进行下载?
到目前为止,我已经设法做一个小的 php 脚本来获取保存音频的必要信息。
$id = $_POST["A"];
$xmlData = simplexml_load_string(file_get_contents("http://gdata.youtube.com/feeds/api/videos/{$id}?fields=title"));
$title = (string)$xmlData->title;
$bad = array_merge(
array_map('chr', range(0,31)),
array("<", ">", ":", '"', "/", "\\", "|", "?", "*"));
$result = str_replace($bad, "-", $title);
$file = "$result.mp3";
fopen("$file", 'w+') or die('Cannot open file: '."$file");
//echo "http://youtubeinmp3.com/fetch/?video=http://www.youtube.com/watch?v=$id";
$current = file_get_contents("$file");
//$current .= "http://youtubeinmp3.com/fetch/?video=http://www.youtube.com/watch?v=$id";
file_put_contents("$file", $current);
(帖子 A 来自我的 html 部分代码,其中包含 youtube 视频 ID)
因此,在该代码中,我并没有完全使用 youtube 来下载 mp3 曲目... 因此,如果你们中的任何人都知道如何直接从 youtube 下载它以及如何保存它,那就太好了,因为按照我的逻辑,该代码应该可以完美运行,而且确实如此,直到保存音频,它可以节省大约 50 位然后停止,我没有得到任何错误或任何东西,所以它真的很难调试。
另外,如果您在我的代码中发现任何错误或更好的处理方法,请通知我。
也很抱歉我来自芬兰的英语不好,对糟糕的代码感到抱歉,这实际上是我将要使用的第一个实用程序:)
【问题讨论】: