1 Star 0 Fork 18

dehoho / 抖音

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

抖音采集

介绍

Python取数据 + Vue写界面 + Aria2下载

根据抖音各种链接或各种id,通过网页接口采集视频作品,并下载作品到本地。

支持用户主页链接或sec_uid/话题挑战和音乐原声链接或ID。

支持下载喜欢列表(需喜欢列表可见) 部分用户可下载喜欢列表(需喜欢列表可见),部分用户不可下载(即使喜欢列表可见也不行),目前不知道原因哈,猜测跟账号有关,不知道是设置问题还是账号注册日期问题(和sec_uid带不带下划线无关),测试账号结果见user.txt

测试环境:Python3.7+pip最新+Win10_x64

依赖安装失败自行百度或更换Python及pip版本解决;UI启动报错猜测是pywebview库调用的浏览器不兼容Vue;

使用

0x00 安装依赖

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

pip install -r requirements.txt

0x01 使用UI界面

双击打开启动.bat,或者在程序目录打开命令行,输入

python ui.py

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

完全不懂Python的朋友用命令行操作界面

有基础的可查看源码使用,或查看当前页源码,因为之前写的注释内容被注释掉了

0x03 从命令行使用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 MS4wLjABAAAAl7TJWjJJrnu11IlllB6Mi5V9VbAsQo1N987guPjctc8 --type=like --limit=10
    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也可跳转
  • 话题/音乐作品数目
  • 2021.04.02 喜欢列表也有数据了

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就无法识别相对目录了
  • 用pipreqs一键生成当前项目依赖:cmd切换到项目路径,pipreqs ./ --encoding=utf-8 --force

命令行模块fire相关

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

UI模块pywebview相关

  • 可以把一个类的实例暴露给页面js_api,通过pywebview.api.func().then(() => {})调用Python函数
  • 也可以把Flask等服务实例暴露给页面js_api(无需url参数),在内部实现index.html
  • Python中通过window.evaluate_js('JS代码')调用JS方法
  • 在UI中,类的初始化无法传参,所以需要重新定义init
  • 在UI中,需要公开的类实例方法不能以下划线_开头
  • 创建UI时设置的窗口宽高,好像和网页中大小不一样,值需要比网页中大一些

笔记

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

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

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

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

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

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

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

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

2021.03.16


拖了差不多3周,终于把UI写了点。

清明节前一天晚上开始动的,结果一晚上就改了几行代码,啥也没写,到前天晚上才又开始写。然后一通百度,两三天晚上写出来这点东西。

而且这次发现,之前不能采集用户喜欢,不是接口问题,是因为用户设置了隐藏,这没办法,不过用户公开的(比如自己)是可以采集喜欢的。

其实好久之前就想过HTML做界面了,当时是想用精易web浏览器来加载页面的,后来写Python还专门找miniblink的库。当时找到了一个更新比较活跃的,但是已经忘了叫什么了,因为在找的过程中发现了pywebview这个库,感觉挺强大的,也比较完善,还不用自己带浏览器内核,所以才有这次尝试。

界面只写了基础功能,限制采集数量没写,就一个input,但是感觉丑,就不加了。

不打算打包exe了,浪费时间,打包了还很大。况且Python环境安装很简单,百度一堆教程,其实无脑点下一步就行了。

这个软件到这里差不多就算完了,以后有机会写个快手的。

2021.04.08


支持作者

有条件的朋友请扫收款码

支付宝微信收款

当然扫描下方各二维码领红包更好,白嫖红包

红包码

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下载,Vue做界面。 以及远古时期的抖音相关资料。Python3.7+ 展开 收起
Python
LGPL-3.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

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

搜索帮助