当前位置:   article > 正文

网页视频下载mp4格式到本地

视频下载mp4格式

发现个网页视频地址下载保存为mp4格式的资源,分享给大家:

git下载地址:

https://gitee.com/tiankf/mp4

CSDN下载地址:
MP4下载到保存到本地资源-CSDN文库

使用方式:

 

代码如下:

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta author="kevy tian">
  6. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  7. <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
  8. <title>腾讯视频下载</title>
  9. <style>
  10. #res {
  11. display: inline-block;
  12. width: 500px;
  13. height: 30px;
  14. font-size: 14px;
  15. line-height: 30px;
  16. padding: 0;
  17. }
  18. .container {
  19. padding-top: 50px;
  20. }
  21. #qxd, #isVid {
  22. display: inline-block;
  23. width: 120px;
  24. height: 30px;
  25. font-size: 14px;
  26. line-height: 30px;
  27. }
  28. #download {
  29. display: inline-block;
  30. width: 100px;
  31. height: 30px;
  32. font-size: 14px;
  33. line-height: 25px;
  34. text-align: center;
  35. padding: 0;
  36. margin-bottom: 4px;
  37. }
  38. </style>
  39. </head>
  40. <body>
  41. <div class="container">
  42. <p>首先在视频上<b>点击鼠标右键-->复制视频页面地址</b>,然后将复制的地址粘贴到下方输入框:</p>
  43. <div>
  44. <select id="isVid">
  45. <option value="1" selected>视频页面地址</option>
  46. <option value="2">视频vid</option>
  47. </select>
  48. <input id="res" type="text" placeholder="请输入视频链接"/>
  49. <button id="download" class="btn btn-large btn-primary" type="button">获取下载地址</button>
  50. </div>
  51. <p style="width:100%;padding:20px;word-wrap:break-word;" id="result"></p>
  52. </div>
  53. <script type="text/javascript">
  54. var bqApi = "https://vv.video.qq.com/getinfo?vids={vids}&platform=101001&charge=0&otype=json&defn=shd";
  55. var downloadUrl = "";
  56. var link = "";
  57. var isVid = "";
  58. var qxd = "";
  59. var vids = "";
  60. $("#download").click(function () {
  61. link = $("#res").val();
  62. qxd = $("#qxd").val();
  63. isVid = $("#isVid").val();
  64. if (isVid == "1") {
  65. if (checkUrl(link)) {
  66. vids = getVids(link);
  67. process()
  68. }
  69. else {
  70. alert("视频链接不正确");
  71. }
  72. }
  73. else {
  74. vids = link;
  75. if (vids != "") {
  76. process();
  77. }
  78. }
  79. });
  80. function checkUrl(url) {
  81. var reg = /(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/;
  82. if (url != "" && reg.test(url) && url.indexOf("page/") != -1 && url.indexOf(".html") != -1) {
  83. return true;
  84. }
  85. return false;
  86. }
  87. function getVids(url) {
  88. url = url.split(".html")[0].split("\/");
  89. return url[url.length - 1];
  90. }
  91. function process() {
  92. bqApi = bqApi.replaceAll("{vids}", vids);
  93. var api1Json = {};
  94. $.ajax({
  95. type: "get",
  96. url: bqApi,
  97. dataType: "jsonp",
  98. jsonpCallback: "cb",
  99. success: function (data) {
  100. api1Json = data;
  101. downloadUrl = api1Json.vl.vi[0].ul.ui[0].url + api1Json.vl.vi[0].fn + "?vkey=" + api1Json.vl.vi[0].fvkey;
  102. $("#result").html("<span style='font-weight:bold;font-size:20px;'>获取成功!下载方式:</span><br/>方式一:" + "<a target='_blank' href='" + downloadUrl + "'>点击此处</a>打开视频,在视频上右键另存为保存到本地。<br />方式二:如果您的浏览器比较新,直接<a href='javascript:void(0)' onclick='dw(\"" + downloadUrl + "\")'>点击此处</a>下载视频。");
  103. }
  104. });
  105. }
  106. function dw(url) {
  107. try{
  108. fetch(url).then(res => res.blob().then(blob => {
  109. var a = document.createElement('a');
  110. var url = window.URL.createObjectURL(blob);
  111. a.href = url;
  112. a.download = "kevy-download";
  113. a.click();
  114. window.URL.revokeObjectURL(url);
  115. }));
  116. }
  117. catch(err){
  118. alert("您的浏览器不支持该方式,请使用方式一");
  119. }
  120. }
  121. </script>
  122. </body>
  123. </html>

 

如果本文对你有帮助还麻烦赞一下,在此感谢啦!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/797373
推荐阅读
相关标签
  

闽ICP备14008679号