Skip to content

Commit 2276bea

Browse files
committed
抖音APP视频下载
1 parent 393e64c commit 2276bea

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

douyu.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# -*- coding: UTF-8 -*-
2+
import time, sys, pymysql
3+
from danmu import DanMuClient
4+
5+
def pp(msg):
6+
print(msg.encode(sys.stdin.encoding, 'ignore').decode(sys.stdin.encoding))
7+
8+
@dmc.danmu
9+
def danmu_fn(msg):
10+
uid = msg['uid']
11+
name = msg['NickName']
12+
text = msg['Content']
13+
print(text)
14+
sql = """
15+
INSERT INTO danmu (`用户ID`,`用户昵称`,`弹幕内容`) VALUES ('%s','%s','%s')""" % (uid, name, text)
16+
try:
17+
cursor.execute(sql)
18+
# 执行sql语句
19+
conn.commit()
20+
except:
21+
# 发生错误时回滚
22+
conn.rollback()
23+
24+
25+
if __name__ == '__main__':
26+
dmc = DanMuClient('https://www.douyu.com/70537')
27+
if not dmc.isValid():
28+
print('Url not valid')
29+
#打开数据库连接:host-连接主机地址,port-端口号,user-用户名,passwd-用户密码,db-数据库名,charset-编码
30+
conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='meditation',db='douyu',charset='utf8')
31+
#使用cursor()方法获取操作游标
32+
cursor = conn.cursor()
33+
34+
dmc.start(blockThread = True)
35+
36+
# 关闭数据库连接
37+
cursor.close()
38+
conn.close()
39+
40+
41+
# pp('[%s] %s' % (msg['NickName'], msg['Content']))
42+
# result = nlp.tag(msg['Content'])
43+
# pp(msg['Content'])
44+
# print(result[0]['word'])
45+
46+
# @dmc.gift
47+
# def gift_fn(msg):
48+
# pp('[%s] sent a gift!' % msg['NickName'])
49+
50+
# @dmc.other
51+
# def other_fn(msg):
52+
# pp('Other message received')
53+

0 commit comments

Comments
 (0)