Html 获取 youtube 视频 url 表单网页源

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14207977/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 04:48:17  来源:igfitidea点击:

Get youtube video url form webpage source

htmlurlyoutube

提问by user1767260

Is it possible to get the download URL of currently playing video from source of YouTube webpage?Thanks in advance.Please help me.

是否可以从 YouTube 网页的源中获取当前正在播放的视频的下载 URL?提前致谢。请帮助我。

Actually I have a downloader but it is not working now.When I have tried with the URL provided by the downloader in browser it returns an error page says "Access to the webpage was denied".The Url that I got for a video is as " http://r14---sn-h557snel.c.youtube.com/videoplayback?gcr=in&ip=121.241.181.70&upn=OOcjKEO_S6I&cp=U0hUTFZQT19KU0NONF9OSlNGOmFRT2JSUUs2bDVi&ipbits=8&fexp=900148,920704,912806,928001,922403,922405,929901,913605,929104,913546,913556,908496,920201,913302,919009,911116,901451,902556&ms=au&mt=1357625350&mv=m&id=31a79fcdbfc6c2f6&sparams=cp,gcr,id,ip,ipbits,itag,ratebypass,source,upn,expire&expire=1357651559&itag=18&key=yt1&newshard=yes&source=youtube&ratebypass=yes&sver=3"

实际上我有一个下载器,但它现在不起作用。当我在浏览器中尝试使用下载器提供的 URL 时,它返回一个错误页面,显示“访问网页被拒绝”。我为视频获得的 URL 为 http://r14---sn-h557snel.c.youtube.com/videoplayback?gcr=in&ip=121.241.181.70&upn=OOcjKEO_S6I&cp=U0hUTFZQT19KU0NONF9OSlNGOmFRT2JSUUs2bDVi&ipbits=8&fexp=900148,920704,912806,928001,922403,922405,929901, 913605,929104,913546,913556,908496,920201,913302,919009,911116,901451,902556&MS = AU&MT = 1357625350&MV =米&ID = 31a79fcdbfc6c2f6&sparams =厘泊,GCR,ID,IP,ipbits,ITAG,ratebypass,来源,UPN,到期&到期= 1357651559&itag=18&key=yt1&newshard=yes&source=youtube&ratebypass=yes&sver=3

Few months before the format of URL was " http://o-o---preferred---sn-h557snes---v24---lscache3.c.youtube.com/videoplayback?upn=AmmxhSpq470&sparams=cp,gcr,id,ip,ipbits,itag,ratebypass,source,upn,expire&fexp=917013,906437,916626,922401,920704,912806,927201,925706,922403,913546,913556,916805,920201,901451&ms=au&expire=1353668177&itag=18&ipbits=8&gcr=in&sver=3&ratebypass=yes&mt=1353646087&ip=121.241.181.70&mv=m&source=youtube&key=yt1&cp=U0hUSFZRVl9MUUNONF9OS1pCOmhtUTVMak5oTVNy&id=c429fa5466ee9447&newshard=yes"

几个月前 URL 的格式是 http://oo---preferred---sn-h557snes---v24---lscache3.c.youtube.com/videoplayback?upn=AmmxhSpq470&sparams=cp,gcr,id ,IP,ipbits,ITAG,ratebypass,来源,UPN,到期&FEXP = 917013,906437,916626,922401,920704,912806,927201,925706,922403,913546,913556,916805,920201,901451&MS = AU&到期= 1353668177&ITAG = 18&ipbits = 8&GCR在=&sver = 3&ratebypass = YES&MT = 1353646087&IP = 121.241.181.70&MV = M&源= YouTube和键= YT1&CP = U0hUSFZRVl9MUUNONF9OS1pCOmhtUTVMak5oTVNy&ID = c429fa5466ee9447&newshard =是

So I don't know whether the downloader gives the correct URL. Please help me

所以我不知道下载器是否给出了正确的URL。请帮我

回答by Devon Bernard

Sorry I looked around and I couldn't find a way to directly download the source file from the youtube link. There are some guides out there but they all are around 2009; and since youtube changes their code a lot currently none of them work.

抱歉,我环顾四周,找不到直接从 youtube 链接下载源文件的方法。那里有一些指南,但它们都在 2009 年左右;并且由于 youtube 更改了很多代码,因此目前它们都不起作用。

Although there are many websites, addons, apps that allow you to download videos; but I do not think they work from a code from the link. Since to watch a video you have to temporarily download it I think they all use a method of opening the page, playing(downloading) the video and actually saving it. I would list those websites and addons but since those sources are not that hard to find; I assume you are trying to build your own downloader and not use one that is already out there.

尽管有许多网站、插件、应用程序可以让您下载视频;但我认为它们不能通过链接中的代码工作。由于观看视频您必须临时下载它,我认为他们都使用打开页面,播放(下载)视频并实际保存它的方法。我会列出这些网站和插件,但因为这些来源并不难找到;我假设您正在尝试构建自己的下载器,而不是使用已经存在的下载器。

Also on another note if you could somehow get a link to a videos source file. I am sure youtube has permissions blocked access on all folders and files on their backend for security measures; only allowing those files to be forwarded and displayed on the actual player page. And if you think embedded videos would somehow work they still just make a request to youtube which youtube then gives back video-feed-data so there still is no direct connection to the file.

另请注意,如果您能以某种方式获得视频源文件的链接。我确信 youtube 有权限阻止访问其后端的所有文件夹和文件,以采取安全措施;只允许这些文件被转发并显示在实际播放器页面上。如果您认为嵌入的视频会以某种方式工作,他们仍然只是向 youtube 发出请求,然后 youtube 返回视频源数据,因此仍然没有与文件的直接连接。

回答by Juan Mendes

You should use the player API https://developers.google.com/youtube/js_api_reference#Retrieving_video_information

您应该使用播放器 API https://developers.google.com/youtube/js_api_reference#Retrieving_video_information

player.getVideoUrl():String

player.getVideoUrl():String

Returns the YouTube.com URL for the currently loaded/playing video.

返回当前加载/播放视频的 YouTube.com URL。

回答by mortezaipo

I have written a simple python code that can fetch youtube href from html code. hope it can help you:

我编写了一个简单的 python 代码,可以从 html 代码中获取 youtube href。希望能帮到你:

#!/usr/bin/env python

import re

pattern = '.*<(iframe|param).*(src|value)="(?P<link>http://www.youtube.com/(embed|v)/[a-zA-Z0-9/\.\?&;=\+_-]+);?.*".*>.*</(iframe|param)>.*'

action = re.compile(pattern)
result = action.findall('<div><iframe.....></iframe><param......></param></div>')

print result 

https://gist.github.com/Mortezaipo/5707738

https://gist.github.com/Mortezaipo/5707738