java开发最新获取抖音无水印视频和背景音乐

java版最新获取抖音无水印视频和背景音乐,
这个工具已经被我放到我的网站上做成了在线抖音无水印获取工具:
在线演示地址:http://www.yzcopen.com/video/dywsy

废话不多说先看效果

用到jsoup,自行下载

代码如下:

     public static void main(String[] args) throws Exception {
              String url1 = "三里屯街拍,祝愿大家高考顺利🥤 https://v.douyin.com/JNDRc6L/ 复制此链接,打开【抖音短视频】,直接观看视频!";
             System.out.println(getDyMp4Jsoup(url1));
         }

 public static Connection getConn(String url) {
            return Jsoup.connect(url).userAgent("Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1").ignoreContentType(true);
        }
        public static Map<String,Object> dyhtml(String url){
            Map<String,Object> restmap = new HashMap<String,Object>();
         
              try {      
                  Connection con = getConn(url);
                      String recurl = getRedirectURL(con);
                   
                     String[] rest = recurl.split("video/");  
                     
                    String[] mid =  rest[1].split("/");
                 String rceurl = "https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids="+mid[0];

                      Connection reccon = getConn(rceurl);
                    Response  res  = reccon.ignoreContentType(true).timeout(10000).execute();
              
              com.alibaba.fastjson.JSONObject json = com.alibaba.fastjson.JSONObject.parseObject(res.body());
                List<Map<String,Object>> maprest = (List<Map<String, Object>>) json.get("item_list"); 
                     
                Map<String,Object> re = maprest.get(0);
                Map<String,Object> video = (Map<String, Object>) re.get("video");
                Map<String,Object> play_addr = (Map<String, Object>) video.get("play_addr");
                String urls = ((List<String>)play_addr.get("url_list")).get(0);
                    
                urls = urls.replace("playwm", "play");
                restmap.put("urls", urls);
                 
                Map<String,Object> music = (Map<String, Object>) re.get("music");
                Map<String,Object> play_url = (Map<String, Object>) music.get("play_url");
                String uri = play_url.get("uri")+"";
                 
                restmap.put("uri", uri);
                  return restmap;
                 } catch (Exception e) {
                         e.printStackTrace();
                 }

                return restmap;
           
           }
        
        /**
         * 解析抖音
         * @param args
         * @throws Exception 
         * @throws Exception
         */
        public static Map<String,Object>  getDyMp4Jsoup(String url1) throws Exception {
                //过滤链接,获取http连接地址
                String finalUrl = decodeHttpUrl(url1);
                String  matchUrl  = null;
                Map<String,Object> restmap = dyhtml(finalUrl);
              
                matchUrl  = restmap.get("urls")+"";
            
                Connection connreturl =  getConn(matchUrl);
                String urlrest =  getRedirectURL(connreturl);
                System.out.println(urlrest);
                System.out.println(restmap.get("uri"));      
                      
                restmap.put("urlrest", urlrest);
                return restmap;
            
        }
        
        
        private static String getRedirectURL(Connection conn) throws IOException {
            return conn.followRedirects(false).timeout(10000).execute().header("location");
        }
        
        public static String decodeHttpUrl(String url) {
            int start = url.indexOf("http");
            int end = url.lastIndexOf("/");
            String decodeurl = url.substring(start, end);
            return decodeurl;
        }
    
         

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
水印视频的下载可以通过调用API接口实现。可以使用Python或Java编写相关代码。 Python实现: ``` import requests import json url = 'https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?itemId=' item_id = '视频ID' headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3' } response = requests.get(url=url+item_id, headers=headers) data = json.loads(response.text) video_url = data['item_list'][0]['video']['play_addr']['url_list'][0] video = requests.get(video_url, headers=headers) with open('video.mp4', 'wb') as f: f.write(video.content) ``` Java实现: ``` import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; public class DownloadVideo { public static void main(String[] args) throws IOException { String url = "https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?itemId="; String item_id = "视频ID"; String user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"; String video_url = ""; URL real_url = new URL(url+item_id); HttpURLConnection connection = (HttpURLConnection) real_url.openConnection(); connection.setRequestMethod("GET"); connection.setRequestProperty("User-Agent", user_agent); connection.setRequestProperty("Accept", "*/*"); connection.setRequestProperty("Content-Type", "application/json"); connection.setRequestProperty("Connection", "keep-alive"); connection.connect(); InputStream in = connection.getInputStream(); byte[] buf = new byte[1024]; int len = 0; StringBuffer stringBuffer = new StringBuffer(); while((len=in.read(buf))!=-1){ stringBuffer.append(new String(buf,0,len)); } in.close(); JSONObject jsonObject = JSON.parseObject(stringBuffer.toString()); video_url = jsonObject.getJSONObject("item_list").getJSONObject("video").getJSONArray("play_addr").getJSONObject(0).getString("url_list").get(0); real_url = new URL(video_url); connection = (HttpURLConnection) real_url.openConnection(); connection.setRequestMethod("GET"); connection.setRequestProperty("User-Agent", user_agent); connection.setRequestProperty("Accept", "*/*"); connection.setRequestProperty("Content-Type", "application/octet-stream"); connection.setRequestProperty("Connection", "keep-alive"); connection.connect(); in = connection.getInputStream(); FileOutputStream out = new FileOutputStream("video.mp4"); while((len=in.read(buf))!=-1){ out.write(buf,0,len); } in.close(); out.close(); } } ``` 注意:以上代码仅供学习参考,请勿用于非法用途。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值