var links = new String();
var downlink = new String();
var has22 = new Boolean();
has22 = false;
var Marked=false;
var FMT_DATA = fmt_url_map;//This is html text that you have to grab. In case of extension it was readily available through:document.getElementsByTagName('script');
var StrSplitter1='%2C', StrSplitter2='%26', StrSplitter3='%3D';
if (FMT_DATA.indexOf(',')>-1) { //Found ,
StrSplitter1=',';
StrSplitter2=(FMT_DATA.indexOf('&')>-1)?'&':'\\u0026';
StrSplitter3='=';
}
var videoURL=new Array();
var FMT_DATA_PACKET=new Array();
var FMT_DATA_PACKET=FMT_DATA.split(StrSplitter1);
for (var i=0;i<FMT_DATA_PACKET.length;i++){
var FMT_DATA_FRAME=FMT_DATA_PACKET[i].split(StrSplitter2);
var FMT_DATA_DUEO=new Array();
for (var j=0;j<FMT_DATA_FRAME.length;j++){
var pair=FMT_DATA_FRAME[j].split(StrSplitter3);
if (pair.length==2) {
FMT_DATA_DUEO[pair[0]]=pair[1];
}
}
var url=(FMT_DATA_DUEO['url'])?FMT_DATA_DUEO['url']:null;
if (url==null) continue;
url=unescape(unescape(url)).replace(/\\\//g,'/').replace(/\\u0026/g,'&');
var itag=(FMT_DATA_DUEO['itag'])?FMT_DATA_DUEO['itag']:null;
var itag=(FMT_DATA_DUEO['itag'])?FMT_DATA_DUEO['itag']:null;
if (itag==null) continue;
var signature=(FMT_DATA_DUEO['sig'])?FMT_DATA_DUEO['sig']:null;
if (signature!=null) {
url=url+"&signature="+signature;
}
if (url.toLowerCase().indexOf('http')==0) { // validate URL
if (itag == '5') {
links += '<a href="' + url + '&title=' + username + title + quality240 + '"style="text-decoration:none"><span class="yt-uix-button-menu-item" id="v240p">FLV (240p)</span></a>';
}
if (itag == '18') {
links += '<a href="' + url + '&title=' + username + title + quality360 + '"style="text-decoration:none"><span class="yt-uix-button-menu-item" id="v360p">MP4 (360p)</span></a>';
}
if (itag == '35') {
links += '<a href="' + url + '&title=' + username + title + quality480 + '"style="text-decoration:none"><span class="yt-uix-button-menu-item" id="v480p">FLV (480p)</span></a>';
}
if (itag == '22') {
links += '<a href="' + url + '&title=' + username + title + quality720 + '"style="text-decoration:none"><span class="yt-uix-button-menu-item" id="v720p">MP4 HD (720p)</span></a>';
}
if (itag == '37') {
links += ' <a href="' + url + '&title=' + username + title + quality1080 + '"style="text-decoration:none"><span class="yt-uix-button-menu-item" id="v1080p">MP4 HD (1080p)</span></a>';
}
if (itag == '38') {
links += '<a href="' + url + '&title=' + username + title + quality4k + '"style="text-decoration:none"><span class="yt-uix-button-menu-item" id="v4k">MP4 HD (4K)</span></a>';
}
FavVideo();
videoURL[itag]=url;
console.log(itag);
}
}
last time i was working on fixing one of the brocken chrome extension to download youtube video. I fixed it by altering the script part. (Javascript)
var links = new String();
var downlink = new String();
var has22 = new Boolean();
has22 = false;
var Marked=false;
var FMT_DATA = fmt_url_map;//This is html text that you have to grab. In case of extension it was readily available through:document.getElementsByTagName('script');
var StrSplitter1='%2C', StrSplitter2='%26', StrSplitter3='%3D';
if (FMT_DATA.indexOf(',')>-1) { //Found ,
StrSplitter1=',';
StrSplitter2=(FMT_DATA.indexOf('&')>-1)?'&':'\\u0026';
StrSplitter3='=';
}
var videoURL=new Array();
var FMT_DATA_PACKET=new Array();
var FMT_DATA_PACKET=FMT_DATA.split(StrSplitter1);
for (var i=0;i<FMT_DATA_PACKET.length;i++){
var FMT_DATA_FRAME=FMT_DATA_PACKET[i].split(StrSplitter2);
var FMT_DATA_DUEO=new Array();
for (var j=0;j<FMT_DATA_FRAME.length;j++){
var pair=FMT_DATA_FRAME[j].split(StrSplitter3);
if (pair.length==2) {
FMT_DATA_DUEO[pair[0]]=pair[1];
}
}
var url=(FMT_DATA_DUEO['url'])?FMT_DATA_DUEO['url']:null;
if (url==null) continue;
url=unescape(unescape(url)).replace(/\\\//g,'/').replace(/\\u0026/g,'&');
var itag=(FMT_DATA_DUEO['itag'])?FMT_DATA_DUEO['itag']:null;
var itag=(FMT_DATA_DUEO['itag'])?FMT_DATA_DUEO['itag']:null;
if (itag==null) continue;
var signature=(FMT_DATA_DUEO['sig'])?FMT_DATA_DUEO['sig']:null;
if (signature!=null) {
url=url+"&signature="+signature;
}
if (url.toLowerCase().indexOf('http')==0) { // validate URL
if (itag == '5') {
links += '<a href="' + url + '&title=' + username + title + quality240 + '"style="text-decoration:none"><span class="yt-uix-button-menu-item" id="v240p">FLV (240p)</span></a>';
}
if (itag == '18') {
links += '<a href="' + url + '&title=' + username + title + quality360 + '"style="text-decoration:none"><span class="yt-uix-button-menu-item" id="v360p">MP4 (360p)</span></a>';
}
if (itag == '35') {
links += '<a href="' + url + '&title=' + username + title + quality480 + '"style="text-decoration:none"><span class="yt-uix-button-menu-item" id="v480p">FLV (480p)</span></a>';
}
if (itag == '22') {
links += '<a href="' + url + '&title=' + username + title + quality720 + '"style="text-decoration:none"><span class="yt-uix-button-menu-item" id="v720p">MP4 HD (720p)</span></a>';
}
if (itag == '37') {
links += ' <a href="' + url + '&title=' + username + title + quality1080 + '"style="text-decoration:none"><span class="yt-uix-button-menu-item" id="v1080p">MP4 HD (1080p)</span></a>';
}
if (itag == '38') {
links += '<a href="' + url + '&title=' + username + title + quality4k + '"style="text-decoration:none"><span class="yt-uix-button-menu-item" id="v4k">MP4 HD (4K)</span></a>';
}
FavVideo();
videoURL[itag]=url;
console.log(itag);
}
}
You can get separate video link from videoURL[itag] array. Above logic can be converted to PHP easily
Nobody writes manuals/howtos that become outdated every four weeks. The closest you can get is inspecting the actual extraction methods in a contemporary implementation. Quite readable:
现在,一旦找到它,就弄清楚浏览器如何知道获取该文件。搜索会话 (Ctrl+F) 并查找“videoplayback”。您将在访问的第一页上看到一个点击,例如 http://www.youtube.com /watch?v=123asdf。如果您仔细查看该文件,您将看到一个 ID 为“watch-player”的 DIV 标签。其中有一个脚本标签用于设置 Flash 播放器,其中包含所有 Flash 参数。其中包含视频的 URL。
现在您知道如何使用工具来弄清楚浏览器是如何访问它的。如何在 PHP 中复制这种行为?
在引用视频的页面上执行 file_get_contents()。忽略不在该观看播放器 div 中的所有内容。解析代码,直到找到包含 URL 的变量。从那里您可能必须取消转义该 URL。获得后,您可以执行 file_get_contents() (或其他下载方法,具体取决于您要执行的操作)来获取 URL。就是这么简单。您的 HTML 解析代码将是最复杂的。
最后,请记住您要做的事情可能是非法的。检查 EULA。
The first thing you should do is get a tool like Fiddler and visit a YouTube video page. In Fiddler, you will see all of the files that make up that page, including the FLV itself. Now, you know that the video isn't one of the CSS files, nor is it the image files. You can ignore those. Look for a big file. If you look at the URL, it begins with /videoplayback.
Now, once you've found it, figure out how the browser knew to get that file. Do a search through the sessions (Ctrl+F) and look for "videoplayback". You will see a hit on the first page you went to, like http://www.youtube.com/watch?v=123asdf. If you dig through that file, you'll see a DIV tag with the ID of "watch-player". Within that there is a script tag to setup the flash player, and within that are all of the flash parameters. Within those is the URL to the video.
So now you know how to use your tools to figure out how the browser got to it. How do you duplicate this behavior in PHP?
Do a file_get_contents() on the page that references the video. Ignore everything not in that watch-player div. Parse through the code until you find that variable that contains the URL. From there you will probably have to unescape that URL. Once you have it, you can do a file_get_contents() (or some other download method, depending on what you are trying to do) to get the URL. it is that simple. Your HTML parsing code will be the most complex.
Finally, keep in mind what you are about to do may be illegal. Check the EULA.
发布评论
评论(3)
上次我正在修复一个损坏的 chrome 扩展来下载 YouTube 视频。我通过更改脚本部分修复了它。 (Javascript)
您可以从 videoURL[itag] 数组中获取单独的视频链接。
上述逻辑可以轻松转换为 PHP
扩展可以从位置下载 http://www.figmentsol.com /chrome/ytdw/
我希望这会对某人有所帮助。这是有效的解决方案(日期:2013年4月6日)
last time i was working on fixing one of the brocken chrome extension to download youtube video. I fixed it by altering the script part. (Javascript)
You can get separate video link from videoURL[itag] array.
Above logic can be converted to PHP easily
The extension can be downloaded from location http://www.figmentsol.com/chrome/ytdw/
I hope this would help someone. This is working solution (date:06-04-2013)
没有人编写每四个星期就会过时的手册/指南。您可以获得的最接近的是检查当代实现中的实际提取方法。非常可读:
http://bitbucket.org/rg3/youtube -dl/raw/2010.08.04/youtube-dl
如果您不想通读/重新实现它,这显然并不简单,您可以从 PHP 中按原样运行它:
Nobody writes manuals/howtos that become outdated every four weeks. The closest you can get is inspecting the actual extraction methods in a contemporary implementation. Quite readable:
http://bitbucket.org/rg3/youtube-dl/raw/2010.08.04/youtube-dl
If you don't want to read through/reimplement it, it's obviously not simple, you could just run it as-is from PHP:
您应该做的第一件事是获取一个类似 Fiddler 的工具并访问 YouTube 视频页面。在 Fiddler 中,您将看到构成该页面的所有文件,包括 FLV 本身。现在,您知道视频不是 CSS 文件之一,也不是图像文件。你可以忽略那些。寻找一个大文件。如果您查看 URL,它会以
/videoplayback
开头。现在,一旦找到它,就弄清楚浏览器如何知道获取该文件。搜索会话 (Ctrl+F) 并查找“videoplayback”。您将在访问的第一页上看到一个点击,例如 http://www.youtube.com /watch?v=123asdf。如果您仔细查看该文件,您将看到一个 ID 为“watch-player”的 DIV 标签。其中有一个脚本标签用于设置 Flash 播放器,其中包含所有 Flash 参数。其中包含视频的 URL。
现在您知道如何使用工具来弄清楚浏览器是如何访问它的。如何在 PHP 中复制这种行为?
在引用视频的页面上执行
file_get_contents()
。忽略不在该观看播放器 div 中的所有内容。解析代码,直到找到包含 URL 的变量。从那里您可能必须取消转义该 URL。获得后,您可以执行file_get_contents()
(或其他下载方法,具体取决于您要执行的操作)来获取 URL。就是这么简单。您的 HTML 解析代码将是最复杂的。最后,请记住您要做的事情可能是非法的。检查 EULA。
The first thing you should do is get a tool like Fiddler and visit a YouTube video page. In Fiddler, you will see all of the files that make up that page, including the FLV itself. Now, you know that the video isn't one of the CSS files, nor is it the image files. You can ignore those. Look for a big file. If you look at the URL, it begins with
/videoplayback
.Now, once you've found it, figure out how the browser knew to get that file. Do a search through the sessions (Ctrl+F) and look for "videoplayback". You will see a hit on the first page you went to, like http://www.youtube.com/watch?v=123asdf. If you dig through that file, you'll see a DIV tag with the ID of "watch-player". Within that there is a script tag to setup the flash player, and within that are all of the flash parameters. Within those is the URL to the video.
So now you know how to use your tools to figure out how the browser got to it. How do you duplicate this behavior in PHP?
Do a
file_get_contents()
on the page that references the video. Ignore everything not in that watch-player div. Parse through the code until you find that variable that contains the URL. From there you will probably have to unescape that URL. Once you have it, you can do afile_get_contents()
(or some other download method, depending on what you are trying to do) to get the URL. it is that simple. Your HTML parsing code will be the most complex.Finally, keep in mind what you are about to do may be illegal. Check the EULA.