吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3512|回复: 24
收起左侧

[学习记录] tiktok批量下载视频

  [复制链接]
13100312467 发表于 2023-2-11 21:24
本帖最后由 13100312467 于 2023-2-11 21:27 编辑

  • 搜索用户名,默认第一个为该用户
    [Python] 纯文本查看 复制代码
        def search_one_user(self, keyword):        device = random.randint(1999999999999, 99999999999999)
            url =  self.api + "/aweme/v1/search/general/single/?carrier_region=US®ion=US&device_id={}&os_version=5.1.1&aid=4082&keyword={}&count=1&query_correct_type=1&search_source=normal_search&cursor=0".format(
                str(device),
                keyword)
            try:
                res = requests.get(url).content.decode('utf-8')
                res = res.replace("https", "http")
                res = json.loads(res)
                if res.get('data'):
                    for v in res.get('data'):
                        if v.get('type') == 4:
                            # print(v['user_list'][0]['user_info']['sec_uid'])
                            # return v['user_list'][0]['user_info']
                            res = self.get_user_other(v['user_list'][0]['user_info']['sec_uid'])
                            return res
            except:
                pass
            return {"status_code": "-1"}
  • 作品获取,需要参数sec_uid 和 翻页游标 cursor
    [Python] 纯文本查看 复制代码
    def post(self, sec_uid, cursor):
        device = random.randint(1999999999999, 99999999999999)
        url =  self.api + "/aweme/v1/aweme/post/?count=12&sec_user_id={}&max_cursor={}&os_api=22&device_id={}&aid=4082".format(
            sec_uid, str(cursor), str(device))
        for _ in range(10):
            try:
                res = requests.get(url).content.decode('utf-8')
                res = res.replace("https", "http")
                res = json.loads(res)
                if res.get('aweme_list'):
                    return res
            except:
                pass
        return {"status_code": "-1", 'aweme_list': []}
  • 批量下载视频
    [Python] 纯文本查看 复制代码
      def down(self, sec_uid, nickname):
            if self.downing == True:
                return "等待下载任务结束后再下载"
            self.downing = True
            self.sec_uid = sec_uid
            self.nickname = nickname
            self.Isend = False
            self.path = "." + sprit + "Download" + sprit + self.nickname + sprit
            if not os.path.exists(self.path):
                os.makedirs(self.path)
            self.max_cursor = 0
            device = random.randint(1999999999999, 99999999999999)
            url = self.api + "/aweme/v1/aweme/post/?count=12&sec_user_id={}&max_cursor={}&os_api=22&device_id={}&aid=4082".format(
                sec_uid, str(self.max_cursor), str(device))
            for _ in range(10):
                res = requests.get(url).content.decode('utf-8')
                res = res.replace("https", "http")
                res = json.loads(res)
                if res['has_more'] == 0:
                    self.Isend = True
                if res.get('aweme_list'):
                    self.max_cursor = res['max_cursor']
                    self.getVideoInfo(res.get('aweme_list'))
                    break
                else:
                    break
            self.downing = False
    
        def getNextData(self):
            if self.Isend == False:
                device = random.randint(1999999999999, 99999999999999)
                url = self.api + "/aweme/v1/aweme/post/?count=12&sec_user_id={}&max_cursor={}&os_api=22&device_id={}&aid=4082".format(
                    self.sec_uid, str(self.max_cursor), str(device))
                for _ in range(10):
                    try:
                        res = requests.get(url).content.decode('utf-8')
                        res = res.replace("https", "http")
                        res = json.loads(res)
                        if res['has_more'] == 0:
                            self.Isend = True
                        if res.get('aweme_list'):
                            self.max_cursor = res['max_cursor']
                            self.getVideoInfo(res.get('aweme_list'))
                            break
                        else:
                            break
                    except:
                        pass
    
        def getVideoInfo(self, result):
            self.author_list = []
            # 无水印视频链接
            self.video_list = []
            # 作品idvideo_list
            self.aweme_id = []
            # 唯一视频标识
            self.uri_list = []
    
            for v in range(len(result)):
                try:
                    self.author_list.append(str(result[v]['desc']))
                    self.video_list.append(
                        str(result[v]['video']['play_addr']['url_list'][0]).replace("https", "http"))
                    self.uri_list.append(
                        str(result[v]['video']['play_addr']['uri']))
                    self.aweme_id.append(str(result[v]['aweme_id']))
                except Exception as e:
                    break
            for i in range(len(self.author_list)):
                self.xhl.acquire()
                self.xc = threading.Thread(target=self.download,
                                           args=(self.author_list[i], self.uri_list[i], self.video_list[i]), daemon=True)
                self.xc.start()
            self.getNextData()
    
        def download(self, author, uri, video_):
            author = ''.join(author.splitlines())
            if len(author) > 182:
                author = author[0:180]
            file_state = test(self.path, re.sub(r'[\\/:*?"<>|\r\n]+', "_", author), uri, ".mp4")
            if file_state == True:
                self.xhl.release()
            else:
                try:
                    video = requests.get(video_)  # 视频信息
                    t_video = video.content
                    if video.status_code == 200:  # 判断是否响应成功
                        # print(self.uri_list[i])
                        v_url = self.path + sprit + re.sub(r'[\\/:*?"<>|\r\n]+', "_", author) + uri + '.mp4'
                        with open(v_url, 'wb') as file:  # 显示进度条
                            file.write(t_video)
                    self.xhl.release()
                except:
                    print("下载出错")
                # lyex_zb
                # HOLA AJJSKSKSKS | #fyp #parati #musica #cancion #lyric #letra #viral #capcut #ariela640 #lyexzbv09044g40000capqukbc77u2aho81g90.mp4
    
        def getdowninfo(self, nickname, all):
            try:
                if self.downing == False:
                    return {'count': '100', 'status': 0}
                path = "." + sprit + "Download" + sprit + nickname + sprit
                files = os.listdir(path)  # 读入文件夹
                num_png = len(files)
                return {'count': str(math.ceil(num_png * 100 / int(all))), 'status': 0}
            except:
                return {'status': -1}
  • 1_爱奇艺.jpg
  • 无需外网也可下载

免费评分

参与人数 6吾爱币 +6 热心值 +6 收起 理由
kk2apple + 1 + 1 我很赞同!
fenyeyu + 1 + 1 求成品
chenhollis + 1 + 1 大佬能出个成品吗?急需
jhjhsxs + 1 + 1 求成品,谢谢大佬!
芫恬夜悟 + 1 + 1 谢谢@Thanks!
254617517 + 1 + 1 可有成品?大佬

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

gqp 发表于 2023-2-13 15:45
什么软件
254617517 发表于 2023-2-13 20:53
本帖最后由 254617517 于 2023-2-13 22:48 编辑

有打包好的么 大佬 可开悬赏帖子啊
tenaiai 发表于 2023-2-14 14:28
kk2apple 发表于 2023-2-15 21:52
能不能出个成品?大哥
sskuye 发表于 2023-2-16 14:19
是可以不用科学上网就能下载吗?
zhangxuok2099 发表于 2023-2-17 11:29
期待有个成品。。谢谢大佬!
芫恬夜悟 发表于 2023-2-21 01:52
求成品,或者这个用这个代码的教程..
myoi2002 发表于 2023-3-1 13:53
大佬,能出个教程吗?小白看不懂啊~
喜欢做娃娃 发表于 2023-3-9 23:23
大师我也想要~~~
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止回复与主题无关非技术内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-6-5 23:31

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表