1 Star 0 Fork 2

晴云孤魂 / 抖音

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
LGPL-3.0

抖音采集

介绍

根据抖音各种链接或各种id,通过网页接口采集用户的作品,下载作品到本地。 支持用户主页链接或用户sec_uid/话题挑战和音乐原声链接或ID

使用

0x00 安装依赖

在程序目录打开命令行,输入

pip install -r requirements.txt

0x01 直接修改douyin.py中相关参数使用

  1. 实例化任务对象,可指定采集类型及采集作品数量,默认为用户作品、不限数量全部采集
    task = Task()  # 用户作品
    # task = Task(type='like', limit=10)  # 用户喜欢(不可用)
    # task = Task(type='music', limit=10)  # 音乐原声
    # task = Task(type='challenge', limit=10)  # 话题挑战
  2. 下载
    1. 单个下载
      target = "要下载的链接或ID"
      task.download(target)
    2. 批量下载
      target = 'user.txt'  # 文件路径
      task.download_batch(target)

0x02 从命令行使用exec.py

  1. 直接运行可查看命令列表,或使用-h参数查看帮助
    python exec.py
    python exec.py -h
    python exec.py download -h
    python exec.py download_batch -h
  2. 使用函数名调用程序
    --type  指定下载类型,默认值:--type=user
    --limit 指定采集数量,默认值:--limit=0(不限制)
    例如采集某用户全部作品:
    python exec.py download https://v.douyin.com/xxxx/
    python exec.py download 用户的secuid
    例如采集某音乐原声前10个作品:
    python exec.py download https://v.douyin.com/xxxx/ --type=music --limit=10
    python exec.py download 音乐ID --type=music --limit=10

TODO

  • 采集用户作品
  • 调用Aria2下载
  • 话题/原声作品采集
  • 喜欢作品采集 官方接口暂时不能用
  • 导入文件批量采集
  • 命令行调用
  • 用webview写界面
  • 打包exe 不打包了,感觉直接装个Python环境更简单

知识点

抖音相关

  • 网页接口恢复了,一次请求即可取回数据
  • UID几乎没用了,拼不成主页链接了,所有接口都是sec_uid
  • signature可固定了,不用再扣JS了
  • 作品中直接包含无水印视频地址了,不需要移动端UA也可跳转
  • 话题/音乐作品数目

Aria2相关

  • aria2p库使用体验还不错
  • 大部分Aria2下载都是通过rpc接口实现的,这个也一样
  • 需要自己下载Aria2c.exe来开启服务,所以要用代码实现自动启动服务
  • 若文件已存在则跳过下载的方法:
    1. --auto-file-renaming=false 可行,但控制台使用会报错,虽然报错不影响
    2. -c 可行,且控制台不报错
  • 添加下载任务时通过指定options = {'out': filename}指定文件名,即-d
  • Aria2会根据指定路径及指定文件名自动创建下载目录
  • Aria2指定路径及文件名中不能传入非法字符串(*|等),所以写了Download.title2path静态方法
  • 监听事件要手动停止,不停止会阻塞进程,导致程序无法关闭
  • 未发现实时获取任务进度及下载速度的函数,自己写了循环监听回调方法

Python相关

  • 通过os.popensubprocess.Popen实现子进程打开程序,无界面,不阻塞
  • 继承父类后重写init时,通过super().init()调用父类构造方法
  • 参数指定类型提示挺好用,方便调用参数的函数时自动补全
  • 可通过if 'PROGRAMFILES(X86)' in os.environ简单判断系统是否为64位
  • Pylance的自动导入依赖功能很好用,就是感觉时灵时不灵,重新开关后又可以用
  • vscode默认启动路径是当前项目路径,在launch.json中加一句"cwd": "${fileDirname}",即可,不过自动补全pylance就无法识别相对目录了

命令行模块fire相关

  • 最简单的方法就是直接一个fire.Fire(),暴露全部函数
  • 如果用类或对象暴露,类参数需要单独指定
  • 组合命令需要用不同的类,暴露的类中引入需用组合命令的类,但是在这个批量下载的场景下感觉比较繁琐,所以直接加了个参数,分两个函数来调用

笔记

偶然发现抖音网页的接口恢复了(不用频繁请求就有数据),就想修复一下之前做的采集工具,奈何代码实在是太乱了,自己看的头疼,只好稍微改了一下就扔出去了

近期也比较无聊,就打算用Python重写一版,于是就有了这篇介绍。

Python入门水平加懒癌晚期的我,从10号开始有具体想法,用了差不多3天的碎片化时间构思了程序结构(主要是了解面向对象思维),看了不少文档。

私以为自己写一个下载功能不如直接调用Aria2,毕竟功能强大且稳定,但是网上没有找到多少Python调用Aria2的示例,只好在pypi找了个还在维护的看起来不错的库(aria2p),把文档翻了一遍,强行学习了一波。

我还从来没有写过类,这是第一次,对着文档和网上的各种文章,勉强按照理解写了出来。现在觉得,其实写不写类都一样能写出同样的功能,代码也差不了多少,不过函数比较多的时候,如果不用类,会比较乱(上一版易语言的就是,很长时间不看,自己再看都头疼),类的优势还有一点,就是公有属性。

面向对象编程确实有优势,先抽象化出类,再去实例化对象,代码结构一目了然,再加上继承什么的,确实很强大。

12号晚上开始敲代码,13号差不多写出来用户作品采集和下载功能,接着14号写了话题和音乐下载,同时完成了命令行。测试通过后,就不太想动了,直到今天16号,终于把介绍写出来了。界面暂时不写了,打包exe等明天后天或者大后天晚上再做。

可以说这次重新学了很多东西,不过根据过往经验,大概没几天就全忘了,没办法,就这样吧。

2021.03.16

支持作者

有条件的朋友请扫收款码

支付宝微信收款

也可扫描下方各二维码领红包

红包码

如果能帮我助力一下就更好了

  1. 淘宝特价版0.1元购(新用户邀请)

    4¥xRMWXaaZ3W2¥ 点击跳转:https://m.tb.cn/h.4NLHzcz 新人0.1元购 速来抢

  2. 淘宝特价版帮我助力 淘宝特价版

GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.

简介

抖音爬虫,调用Aria2下载。 以及远古时期的抖音相关资料。 展开 收起
Python
LGPL-3.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Python
1
https://gitee.com/hexiyou/douyin.git
git@gitee.com:hexiyou/douyin.git
hexiyou
douyin
抖音
master

搜索帮助