mirror of
https://github.com/imgyh/tiktok.git
synced 2025-05-30 02:39:17 +08:00
refactor(tiktok tiktokcommand): 完善命令行参数提示与打印信息提示
This commit is contained in:
parent
f84dfd79e7
commit
e012abf592
@ -390,6 +390,9 @@ class TikTok(object):
|
||||
# 暂时使用不需要xg的接口
|
||||
max_cursor = 0
|
||||
self.awemeList = []
|
||||
|
||||
print("[ 提示 ]:正在获取接口数据请稍后...\r\n")
|
||||
|
||||
while True:
|
||||
if mode == "post":
|
||||
post_url = 'https://www.iesdouyin.com/aweme/v1/web/aweme/post/?sec_user_id=%s&count=%s&max_cursor=%s&aid=1128&version_name=23.5.0&device_platform=android&os_version=2333' % (
|
||||
@ -397,6 +400,9 @@ class TikTok(object):
|
||||
elif mode == "like":
|
||||
post_url = 'https://www.iesdouyin.com/web/api/v2/aweme/like/?sec_uid=%s&count=%s&max_cursor=%s&aid=1128&version_name=23.5.0&device_platform=android&os_version=2333' % (
|
||||
sec_uid, count, max_cursor)
|
||||
else:
|
||||
print("[ 错误 ]:模式选择错误, 仅支持post和like, 请检查后重新运行!\r")
|
||||
return None
|
||||
res = requests.get(url=post_url, headers=self.headers)
|
||||
|
||||
datadict = json.loads(res.text)
|
||||
@ -404,7 +410,6 @@ class TikTok(object):
|
||||
print("[ 错误 ]:未找到数据, 请检查后重新运行!\r")
|
||||
return None
|
||||
|
||||
print("[ 提示 ]:正在获取接口数据请稍后...\r\n")
|
||||
for aweme in datadict["aweme_list"]:
|
||||
# 获取 aweme_id 使用这个接口 https://www.iesdouyin.com/aweme/v1/web/aweme/detail/
|
||||
aweme_id = aweme["aweme_id"]
|
||||
|
@ -27,13 +27,13 @@ def argument():
|
||||
type=str, required=True)
|
||||
parser.add_argument("--path", "-p", help="下载保存位置",
|
||||
type=str, required=True)
|
||||
parser.add_argument("--music", "-m", help="是否下载视频中的音乐(True/False)",
|
||||
parser.add_argument("--music", "-m", help="是否下载视频中的音乐(True/False), 默认为True",
|
||||
type=bool, required=False, default=True)
|
||||
parser.add_argument("--cover", "-c", help="是否下载视频的封面(True/False), 当下载视频时有效",
|
||||
parser.add_argument("--cover", "-c", help="是否下载视频的封面(True/False), 默认为True, 当下载视频时有效",
|
||||
type=bool, required=False, default=True)
|
||||
parser.add_argument("--avatar", "-a", help="是否下载作者的头像(True/False)",
|
||||
parser.add_argument("--avatar", "-a", help="是否下载作者的头像(True/False), 默认为True",
|
||||
type=bool, required=False, default=True)
|
||||
parser.add_argument("--mode", "-M", help="link是个人主页时, 设置下载发布的作品(post)或喜欢的作品(like)",
|
||||
parser.add_argument("--mode", "-M", help="link是个人主页时, 设置下载发布的作品(post)或喜欢的作品(like), 默认为post",
|
||||
type=str, required=False, default="post")
|
||||
args = parser.parse_args()
|
||||
|
||||
@ -43,26 +43,26 @@ def argument():
|
||||
def main():
|
||||
args = argument()
|
||||
tk = TikTok()
|
||||
url = tk.getShareLink(args.sharelink)
|
||||
url = tk.getShareLink(args.link)
|
||||
key_type, key = tk.getKey(url)
|
||||
if key is None or key_type is None:
|
||||
exit(0)
|
||||
return
|
||||
elif key_type == "user":
|
||||
datalist = tk.getUserInfo(key, args.mode, 35)
|
||||
tk.userDownload(awemeList=datalist, music=args.music, cover=args.cover, avatar=args.avatar,
|
||||
savePath=args.savepath)
|
||||
savePath=args.path)
|
||||
elif key_type == "aweme":
|
||||
datadict = tk.getAwemeInfo(key)
|
||||
tk.awemeDownload(awemeDict=datadict, music=args.music, cover=args.cover, avatar=args.avatar,
|
||||
savePath=args.savepath)
|
||||
savePath=args.path)
|
||||
elif key_type == "live":
|
||||
live_json = tk.getLiveInfo(key)
|
||||
if not os.path.exists(args.savepath):
|
||||
os.mkdir(args.savepath)
|
||||
if not os.path.exists(args.path):
|
||||
os.mkdir(args.path)
|
||||
|
||||
# 保存获取到json
|
||||
print("[ 提示 ]:正在保存获取到的信息到result.json\r\n")
|
||||
with open(os.path.join(args.savepath, "result.json"), "w", encoding='utf-8') as f:
|
||||
with open(os.path.join(args.path, "result.json"), "w", encoding='utf-8') as f:
|
||||
f.write(json.dumps(live_json, ensure_ascii=False, indent=2))
|
||||
f.close()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user