python 24行代码简单实现通过分享链接下载无水印视频

/ 21评 / 0

网上这类工具很多,但是我还是想自己实现一下。

研究了一下,主要流程如下:

  1. 访问地址:https://v.douyin.com/J8cHNas/,他帮我们自动跳转到一个页面。
  2. 不用管页面如何,我们可以直接打开f12看到请求,稍微看一下,会发现所有的视频信息(包含视频路径、名称、作者等等)都存储在这个请求中:https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=6841990853624433920&dytk=
  3. 直接从接口获取到video的链接:https://aweme.snssdk.com/aweme/v1/playwm/?video_id=v0200f4f0000brpq51lahtm68p8nvh6g&ratio=720p&line=0
  4. 把链接中的playwm替换成play(去掉wm就行),就可以获得无水印的地址了,如:https://aweme.snssdk.com/aweme/v1/play/?video_id=v0200f4f0000brpq51lahtm68p8nvh6g&ratio=720p&line=0
  5. 注:无水印的视频,只能在移动端播放,所以我们需要在user-agent中模拟手机端的操作。
  6. 至于如何得出去掉wm就可以无水印的结论,有经验的可以尝试看抖音时抓包,可以得到他的视频链接,简单对比就可以得出结论了。

代码如下:

import requests
import re
import json
#获取抖音地址
url=input("请输入抖音地址\n")
userAgent = "Mozilla/5.0 (Linux; Android 8.0.0; Pixel 2 XL Build/OPD1.170816.004) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Mobile Safari/537.36"
header = {
    "Referer": "https://v.douyin.com/",
    'User-Agent': userAgent,
}
#获取到视频id
r = requests.get(url,headers = header)
url=r.url
id=url.split("video/")[1].split("/?")[0]
#获取到有水印视频地址
url="https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids="+id
r = requests.get(url,headers = header)
#获取到无水印视频地址
video=json.loads(r.content)["item_list"][0]
url=video["video"]["play_addr"]["url_list"][0]
url=url.replace("playwm","play")
#开始下载
r = requests.get(url,headers = header)
with open(video["desc"]+".mp4", "wb") as code:
     code.write(r.content)
     print("下载成功")
input("按下回车退出程序")

比较简单,其实看懂了逻辑非常好实现。

但,如果是实用党,也可以直接下载成品:

  1. skrt说道:

    发布一个完整的代码吧!!@#!小白搞定不了啊

  2. google说道:

    After going over a handful of the articles on your web site, I honestly appreciate your way of writing a blog.
    I bookmarked it to my bookmark website list and will be checking back in the near future.
    Take a look at my web site as well and let me know what you think.

  3. Harriett说道:

    Your style is really unique in comparison to other people I have
    read stuff from. I appreciate you for posting when you
    have the opportunity, Guess I will just book mark this site.

  4. Truly no matter if someone doesn’t understand then its up to
    other people that they will assist, so here it happens.

  5. Wow, this article is good, my younger sister is analyzing such things, so I am going to inform her.

  6. Brenda说道:

    Yes! Finally someone writes about 롤대리.

  7. zoom magician说道:

    Generally I do not read post on blogs, however I wish to say that this write-up very forced me to try and do it!
    Your writing taste has been amazed me. Thanks,
    very great post.

  8. Janet说道:

    I am not sure where you are getting your information, but good topic.
    I needs to spend some time learning more or understanding more.
    Thanks for wonderful information I was looking for this info for my mission.

  9. I’m really loving the theme/design of your website.
    Do you ever run into any internet browser compatibility
    issues? A number of my blog audience have complained about my
    blog not operating correctly in Explorer but looks great in Opera.
    Do you have any ideas to help fix this problem?

  10. Isabella说道:

    Thanks for sharing your thoughts on python. Regards

  11. Car garage说道:

    Hello my friend! I want to say that this article is amazing,
    nice written and come with approximately all important infos.
    I would like to peer more posts like this .

  12. Simply want to say your article is as astounding.
    The clarity in your post is simply cool and i can assume you’re an expert on this subject.
    Well with your permission allow me to grab your RSS feed to keep
    updated with forthcoming post. Thanks a million and please
    carry on the gratifying work.

  13. If some one desires to be updated with most recent technologies after that he must be visit this web site and be up to date all the
    time.

  14. Good post. I certainly love this site. Continue the good work!

  15. Simply desire to say your article is as astounding.
    The clearness in your publish is just great and i can assume
    you’re knowledgeable in this subject. Well along with your permission let me to take hold of your feed to keep up to date with impending post.
    Thanks a million and please carry on the enjoyable work.

  16. Run meme说道:

    I do not even know how I ended up here, but I
    thought this post was good. I don’t know who you
    are but definitely you’re going to a famous blogger if you are not already ;
    ) Cheers!

  17. Thanks in favor of sharing such a nice thinking, article is fastidious,
    thats why i have read it completely

  18. Check This Out说道:

    I loved as much as you will receive carried out right here.
    The sketch is tasteful, your authored material stylish.
    nonetheless, you command get got an impatience over that you wish be
    delivering the following. unwell unquestionably come further formerly again as exactly the same nearly a lot often inside case you shield this increase.

  19. Hi there, just became aware of your blog through Google, and found that it
    is truly informative. I’m gonna watch out for brussels.
    I’ll be grateful if you continue this in future.
    Numerous people will be benefited from your writing. Cheers!

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注