In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to handwrite a Douyin video watermarking tool", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn how to handwrite a Douyin video to watermark tool!
Every cause must have its result.
Tell me why I want to make a Douyin video watermarking tool, in fact, it is because of my sand sculpture girlfriend, she just me ~
One night she saw a very educational video on Douyin saying, "if a man loves his wife, he should do all the housework." then it wants to download the video and share the experience of her sister group driver.
But we all know that the videos downloaded by Douyin are watermarked, and as a player with severe obsessive-compulsive disorder, this is not allowed. If there is no way, then find out if there is a watermarking tool. If you look around for a fee, or you can't download it, the smile on the Lord's face is gradually disappearing.
I joked on the side: it's not that hard, or I'll make one for you! "can you do it?" And then cast a look of disdain.
Oops! It was a joke and said I couldn't stand it. I have to prove it to you! Men, I can't stand that.
First, take a look at the online preview effect of the de-watermarking tool I made: http://47.93.6.5:8888/index.
Below, let's analyze the idea of doing this watermarking tool. Many people subconsciously feel that it is a kind of bull algorithm when they first hear it. In fact, this is an illusion.
get to the bottom of
Although I had to fight for breath, I was really confused when I first started, because I didn't know where to start and how to watermark. Do I have to write an algorithm?
Found a Douyin video sharing link, a little analysis, it is not difficult to find that this is a processed short link, then this short link must be redirected to the real video address URL.
Https://v.douyin.com/JSkuhE4/
Enter a short link in the browser and get the following URL. Based on my experience, 6820792802394262795 in URL is probably the only ID of the video, and the only ID is usually used as an input parameter for the API to get details. Hey, I seem to have a clue.
Https://www.iesdouyin.com/share/video/6820792802394262795/
Quickly sacrifice F12 Dafa to open the console, in many requests found such an interface, it unexpectedly used the only ID above.
Https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=6820792802394262795
What is more surprising is that the data returned by the interface is called a detail, including author information, audio address, video address and floor plan. But there is no video URL without watermark. Only found a watermarked video URL, a little lost, I looked at this address, found that wm and my project name is a bit similar, ah, is not the abbreviation of watermark watermark?
Https://aweme.snssdk.com/aweme/v1/playwm/?video_id=v0200f030000bqk54kg2saj3lso3oh30&ratio=720p&line=0
As if I saw a glimmer of hope, I quickly modified the URL and tried again in the browser, and sure enough, there was no watermark.
Https://aweme.snssdk.com/aweme/v1/play/?video_id=v0200f030000bqk54kg2saj3lso3oh30&ratio=720p&line=0
Only then did I find that the simple watermark of Douyin is touching, ~
set an example by personally taking part
Now that the principle is clear, what is left is to realize the function step by step, the principle looks very simple, but we still encounter a little pit in the implementation, which wastes a lot of time.
There are only three simple steps to implement:
1. Filter the video short connection from the input box.
2. The short connection is transmitted to the backend to resolve the unwatermarked video URL.
3. The video URL is passed to the front end for preview and download.
There is no difficulty in the backend. Just parse the real video URL step by step according to the process analyzed above.
Note: the address URL we want is the redirected URL of the current short connection URL. However, some links in Douyin do not support browser access, so you have to manually modify the User-agent attribute to simulate mobile access.
/ * * @ param url* @ author xiaofu* @ description get the current link redirected 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"); / / Analog phone connection conn.connect (); String location = conn.getHeaderField ("Location"); return location;} catch (Exception e) {e.printStackTrace ();} return "";}
The following is a complete back-end implementation, and you can see that the amount of code is very small.
/ * * @ author xiaofu- official account: something inside programmers * @ description Douyin unwatermarked video download * @ date 18:44 on 2020-9-15 * / @ 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 Resolution Douyin unwatermarked video * @ date 12:43 on 2020-9-15 * / @ 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) after short connection redirection; / * 2. Get the corresponding ItemId * / String videoUrl = ""; String musicUrl = ""; String videoPic = "" String desc = ""; if (! StringUtils.isEmpty (redirectUrl)) {/ * 3. Use ItemId to get video details, including unwatermarked video 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. Unwatermarked video 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, cover * / videoPic = dyResult.getItem_list (). Get (0). GetVideo (). GetDynamic_cover (). GetUrl_list (). Get (0); dyDto.setVideoPic (videoPic) / * 7, video copy * / desc = dyResult.getItem_list (). Get (0). GetDesc (); dyDto.setDesc (desc);} catch (Exception e) {log.error ("de-watermark exception {}", e) } return JSON.toJSONString (dyDto);}}
The implementation of the front-end is also relatively simple. The video URL parsed from the back-end is previewed and played and downloaded to OK.
I used antique JQuery for quick implementation, and people of my age still have a deep affection for it. Layer.js is used in the UI framework. The source code will be shared with you later, so not all of it will be posted.
$.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: `copy link
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.