如何从浏览器的右键菜单中禁用“另存为…”以防止客户端下载视频?
是否有更完整的解决方案来阻止客户端直接访问文件路径?
如何从浏览器的右键菜单中禁用“另存为…”以防止客户端下载视频?
是否有更完整的解决方案来阻止客户端直接访问文件路径?
当前回答
你不能。
例如,人们可以使用一些api例如desktopCapture, getUserMedia 允许用户记录屏幕、窗口、选项卡。
人们可以使用它并将其写入画布,然后将所有的块连接在一起以获得视频,
所以如果他们真的想要视频,没有办法阻止他们下载。
其他回答
你不能百分百保护它,但你可以让它更难。我解释的这些方法,是我在PluralSight和BestDotNetTraining中学习保护方法时遇到的。尽管如此,这些方法都没有阻止我下载我想要的东西,但我很难策划下载者通过他们的保护。
除了其他提到的方法禁用上下文菜单。用户仍然可以使用第三方工具,如InternetDownload manager或其他类似软件下载视频。我在这里解释的保护方法是缓解这些第三方软件。
所有这些方法的要求是,当您确定有人正在下载您的视频时,阻止用户。这样,在你禁止他们访问你的网站之前,他们只能下载一到两个视频。
免责声明
如果有人滥用这些方法或用它来伤害其他人或我举的例子中的网站,我将不承担任何责任。它只是用来分享知识,帮助你保护你的知识产品。
生成带有过期的链接
这样做的要求是为每个用户创建一个下载链接。azure blob存储或amazon s3可以很容易地处理这个问题。您可以使用视频长度到期时间戳的两倍创建下载链接。然后,您需要捕获该视频链接和请求的时间。这是下一个方法所必需的。这种方法的问题在于,当用户单击播放按钮时,将生成下载链接。
在播放按钮事件中,您将向服务器发送一个请求,并获得链接并更新源代码。
限制视频请求速率
然后监视用户请求第二个视频的速度。如果用户请求下载链接的速度太快,那么你会立即阻止他们。你不能把这个阈值设得太大,因为你可能会错误地阻止那些只是浏览或浏览视频的用户。
启用HTTP范围
use some js library like videojs to play your video, also you need to return an AcceptRange in your header. Azure blob storage supports this out of the box. this way the browser starts to download the video chunk by chunk. usually, 32byte by 32byte. then you need to listen to videojs timeupdate change and update your server about the percentage that the video is watched. the percentage that the video is watched can't be more than the percentage that video is delivered. and if you are delivering a video content without receiving any percentage change, then you can block the user. because for sure they are downloading.
实现这个很棘手,因为用户可以向前或向后跳过视频,所以在实现这个时要注意这一点。
这是BestDotnetTraining处理时间更新的方式
myPlayer.ready(function () {
//var player = this;
this.src({
type: "video/mp4",
src: videoURL
});
if (videoId) {
myPlayer.play();
this.on('timeupdate', function () {
var currentPercent = parseInt(100 * myPlayer.currentTime() / myPlayer.duration());//calcualte as percentage
if (currentPercent % 5 == 0) {
//send percentage to server
SaveVideoDurationWatched(currentPercent, videoId);
}
});
}
});
anyway, the user is able to work around this by using some download method that downloads a file through streaming. almost c# do it out of the box and for nodejs, you can use request module. then you need to start a stopWatch, listen to a package received and compare the total byte received compare to the total size. this way you can calculate a percentage and the time spent to get that amount of percentage. then use the Thread.Sleep() or something like that to delay the thread the amount that you have to wait if you watch the video normally. also before the sleep the user can call the server and update the percentage that is received. so the server thinks that the user is actually watching a video.
例如,如果你计算出到目前为止你收到了1%,那么你可以计算出你应该等待休眠下载线程的数量。通过这种方式,你下载视频的速度不会超过它的实际长度。如果一个视频是24分钟,那么下载它就需要24分钟。(加上我们在第一个方法中设置的阈值)
original video length 24 minute
24 min *60000 = 1,440,000 miliseconds
1,440,000 % 100 = 14,400 milisecond is needed to download one percent
检查浏览器代理
当您正在提供网页和视频链接或接受进度更新请求时,您可以查看浏览器代理。如果它是不同的,然后禁止用户。
请注意,一些旧的浏览器不会传递此信息。因此,当视频请求和网页请求都没有浏览器代理时,可以忽略这一点。但是如果一个请求有,而另一个没有,那么你应该禁止这个用户。
为了解决这个问题,用户可以手动将浏览器代理头设置为与他们用来捕获下载链接的无头浏览器相同。
检查引用标头
当引用者不是你的主机URL或你提供视频的页面URL时,你可以禁止该用户,因为他们将下载链接放在另一个选项卡或另一个应用程序中。甚至对于进度更新请求也可以这样做。
这样做的要求是有一个视频和显示该视频的页面的映射。你可以创建一些惯例或模式来理解URL应该是什么,这取决于你的设计。
为了解决这个问题,用户可以在下载视频时手动设置与下载页面URL相等的referrer头。
计算请求之间的时间间隔
if you receive so many requests that the time between them is the same, then you should block the user. you should put this to capture how much is time between the video link generation request. if they are the same (plus/minus some threshold) and it happens more than a number of times, then you can ban the user. because if there is a bot that is going to crawl your website or videos, then usually they have the same sleep time between their request. so if you receive each request, for example, every 1.3(plus/mins some deviation) minutes. then you raise an alarm. for this, you can use some statistic calculation to know the deviation between the requests.
为了解决这个问题,用户可以在请求之间设置一个随机的睡眠时间。
示例代码
我有一个回购PluralSight-Downloader正在中途做它。我在5年前创建了这个回购。因为我写它是为了学习目的和自己的个人使用,到目前为止,回购没有收到任何更新,我不打算更新或使它易于使用。这只是一个可以做到的例子。
这是一个完整的解决方案禁用下载,包括右击>另存为…在上下文菜单中:
<video oncontextmenu="return false;" controlsList="nodownload">
</video>
你不能。
例如,人们可以使用一些api例如desktopCapture, getUserMedia 允许用户记录屏幕、窗口、选项卡。
人们可以使用它并将其写入画布,然后将所有的块连接在一起以获得视频,
所以如果他们真的想要视频,没有办法阻止他们下载。
简单回答:像youtube那样加密链接,不知道怎么做,不如问问youtube/谷歌他们是怎么做的。(以防你想直奔主题。)
I would like to point out to anyone that this is possible because youtube does it and if they can so can any other website and it isn't from the browser either because I tested it on a couple browsers such as microsoft edge and internet explorer and so there is a way to disable it and seen that people still say it...I tries looking for an answer because if youtube can than there has to be a way and the only way to see how they do it is if someone looked into the scripts of youtube which I am doing now. I also checked to see if it was a custom context menu as well and it isn't because the context menu is over flowing the inspect element and I mean like it is over it and I looked and it never creates a new class and also it is impossible to actually access inspect element with javascript so it can't be. You can tell when it double right-click a youtube video that it pops up the context menu for chrome. Besides...youtube wouldn't add that function in. I am doing research and looking through the source of youtube so I will be back if I find the answer...if anyone says you can't than, well they didn't do research like I have. The only way to download youtube videos is through a video download.
Okay...I did research and my research stays that you can disable it except there is no javascript to it...you have to be able to encrypt the links to the video for you to be able to disable it because I think any browser won't show it if it can't find it and when I opened a youtube video link it showed as this "blob:https://www.youtube.com/e5c4808e-297e-451f-80da-3e838caa1275" without quotes so it is encrypting it so it cannot be saved...you need to know php for that but like the answer you picked out of making it harder, youtube makes it the hardest of heavy encrypting it, you need to be an advance php programmer but if you don't know that than take the person you picked as best answer of making it hard to download it...but if you know php than heavy encrypt the video link so it only is able to be read on yours...I don't know how to explain how they do it but they did and there is a way. The way youtube Encrypts there videos is quite smart so if you want to know how to than just ask youtube/google of how they do it...hope this helps for you although you already picked a best answer. So encrypting the link is best in short terms.
@Clayton-Graul有我正在寻找的东西,除了我需要一个使用AngularJS的网站的CoffeeScript版本。以防你也需要它,下面是你在AngularJS控制器中输入的内容:
# This is how to we do JQuery ready() dom stuff
$ ->
# let's hide those annoying download video options.
# of course anyone who knows how can still download
# the video, but hey... more power to 'em.
$('#my-video').bind 'contextmenu', ->
false
“奇怪的事情正在k圈发生”(这是真的)