欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python下载抖音无水印视频

程序员文章站 2022-04-11 16:52:34
...
import re
import requests
import json

HEADERS = {
    "accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
    "accept-encoding":"deflate",
    "accept-language":"en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4",
    "cache-control":"no-cache",
    'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36',
}

H0 = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36"
H1 = "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"


class Vibrato():
    """docstring for Vibrato"""
    def __init__(self):
        super(Vibrato, self).__init__()
        self.url = "https://www.iesdouyin.com/share/video/6902052766936583432/"
        self.headers = HEADERS

    def __get_real_url(self):
        session = requests.Session()
        req = session.get(self.url , timeout = 5 , headers = self.headers)
        vid = req.url.split("/")[5]
        videoInfo = session.get("https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=" + vid,
            timeout = 5 , headers = self.headers)
        playAddr = re.findall(r'https://aweme.snssdk.com/aweme[\S]*?"',videoInfo.text)[0][:-1]
        parsedAddr = playAddr.replace("/playwm/","/play/")
        desc = json.loads(videoInfo.text)["item_list"][0]["desc"]
        return vid,parsedAddr,session,desc

    def __download(self, vid, info, session,desc):
        self.headers['user-agent'] = H1
        videoBin = session.get(info,timeout = 5, headers = self.headers )
        try:
            with open('%s.mp4' % (desc),'wb') as fb:
                fb.write(videoBin.content)
            self.headers['user-agent'] = H0
            # print("下载完成!",'%s.mp4' % (desc))
            return "下载完成!{}.mp4".format(desc)
        except:
            with open('%s\%s.mp4' % (vid),'wb') as fb:
                fb.write(videoBin.content)
            self.headers['user-agent'] = H0
            return "下载完成!{}.mp4".format(desc)

    def run(self, url):
        try:
            self.url = url
            vid,info,session,desc = self.__get_real_url()
            return self.__download(vid, info, session,desc)
        except Exception as e:
            raise e

使用方法:

url:抖音视频分享链接

Vibrato().run(url)

打包好的exe:

复制抖音视频分享链接,点击下载即可。

python下载抖音无水印视频

扫码关注公众号,发送抖音下载即可获取exe文件下载链接

python下载抖音无水印视频