Table of Contents
## Practice it personally" >## Practice it personally
Home Java JavaBase Java programmers hand-write a Douyin video watermark removal tool

Java programmers hand-write a Douyin video watermark removal tool

Nov 27, 2020 pm 05:02 PM
java Remove watermark

java Basics introduces the method of removing watermark tools.

Java programmers hand-write a Douyin video watermark removal tool

Related learning recommendations: java basics

百cause有愿

Let me tell you why I want to make a Douyin video watermark removal tool. It’s actually because of my silly girlfriend. She actually fucked me~

One night she was in Douyin saw a very educational video, "If a man loves his wife, he should do all the housework", and then he wanted to download the video and share it with her sisters group to communicate 元夫 Thoughts.

But everyone knows that the videos downloaded from Douyin are watermarked. As a player with severe obsessive-compulsive disorder, this is not allowed. If there is no way, then look for a watermark removal tool. I searched around and found one. Either it is charging or it cannot be downloaded, and the smile on the master's face is gradually disappearing.

I joked on the side: It’s not that difficult, how about I make one for you! "Are you okay?" Then he cast a disdainful look.

Java programmers hand-write a Douyin video watermark removal tool

oops! It was just a joke, but you actually said that I am not good. This is unbearable. I have to prove it to you! Men, I just can’t stand this.

Let’s take a look at the online preview of the watermark removal tool I made: 47.93.6.5:8888/index

Java programmers hand-write a Douyin video watermark removal tool

Let’s analyze the idea of ​​​​making this watermark removal tool with everyone. When many people hear watermark removal at first glance, they subconsciously think that it is an awesome algorithm. In fact, it is an algorithm. It’s an illusion~

Go to the bottom of things

Although I have to argue, I was really confused when I first started doing it because I didn’t know where to start. What is the principle behind watermark removal? Is it possible that I still need to write an algorithm?

I found a sharing link for a Douyin video. After a little analysis, it was not difficult to find that this is a processed short link. Then this short link will definitely redirect to the real video addressURL .

https://v.douyin.com/JSkuhE4/
Copy after login

Enter the short link in the browser and get the following URL. Based on my experience, I judge that the 6820792802394262795 in URL is very likely to be The unique ID of the video, and the unique ID is usually used as an input parameter for the interface to obtain details. Hehe~ I seem to have a clue.

https://www.iesdouyin.com/share/video/6820792802394262795/
Copy after login

Java programmers hand-write a Douyin video watermark removal tool

hurry up F12 Dafa opened the console and found such an interface among many requests. It actually used the unique ID above.

https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=6820792802394262795
Copy after login


What’s even more surprising is that the data returned by the interface is so detailed, including author information, audio address, video address, and floor plan. But there is no video URL without watermark.

Only found one video with watermark URL, I was a little disappointed. I looked at the address again and found that wm was a bit similar to the name of my project. Ah, isn't it the abbreviation of watermark?

https://aweme.snssdk.com/aweme/v1/playwm/?video_id=v0200f030000bqk54kg2saj3lso3oh20&ratio=720p&line=0
Copy after login


As if I saw a glimmer of hope again, I quickly modified URL and tried it again in the browser, and sure enough, there was no watermark.

https://aweme.snssdk.com/aweme/v1/play/?video_id=v0200f030000bqk54kg2saj3lso3oh20&ratio=720p&line=0
Copy after login

Java programmers hand-write a Douyin video watermark removal tool
Only then did I discover DouyinRemove the watermark It’s so simple that it’s touching, hahaha~

Now that the principles are clear, all that's left is to implement the function step by step. The principle seems quite simple, but there are still some pitfalls in the implementation, which wastes a lot of time.

The implementation process has only three simple steps:

    1. Filter out the short video link from the input box
  • 2. Pass the short link to the backend and parse it out Video without watermark
  • URL
  • 3. Video
  • URL is passed to the front-end for preview and download
. It is not difficult for the back-end in one step. Just follow the analysis process above to parse the real video

URL in one step.

注意 :我们想得到的地址URL,都是当前短连接URL 经过重定向后的URL。而抖音有些链接是不支持浏览器访问的,所以要手动修改 User-agent 属性模拟移动端访问才可以。

/**
* @param url
* @author xiaofu
* @description 获取当前链接重定向后的url
* @date 2020/9/15 12:43
*/public static String getLocation(String url) {
        try {
            URL serverUrl = new URL(url);
            HttpURLConnection conn = (HttpURLConnection) serverUrl.openConnection();
            conn.setRequestMethod("GET");
            conn.setInstanceFollowRedirects(false);
            conn.setRequestProperty("User-agent", "ua");//模拟手机连接
            conn.connect();
            String location = conn.getHeaderField("Location");
            return location;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
Copy after login

下边是完整的后端实现,可以看到代码量非常的少。

/**
 * @author xiaofu-公众号:程序员内点事
 * @description 抖音无水印视频下载
 * @date 2020/9/15 18:44
 */@Slf4j
@Controllerpublic class DYController {
    public static String DOU_YIN_BASE_URL = "https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=";
    /**
     * @param url
     * @author xiaofu
     * @description 解析抖音无水印视频
     * @date 2020/9/15 12:43
     */
    @RequestMapping("/parseVideoUrl")
    @ResponseBody    public String parseVideoUrl(@RequestBody String url) throws Exception {
        DYDto dyDto = new DYDto();
        try {
            url = URLDecoder.decode(url).replace("url=", "");
            /**
             * 1、短连接重定向后的 URL
             */
            String redirectUrl = CommonUtils.getLocation(url);

            /**
             * 2、拿到视频对应的 ItemId
             */
            String videoUrl = "";
            String musicUrl = "";
            String videoPic = "";
            String desc = "";
            if (!StringUtils.isEmpty(redirectUrl)) {
                /**
                 * 3、用 ItemId 拿视频的详细信息,包括无水印视频url
                 */
                String itemId = CommonUtils.matchNo(redirectUrl);
                StringBuilder sb = new StringBuilder();
                sb.append(DOU_YIN_BASE_URL).append(itemId);
                String videoResult = CommonUtils.httpGet(sb.toString());
                DYResult dyResult = JSON.parseObject(videoResult, DYResult.class);
                /**
                 * 4、无水印视频 url
                 */
                videoUrl = dyResult.getItem_list().get(0)
                        .getVideo().getPlay_addr().getUrl_list().get(0)
                        .replace("playwm", "play");
                String videoRedirectUrl = CommonUtils.getLocation(videoUrl);
                dyDto.setVideoUrl(videoRedirectUrl);
                /**
                 * 5、音频 url
                 */
                musicUrl = dyResult.getItem_list().get(0).getMusic().getPlay_url().getUri();
                dyDto.setMusicUrl(musicUrl);
                /**
                 * 6、封面
                 */
                videoPic = dyResult.getItem_list().get(0).getVideo().getDynamic_cover().getUrl_list().get(0);
                dyDto.setVideoPic(videoPic);
                /**
                 * 7、视频文案
                 */
                desc = dyResult.getItem_list().get(0).getDesc();
                dyDto.setDesc(desc);
            }
        } catch (Exception e) {
            log.error("去水印异常 {}", e);
        }
        return JSON.toJSONString(dyDto);
    }}
Copy after login

前端实现也比较简单,拿到后端解析出来的视频URL 预览播放、下载就OK了。

Java programmers hand-write a Douyin video watermark removal tool

为快速实现我用了老古董JQuery,我这个年纪的人对它感情还是很深厚的,UI 框架用的 layer.js。源码后边会分享给大家,就不全贴出来了。

$.ajax({
    url: '/parseVideoUrl',
    type: 'POST',
    data: {"url": link},
    success: function (data) {
        $('.qsy-submit').attr('disabled', false);
        try {
            var rows = JSON.parse(data);
            layer.close(index);
            layer.open({
                type: 1,
                title: false,
                closeBtn: 1,
                shadeClose: true,
                skin: 'yourclass',
                content: `<p></p><p></p><p><a><button>下载视频</button></a></p><p><textarea>${rows['videoUrl']}</textarea><button>复制链接</button></p><p><a><button>下载音频</button></a></p><video><source> </source></video>`
                //content: `<video><source> </source></video>`
            });

        } catch (error) {
            layer.alert('错误信息:' + error, {
                title: '异常',
                skin: 'layui-layer-lan',
                closeBtn: 0,
                anim: 4 //动画类型
            });
            return false;
        }
    },
    error: function (err) {
        console.log(err);
        layer.close(index);
        $('.qsy-submit').attr('disabled', false);
    },
    done: function () {
        layer.close(index);
    }})})
Copy after login

注意:我们在自己的网站中引用其它网站的资源URL,由于不在同一个域名下referrer 不同,通常会遇到三方网站的防盗链拦截,所以要想正常访问三方资源,必须要隐藏请求的referrer,页面中设置如下参数。

 <!-- 解决访问视频url 请求403异常 -->
 <meta>
Copy after login

还简单做了下移动端适配,样式看着还可以,但是功能使用起来有点差强人意,后边在做优化了。

Java programmers hand-write a Douyin video watermark removal tool

总结

很多东西就是这样,没认真研究之前总感觉深不可测,可一旦接触到技术的本质,又开始笑自己之前好蠢,懂与不懂有时就查那么一层窗户纸。

The above is the detailed content of Java programmers hand-write a Douyin video watermark removal tool. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Square Root in Java Square Root in Java Aug 30, 2024 pm 04:26 PM

Guide to Square Root in Java. Here we discuss how Square Root works in Java with example and its code implementation respectively.

Perfect Number in Java Perfect Number in Java Aug 30, 2024 pm 04:28 PM

Guide to Perfect Number in Java. Here we discuss the Definition, How to check Perfect number in Java?, examples with code implementation.

Random Number Generator in Java Random Number Generator in Java Aug 30, 2024 pm 04:27 PM

Guide to Random Number Generator in Java. Here we discuss Functions in Java with examples and two different Generators with ther examples.

Armstrong Number in Java Armstrong Number in Java Aug 30, 2024 pm 04:26 PM

Guide to the Armstrong Number in Java. Here we discuss an introduction to Armstrong's number in java along with some of the code.

Weka in Java Weka in Java Aug 30, 2024 pm 04:28 PM

Guide to Weka in Java. Here we discuss the Introduction, how to use weka java, the type of platform, and advantages with examples.

Smith Number in Java Smith Number in Java Aug 30, 2024 pm 04:28 PM

Guide to Smith Number in Java. Here we discuss the Definition, How to check smith number in Java? example with code implementation.

Java Spring Interview Questions Java Spring Interview Questions Aug 30, 2024 pm 04:29 PM

In this article, we have kept the most asked Java Spring Interview Questions with their detailed answers. So that you can crack the interview.

Break or return from Java 8 stream forEach? Break or return from Java 8 stream forEach? Feb 07, 2025 pm 12:09 PM

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is

See all articles