用Python实现一个简单的批量无水印快手抖音批量下载器

文中介绍的方法仅限学习使用,切勿做非法用途

结合上一篇说了一个通过在手机上面搭建Http服务去破解App的密钥,如何真正的实现一个批量下载视频的功能呢?
我们用Python3简单的写了一个脚本,可以搜索特定用户,选择用户后,下载这个用户所有的视频。
项目地址:https://github.com/tbruceyu/AppCaller , 欢迎Star

关键接口

  1. 搜索用户的接口:http://api.ksapisrv.com/rest/n/search/user
  2. 查找用户视频接口:http://api.ksapisrv.com/rest/n/feed/profile2
  3. 用AppCaller搭建的破解密钥接口

有了这些接口后,我们就可以开始写代码了,代码很简单,我直接贴出来了:

# -*- coding: utf-8 -*-
import json
import os
from urllib import request
import requests

__KEY_SERVER_HOST = 'http://172.16.70.147:8889/api'


def search_user(keyword, pcursor=None):
    key_req_json = {
        'url': 'http://api.ksapisrv.com/rest/n/search/user?app=0&kpf=ANDROID_PHONE&ver=6.4&c=BAIDU',
        'commonParams': 'mod=huawei%28MI%208%29&appver=6.4.0.9003&ftt=K-F-T&isp=CTCC&kpn=KUAISHOU&'
                        'lon=33.337841&language=zh-cn&sys=ANDROID_9&max_memory=512&ud=0&country_code=cn&'
                        'pm_tag=11694575470&oc=BAIDU&hotfix_ver=&did_gt=1539073091012&iuid=&net=WIFI&'
                        'did=ANDROID_2ec0f9e99f32fb16&lat=33.979012',
        'field': {
            'keyword': keyword,
            'client_key': '3c2cd3f3',
            'os': 'android',
        },
        'header': {
            'User-Agent': ['kwai-android'],
            'Accept-Language': ['zh-cn'],
            'X-REQUESTID': ['193601906'],
            'Host': ['api.ksapisrv.com']
        },
        'method': 'post'
    }
    if pcursor is not None:
        key_req_json['field'] = {
            'keyword': keyword,
            'pcursor': str(pcursor),
            'client_key': '3c2cd3f3',
            'os': 'android',
        }
    res_json = requests.post(url=__KEY_SERVER_HOST, data=json.dumps(key_req_json)
                             , headers={'Content-Type': 'application/json'})
    request_data = json.loads(res_json.text)
    url = request_data['url']
    field_data = request_data['field']

    header_data = {}
    for k in request_data['header'].keys():
        header_data[k] = request_data['header'][k][0]
    search_data = json.loads(requests.post(url=url, data=field_data
                                           , headers=header_data).text)
    if len(search_data['users']) <= 0:
        return []
    return search_data['pcursor'], search_data['users']


def get_video(uid, pcursor=None):
    key_req_json = {
        'url': 'http://api.ksapisrv.com/rest/n/feed/profile2?app=0&kpf=ANDROID_PHONE&ver=6.4&c=BAIDU',
        'commonParams': 'mod=huawei%28MI%208%29&appver=6.4.0.9003&ftt=K-F-T&isp=CTCC&kpn=KUAISHOU&'
                        'lon=33.337841&language=zh-cn&sys=ANDROID_9&max_memory=512&ud=0&country_code=cn&'
                        'pm_tag=11694575470&oc=BAIDU&hotfix_ver=&did_gt=1539073091012&iuid=&net=WIFI&'
                        'did=ANDROID_2ec0f9e99f32fb16&lat=33.979012',
        'field': {
            "token": "", "user_id": str(uid), "lang": "zh", "count": "30", "privacy": "public",
            "referer": "ks://profile/133107719/5202502011931030729/1_i/1648554269758459910_h139/8",
            "browseType": "1", "client_key": "3c2cd3f3", "os": "android"
        },
        'header': {
            'User-Agent': ['kwai-android'],
            'Accept-Language': ['zh-cn'],
            'X-REQUESTID': ['193601906'],
            'Host': ['api.ksapisrv.com']
        },
        'method': 'post'
    }
    if pcursor is not None:
        key_req_json['field'] = {
            "token": "", "pcursor": str(pcursor), "user_id": str(uid), "lang": "zh", "count": "30", "privacy": "public",
            "referer": "ks://profile/133107719/5202502011931030729/1_i/1648554269758459910_h139/8",
            "browseType": "1", "client_key": "3c2cd3f3", "os": "android"
        }
    res_json = requests.post(url=__KEY_SERVER_HOST, data=json.dumps(key_req_json)
                             , headers={'Content-Type': 'application/json'})
    request_data = json.loads(res_json.text)
    url = request_data['url']
    field_data = request_data['field']

    header_data = {}
    for k in request_data['header'].keys():
        header_data[k] = request_data['header'][k][0]
    user_data = json.loads(requests.post(url=url, data=field_data
                                         , headers=header_data).text)
    return user_data['pcursor'], user_data['feeds']


if __name__ == "__main__":
    keyword = input("输入关键字:")

    user_count = 0
    pcursor, search_res = search_user(keyword)
    if len(search_res) == 0:
        print("没有找到用户")
        exit(1)
    users = search_res
    target_user = None
    while True:
        for user in users:
            print("{0}. {1}".format(user_count, user['user_name']))
            user_count += 1
        print("请输入用户编号(翻页请直接按回车键):")
        choose = input("输入关键字:")
        if choose.isnumeric():
            target_user = users[int(choose)]
            break
        else:
            pcursor, new_users = search_user(keyword, pcursor)
            users += new_users
    print(target_user)
    pcursor = None
    if not os.path.exists("output"):
        os.mkdir("output")
    feed_count = 0
    while True:
        pcursor, feeds = get_video(target_user['user_id'], pcursor)
        if len(feeds) == 0:
            print("已经全部下载完成!")
            break
        for feed in feeds:
            video_url = feed['main_mv_url']
            if video_url is None:
                video_url = feed['main_mv_urls'][0]
            target_file = "./output/{0}.mp4".format(feed_count)
            if not os.path.exists(target_file):
                try:
                    request.urlretrieve(video_url, target_file)
                except Exception as e:
                    print("下载失败:" + video_url)
            feed_count += 1

操作步骤

废话不多说,开始行动吧:

  1. 首先把项目clone下来,然后./gradlew assembleDebug编译我们的App。
  2. 编译成功后安装AppCaller:adb install -r app/build/outputs/apk/debug/app-debug.apk
  3. 然后安装slave程序:adb install -r clients/kuaishou.apk
  4. 在手机上打开AppCaller,添加快手App,然后点击开启
    在这里插入图片描述
  5. 查看手机的IP地址:ifconfig ,查看wlan0的IP地址
  6. 把tools/download.py的__KEY_SERVER_HOST = ‘http://172.16.70.147:8889/api’ IP地址改为手机上面的IP地址
  7. 运行脚本,然后输入用户名,选择一个用户,就可以开始下载啦。输出如下:
xxx@bogon:~/Projects/AppCaller/tools$ python3.7 download.py
输入关键字:手工耿
0. V手工~耿
1. 手工耿弟
2. 陌路離腸(耿湾手工鞋垫)
3. 耿哥手工玫瑰
4. 手工耿
5. 手工耿 非物质文化遗产
6. 耿湾?手工?豆腐
7. 手工编制耿梅
8. 耿耿?DIY手工制作
9. 耿姐的手工针线43387
10. 耿氏手工豆腐
11. 耿记手工辣条
12. 耿青春的手工传奇
13. 耿马勐永宋永芳传统手工傣
14. 耿大妮~全国手工活外放
15. 耿姐手工编织手链脚链腰链
16. 五棵树手工干豆腐耿丽娜
17. 机械加工耿师
18. 东宿村粉面粉条加工耿保忠
19. 招缝纫机工!耿文龙177362
20. 数控车床对外加工耿增旺
21. 精众化工耿常见
22. 昭通架子工耿华
23. 外架工耿国
24. ,建筑电工耿振勇138338914
25. 数控车工,耿哥
26. 农民工耿哥
27. 御通花园财源建工耿洪泉
28. 我是机修工耿涛
29. 羊毛衫加工,耿利东
请输入用户编号(翻页请直接按回车键):
输入关键字:0
下载视频成功:http://jsmov2.a.yximgs.com/upic/2019/10/22/20/BMjAxOTEwMjIyMDAxNDhfMzMyODQyMTExXzE4Nzc4OTc3ODI1XzFfMw==_b_B3f60bcff9bbda1a56505e434f59966bb.mp4?tag=1-1572264843-p-0-z65nxxy1b6-8a39387debd35122&type=hot
下载视频成功:http://jsmov2.a.yximgs.com/upic/2019/10/16/11/BMjAxOTEwMTYxMTM1NDhfMzMyODQyMTExXzE4NTY2MzY5MjAyXzFfMw==_b_Bded1516bcf28343539c26b3cc2e9a469.mp4?tag=1-1572264843-p-0-8mrzya9pw3-4db9ce8b186a3901&type=hot
下载视频成功:http://jsmov2.a.yximgs.com/upic/2019/10/10/20/BMjAxOTEwMTAyMDM2NDdfMzMyODQyMTExXzE4NDAxNzkyMzAwXzFfMw==_b_B2d039e11c3263491d8c3001ac7a844fc.mp4?tag=1-1572264843-p-0-oeziowhxdt-5b5f7260c44b14b2&type=hot
下载视频成功:http://jsmov2.a.yximgs.com/upic/2019/10/03/08/BMjAxOTEwMDMwODAyMTZfMzMyODQyMTExXzE4MTIwOTQ3MjExXzFfMw==_b_Bca3c27612dc62ea907887edd48ac6ccf.mp4?tag=1-1572264843-p-0-wjycc4zqsi-045d9b68d9f8a7fb&type=hot
下载视频成功:http://jsmov2.a.yximgs.com/upic/2019/10/01/10/BMjAxOTEwMDExMDM4MjRfMzMyODQyMTExXzE4MDI4MzgzODk2XzFfMw==_b_B072a824dbf29fbabeddff896d671ebcd.mp4?tag=1-1572264843-p-0-kwqvozhrff-039073ab5a551e15&type=hot
......
``
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值