Java implementation of Douyin short video to watermark window program

Description

I am also a beginner who has just learned Java, and there may be many irregularities. This program is for reference only and the functions have been implemented.

The response of the program is a bit slow, just click the button

The principle of watermark removal for Douyin short videos: https://blog.csdn.net/qq_29556507/article/details/106943093

Before reading the program, you can manually analyze it with a computer, and you will know the general process and how we generally need to operate it.

When using a computer to parse out the real watermark-free address step by step, you need to pay attention: After you find the website starting with this https://aweme.snssdk.com/aweme, don’t forget to change playwm to play and then visit it. The article on the principle of watermarking is written.

But if you use a computer to access the modified URL, the computer cannot load it, the phone can jump to the real non-watermarked address, and then open it with Google Chrome to download the non-watermarked video,
Insert picture description here
Insert picture description here
so our Java program needs to modify the user when accessing -agent to simulate mobile phone access In the
program:
public void doGet()


The two methods of private void parseResult(InputStream inStream, String charSet) are to modify the sent data to simulate mobile phone access.

Program demonstration

Insert picture description here
Insert picture description here

Just download through Google Chrome

Code area

import javax.swing.*;
import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.net.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.*;
import java.io.InputStreamReader;

public class dy {
    
    
    String str="";
    String num="";
    String wz="";
    String strend = "";
    public static void main(String [] args) {
    
    
        dy dy = new dy();
        //创建窗口并进行布局
        JFrame f = new JFrame("02抖音去水印1.0");
        f.setLayout(null);
        f.setBounds(0,0,410,300);
        JLabel jl1 = new JLabel("地址:");
        jl1.setBounds(10,10,30,30);
        f.add(jl1);
        JTextField tf = new JTextField();
        tf.setBounds(45,12,280,25);
        f.add(tf);
        JLabel jl2 = new JLabel("打开:");
        jl2.setBounds(10,40,30,30);
        f.add(jl2);
        JTextArea ta = new JTextArea();
        ta.setLineWrap(true);
        ta.setBounds(45,40,280,200);
        ta.setEditable(false);
        JScrollPane jsp = new JScrollPane(ta);
        jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        jsp.setBounds(45,40,280,200);
        f.add(jsp);
        JButton b = new JButton("OK");
        b.setHorizontalTextPosition(SwingConstants.CENTER);
        b.setVerticalTextPosition(SwingConstants.BOTTOM);
        b.setBounds(328,60,60,130);
        f.add(b);
        //设置按钮点击事件
        b.addActionListener(new ActionListener() {
    
    
            @Override
            public void actionPerformed(ActionEvent e) {
    
    
                //获得tf文本框输入的需要解析的地址
                String text="";
                text=tf.getText();
                dy.str=text;
                if (text.length()==0){
    
    
                    ta.setText("地址为空");
                    return;
                }else {
    
    
                    try {
    
    
                        //对地址进行解析
                        dy.getNum();
                        dy.getWZ();
                        dy.doGet();
                        ta.setText(dy.strend);
                        //将解析完的网址自动复制到粘贴板上
                        Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
                        Transferable tText = new StringSelection(dy.strend);
                        clip.setContents(tText, null);
                        //在tf文本框中显示复制成功提示
                        tf.setText("解析成功已复制到粘贴板,请去浏览器打开下载");

                    } catch (IOException ioException) {
    
    
                        ta.setText("地址错误");
                    }catch (StringIndexOutOfBoundsException e1){
    
    
                        ta.setText("地址错误");
                    }
                }

            }
        });
        //当tf文本框获得焦点时,自动清空内容
        tf.addFocusListener(new FocusListener() {
    
    
            @Override
            //获得焦点
            public void focusGained(FocusEvent e) {
    
    
                tf.setText("");
            }
            //失去焦点
            @Override
            public void focusLost(FocusEvent e) {
    
    

            }
        });
        //使窗口能正常关闭
        f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        //显示窗口
        f.setVisible(true);

    }
    //获得视频的item_ids,也就是视频网址上的那个19位的数字串
    public void getNum()throws IOException{
    
    
        URL url = null;
        url = new URL(str);
        HttpURLConnection conn= null;
        conn = (HttpURLConnection)url.openConnection();
        conn.setDoOutput(true);

        try {
    
    
            conn.getResponseCode();
        } catch (IOException e) {
    
    
            e.printStackTrace();
        }
        String realUrl=conn.getURL().toString();
        num=realUrl.substring(38,57);
    }
    //获得视频的地址https://aweme.snssdk.com/aweme开头的那个网址,并将网址中的playwm改为play
    public void getWZ()throws IOException{
    
    
        URL url= null;
        url = new URL("https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids="+num);
        try {
    
    
            BufferedReader reader=new BufferedReader(new InputStreamReader(url.openStream()));
            String line;
            String str="";
            while((line=reader.readLine())!=null){
    
    
                str+=line;
            }
            reader.close();
            wz="https://aweme.snssdk.com/aweme/v1/play"+str.substring(str.indexOf("/?video"),str.indexOf("&line=0"))+"&line=0";
        } catch (IOException e) {
    
    
            e.printStackTrace();
        }
    }
    //解决https://aweme.snssdk.com/aweme开头的网址只能手机端访问才能跳转的问题
    //并获得跳转后的真正的无水印地址
    public void doGet()throws IOException{
    
    


        URL obj = new URL(wz);
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();

        con.setRequestMethod("GET");
        // 设置请求头
        con.setRequestProperty("user-agent", "Mozilla/5.0 ");

        int responseCode = con.getResponseCode();

        parseResult(con.getInputStream(), "GB2312");
    }
    private void parseResult(InputStream inStream, String charSet) {
    
    
        try {
    
    
            InputStreamReader stream = new InputStreamReader(inStream, charSet);
            BufferedReader br = new BufferedReader(stream);
            String inputLine;
            StringBuffer response = new StringBuffer();
            while ((inputLine = br.readLine()) != null) {
    
    
                response.append(inputLine);
            }
            String str = response.toString();
            strend=str.substring(str.indexOf("http"),str.indexOf("\">F"));
            System.out.println(strend);
        } catch (IOException e) {
    
    
            e.printStackTrace();
        }
    }
}

Guess you like

Origin blog.csdn.net/z2742431760/article/details/108678470