17 Commits

Author SHA1 Message Date
b8b793e292 网络错误人性化提示 2019-02-01 20:17:39 +08:00
e4fef3df33 修复:脑子不够用 判断反了 2019-02-01 19:37:03 +08:00
54fa20c4f7 紧急更新:新礼物模板 2019-02-01 19:36:42 +08:00
89edd10dc2 Emeg Fix : While Lottery is None , Program will crash 2019-02-01 16:44:38 +08:00
ebe01566c0 Fix: Not show Error Msg when not living 2019-02-01 16:34:14 +08:00
a0f76eb00b Merge branch 'master' of https://github.com/q792602257/XiguaLiveDanmakuHelper 2019-02-01 16:33:25 +08:00
f81c2811ce 录播助手更新:避免因为未开播而导致出现错误提示 2019-02-01 16:31:32 +08:00
c12d8cf4bb Remove Testing Things 2019-02-01 16:26:47 +08:00
77d7f35d25 Add: Actions When Upload Finished 2019-02-01 16:20:50 +08:00
84ca4d0a62 修改isValidRoom判断,避免误更改导致无法获取弹幕 2019-02-01 16:17:21 +08:00
4a59cbcf82 抽奖信息可从弹幕中提取,可实时检测抽奖避免刷屏 2019-02-01 13:33:01 +08:00
1b920fa55c 修复:因isValidRoom判断错误导致的无法获取弹幕,修正抽奖结束时间判断 2019-02-01 13:08:09 +08:00
81f730ea68 各种适配新Android Api,修复各种Bug 2019-01-31 23:05:48 +08:00
a1cfc9b914 Update : Replace delete downloaded files With move to oss 2019-01-31 17:23:18 +08:00
81763fdf37 Emeg Update : Fix isLive is always True 2019-01-31 13:09:21 +08:00
884122b007 Emeg Update: dynamic roomId fix 2019-01-30 19:07:07 +08:00
8c0320c97e 全面改为AndroidApi,添加抽奖识别及消息提示 2019-01-29 13:50:29 +08:00
12 changed files with 267 additions and 109 deletions

10
Chat.py
View File

@ -1,19 +1,27 @@
from User import User from User import User
from Lottery import Lottery
class Chat: class Chat:
content: str ="" content: str =""
user: User=None user: User=None
filterString:list = ["",]
isFiltered = False
def __init__(self, json=None): def __init__(self, json=None, lottery:Lottery = None):
if json: if json:
self.parse(json) self.parse(json)
if lottery:
self.filterString.append(lottery.content)
def parse(self, json): def parse(self, json):
self.user = User(json) self.user = User(json)
if "extra" in json: if "extra" in json:
if "content" in json["extra"]: if "content" in json["extra"]:
self.content = json["extra"]['content'] self.content = json["extra"]['content']
if self.content in self.filterString:
self.isFiltered = True
def __str__(self): def __str__(self):
return "{} : {}".format(self.user,self.content) return "{} : {}".format(self.user,self.content)

0
Digg.py Normal file
View File

19
Gift.py
View File

@ -6,7 +6,7 @@ class Gift:
ID:int = 0 ID:int = 0
count:int = 0 count:int = 0
roomID:int = 0 roomID:int = 0
giftList:dict = {10001: {"Name": "西瓜", "Price": 0}} giftList:dict = {}
amount:int = 0 amount:int = 0
user:User = None user:User = None
@ -16,20 +16,25 @@ class Gift:
def parse(self, json): def parse(self, json):
self.user = User(json) self.user = User(json)
if "extra" in json: if "common" in json and json["common"] is not None:
if Gift.roomID != int(json["common"]["room_id"]):
Gift.roomID = int(json["common"]["room_id"])
self.update()
if "extra" in json and json["extra"] is not None:
if "present_info" in json["extra"] and json["extra"]['present_info'] is not None: if "present_info" in json["extra"] and json["extra"]['present_info'] is not None:
self.ID = int(json["extra"]['present_info']['id']) self.ID = int(json["extra"]['present_info']['id'])
self.count = json["extra"]['present_info']['repeat_count'] self.count = json["extra"]['present_info']['repeat_count']
elif "present_end_info" in json["extra"] and json["extra"]['present_end_info'] is not None: elif "present_end_info" in json["extra"] and json["extra"]['present_end_info'] is not None:
self.ID = int(json["extra"]['present_end_info']['id']) self.ID = int(json["extra"]['present_end_info']['id'])
self.count = json["extra"]['present_end_info']['count'] self.count = json["extra"]['present_end_info']['count']
if self.ID in self.giftList: if self.ID != 0 and self.ID in self.giftList:
self.amount = self.giftList[self.ID]["Price"] * self.count self.amount = self.giftList[self.ID]["Price"] * self.count
else:
self.update()
@staticmethod def update(self):
def update(roomID): p = requests.get("https://i.snssdk.com/videolive/gift/get_gift_list?room_id={roomID}"
Gift.roomID = roomID "&version_code=730&device_platform=android".format(roomID = self.roomID))
p = requests.get("https://i.snssdk.com/videolive/gift/get_gift_list?room_id={roomID}".format(roomID= roomID))
d = p.json() d = p.json()
if "gift_info" not in d: if "gift_info" not in d:
print("错误:礼物更新失败") print("错误:礼物更新失败")

71
Lottery.py Normal file
View File

@ -0,0 +1,71 @@
import requests
import time
from LuckyUser import LuckyUser
class Lottery:
ID: int = 0
isActive = False
content = ""
isFinished = False
luckyUsers = []
joinedUserCount = 0
prizeName = ""
finish:int = 0
def __init__(self, json=None):
if json:
self.parse(json)
def parse(self, json):
if "lottery_info" in json and json["lottery_info"] is not None:
self.isActive = int(json["lottery_info"]["status"]) > 0
self.ID = json["lottery_info"]["lottery_id"]
for i in json["lottery_info"]['conditions']:
if i['type'] != 3:
continue
self.content = i["content"]
self.joinedUserCount = int(json["lottery_info"]["candidate_num"])
self.prizeName = json["lottery_info"]["prize_info"]["name"]
_delta = int(json["lottery_info"]["draw_time"]) - int(json["lottery_info"]["current_time"])
self.finish = time.time()+_delta+1
elif "extra" in json and json["extra"] is not None:
if "lottery_info" in json["extra"] and json["extra"]["lottery_info"] is not None:
return self.parse(json["extra"])
def update(self):
if self.isActive:
if not self.isFinished and self.finish > time.time():
self.checkFinished()
return True
return False
def checkFinished(self):
p = requests.get("https://i.snssdk.com/videolive/lottery/check_user_right?lottery_id={}"
"&version_code=730&device_platform=android".format(
self.ID
))
d = p.json()
if d["base_resp"]["status_code"] != 0:
self.isActive = False
self.isFinished = False
return
self.isActive = int(d["lottery_info"]["status"]) > 0
self.isFinished = int(d["lottery_info"]["status"]) == 2
self.joinedUserCount = int(d["lottery_info"]["candidate_num"])
if self.isFinished:
for i in d["lottery_info"]["lucky_users"]:
self.luckyUsers.append(LuckyUser(i))
def __str__(self):
if self.isFinished:
ret = "恭喜以下中奖用户:\n"
for i in self.luckyUsers:
ret += "> {} {}\n".format(i,self.prizeName)
ret += "> 参与人数:{}".format(self.joinedUserCount)
return ret
elif self.isActive:
return "正在抽奖中。。。\n" \
"> 参与人数:{}".format(self.joinedUserCount)
else:
return "抽奖已失效"

19
LuckyUser.py Normal file
View File

@ -0,0 +1,19 @@
from User import User
class LuckyUser:
user = None
count = 0
def __init__(self, json=None):
if json:
self.parse(json)
def parse(self, json):
self.user = User()
self.user.ID = json['user_id']
self.user.name = json['user_name']
self.count = int(json["grant_count"])
def __str__(self):
return "用户 {} 获得了 {}".format(self.user,self.count)

View File

@ -28,7 +28,8 @@ class MemberMsg:
elif self.type == 1: elif self.type == 1:
return "{} 进入了房间".format(self.user) return "{} 进入了房间".format(self.user)
else: else:
print(self.type) if self.content == "":
return "未知消息{} 关于用户 {}".format(self.type, self.user)
return self.content.format(self.user) return self.content.format(self.user)
def __unicode__(self): def __unicode__(self):

View File

@ -4,10 +4,11 @@
界面版:[q792602257/XiguaDanmakuHelperGUI](https://github.com/q792602257/XiguaDanmakuHelperGUI "C# ver") 界面版:[q792602257/XiguaDanmakuHelperGUI](https://github.com/q792602257/XiguaDanmakuHelperGUI "C# ver")
### 计划更新: ### 计划更新:
+ Digg消息点亮了喜欢实例化
+ √ ~~使用android app协议~~ + √ ~~使用android app协议~~
已使用 已使用
除从用户ID获取roomID及判断是否在播其他均改为Android Api 除从用户ID获取roomID外其他均改为Android Api
+ √ ~~闲的无聊的时候看一看有没有好用的GUI轮子可以用用~~ + √ ~~闲的无聊的时候看一看有没有好用的GUI轮子可以用用~~

12
User.py
View File

@ -23,10 +23,14 @@ class User:
self.type = json["extra"]["user_room_auth_status"]["user_type"] self.type = json["extra"]["user_room_auth_status"]["user_type"]
self.block = json["extra"]["user_room_auth_status"]["is_block"] self.block = json["extra"]["user_room_auth_status"]["is_block"]
self.mute = json["extra"]["user_room_auth_status"]["is_silence"] self.mute = json["extra"]["user_room_auth_status"]["is_silence"]
elif "data" in json: elif "room" in json and json["room"] is not None:
if "anchorInfo" in json["data"]: if "user_info" in json["room"] and json["room"]["user_info"] is not None:
self.ID = json["data"]['anchorInfo']['id'] self.ID = json["room"]['user_info']['user_id']
self.name = json["data"]['anchorInfo']['name'] self.name = json["room"]['user_info']['name']
elif "anchor" in json and json["anchor"] is not None:
if "user_info" in json["anchor"] and json["anchor"]['user_info'] is not None:
self.ID = json["anchor"]['user_info']['user_id']
self.name = json["anchor"]['user_info']['name']
if self.type is None: if self.type is None:
self.type = 0 self.type = 0
if isinstance(self.level, str): if isinstance(self.level, str):

View File

@ -2,10 +2,12 @@ import os
import sys import sys
import time import time
import requests
from Gift import Gift from Gift import Gift
from Lottery import Lottery
from MemberMsg import MemberMsg from MemberMsg import MemberMsg
from User import User from User import User
from Chat import Chat from Chat import Chat
from api import XiGuaLiveApi as Api from api import XiGuaLiveApi as Api
import msvcrt import msvcrt
@ -31,7 +33,9 @@ def readInput(caption, default, timeout: int = 5):
msvcrt.putch(b"\b") msvcrt.putch(b"\b")
if len(input) == 0: if len(input) == 0:
start_time = time.time() start_time = time.time()
elif 32 <= ord(chr) <= 126: # space_char elif 32 > ord(chr) or 255 > ord(chr) > 126: # space_char
continue
else:
input += chr.decode("utf8") input += chr.decode("utf8")
if len(input) == 0 and (time.time() - start_time) > timeout: if len(input) == 0 and (time.time() - start_time) > timeout:
break break
@ -119,7 +123,7 @@ class WinMain(Api):
def onJoin(self, user: User): def onJoin(self, user: User):
set_cmd_text_color(BACKGROUND_WHITE | FOREGROUND_BLACK) set_cmd_text_color(BACKGROUND_WHITE | FOREGROUND_BLACK)
print("感谢", user, "加入了粉丝团") print("欢迎", user, "加入了粉丝团")
resetColor() resetColor()
def onSubscribe(self, user: User): def onSubscribe(self, user: User):
@ -136,7 +140,14 @@ class WinMain(Api):
def onChat(self, chat: Chat): def onChat(self, chat: Chat):
if SHOW_ALL: if SHOW_ALL:
print(chat) resetColor()
if not chat.isFiltered:
print(chat)
def onLottery(self, i:Lottery):
set_cmd_text_color(FOREGROUND_WHITE | BACKGROUND_DARKGRAY)
print(i)
resetColor()
def onPresent(self, gift: Gift): def onPresent(self, gift: Gift):
if SHOW_ALL: if SHOW_ALL:
@ -164,24 +175,14 @@ def warning(*args):
if __name__ == "__main__": if __name__ == "__main__":
room = 97621754276 # 永恒 name = "永恒de草薙"
# room = 75366565294
# room = 83940182312 #Dae
resetColor() resetColor()
print("西瓜直播弹幕助手 by JerryYan") print("西瓜直播弹幕助手 by JerryYan")
if len(sys.argv) > 1: if len(sys.argv) > 1:
if sys.argv[-1] == "a": name = sys.argv[1]
SHOW_ALL = True
try:
room = int(sys.argv[1])
except:
pass
else: else:
try: name = readInput("请输入主播用户名(请用拼音字母),默认为", name, 3)
room = int(readInput("请输入用户ID号默认为永恒的ID号", room, 3)) api = WinMain(name)
except ValueError:
pass
api = WinMain(room)
print("进入", api.roomLiver, "的直播间") print("进入", api.roomLiver, "的直播间")
if not api.isValidRoom: if not api.isValidRoom:
input("房间不存在") input("房间不存在")
@ -190,11 +191,14 @@ if __name__ == "__main__":
print("=" * 30) print("=" * 30)
while True: while True:
if api.isLive: if api.isLive:
os.system("title {}".format(api.getTitle()))
try: try:
os.system("title {}".format(api.getTitle()))
api.getDanmaku() api.getDanmaku()
except requests.exceptions.BaseHTTPError:
print("网络错误,请确认网络")
time.sleep(5)
except Exception as e: except Exception as e:
warning(e) print(e.__str__())
time.sleep(1) time.sleep(1)
else: else:
set_cmd_text_color(FOREGROUND_RED) set_cmd_text_color(FOREGROUND_RED)

144
api.py
View File

@ -4,6 +4,7 @@ from MemberMsg import MemberMsg
from User import User from User import User
from Gift import Gift from Gift import Gift
from Chat import Chat from Chat import Chat
from Lottery import Lottery
import requests import requests
import time import time
@ -16,18 +17,18 @@ class XiGuaLiveApi:
isLive: bool = False isLive: bool = False
isValidRoom: bool = False isValidRoom: bool = False
_rawRoomInfo = {} _rawRoomInfo = {}
name: str = ""
roomID: int = 0 roomID: int = 0
roomTitle: str = "" roomTitle: str = ""
roomLiver: User = None roomLiver: User = None
roomPopularity: int = 0 roomPopularity: int = 0
roomMember: int = 0
_cursor:str = "0" _cursor:str = "0"
_updRoomCount:int = 0
lottery:Lottery = None
def __init__(self, room: int): def __init__(self, name: str = "永恒de草薙"):
self.room = room self.name = name
self.updRoomInfo() self.updRoomInfo()
Gift.update(self.roomID)
self._enterRoom()
def _updateRoomInfo(self, json): def _updateRoomInfo(self, json):
if "extra" in json: if "extra" in json:
@ -52,7 +53,8 @@ class XiGuaLiveApi:
pass pass
def onChat(self, chat: Chat): def onChat(self, chat: Chat):
print(chat) if not chat.isFiltered:
print(chat)
def onEnter(self, msg: MemberMsg): def onEnter(self, msg: MemberMsg):
print("提示 :", msg) print("提示 :", msg)
@ -61,7 +63,7 @@ class XiGuaLiveApi:
print("消息 :", user, "关注了主播") print("消息 :", user, "关注了主播")
def onJoin(self, user: User): def onJoin(self, user: User):
print("感谢", user, "加入了粉丝团") print("欢迎", user, "加入了粉丝团")
def onMessage(self, msg: str): def onMessage(self, msg: str):
print("消息 :", msg) print("消息 :", msg)
@ -70,53 +72,81 @@ class XiGuaLiveApi:
print("用户", user, "点了喜欢") print("用户", user, "点了喜欢")
def onLeave(self, json: any): def onLeave(self, json: any):
print("消息 :", "主播离开一小会") print("消息 :", "主播离开")
def _enterRoom(self): def onLottery(self, i:Lottery):
if not self.isValidRoom: print("中奖消息 :", i)
return
p = s.post("https://i.snssdk.com/videolive/room/enter&version_code=730" def updRoomInfo(self):
"&device_platform=android", if self.isLive:
data="room_id={roomID}&version_code=730" p = s.post("https://i.snssdk.com/videolive/room/enter?version_code=730"
"&device_platform=android".format(roomID=self.roomID), "&device_platform=android",
headers={"Content-Type":"application/x-www-form-urlencoded"}) data="room_id={roomID}&version_code=730"
"&device_platform=android".format(roomID=self.roomID),
headers={"Content-Type":"application/x-www-form-urlencoded"})
d = p.json()
self.isValidRoom = d["base_resp"]["status_code"] == 0
if d["base_resp"]["status_code"] != 0:
return False
if "room" not in d and d["room"] is None:
self.apiChangedError("Api发生改变请及时联系我")
return False
self._rawRoomInfo = d["room"]
self.isLive = d["room"]["status"] == 2
self.roomLiver = User(d)
self.roomTitle = d["room"]["title"]
self.roomPopularity = d["room"]["user_count"]
l = Lottery(d)
if l.isActive:
self.lottery = l
return True
else:
p = s.get("https://security.snssdk.com/video/app/search/live/?version_code=730&device_platform=android"
"&format=json&keyword={}".format(self.name))
d = p.json()
if "data" in d and d["data"] is not None:
for i in d["data"]:
if i["block_type"] != 0:
continue
if len(i["cells"]) == 0:
return
self.isValidRoom = True
self.isLive = i["cells"][0]["anchor"]["user_info"]["is_living"]
self.roomID = int(i["cells"][0]["anchor"]["room_id"])
self.roomLiver = User(i["cells"][0])
if self.isLive:
return self.updRoomInfo()
else:
return False
@staticmethod
def findRoomByUserId(userId:int):
p = s.get("https://live.ixigua.com/api/room?anchorId={room}".format(room=userId))
if DEBUG: if DEBUG:
print(p.text) print(p.text)
d = p.json()
if "data" not in d or "title" not in d["data"] or "id" not in d["data"]:
XiGuaLiveApi.apiChangedError("无法获取RoomID请与我联系")
return XiGuaLiveApi()
return XiGuaLiveApi(d["data"]["id"])
def searchLive(self, keyword): @staticmethod
def searchLive(keyword):
ret = [] ret = []
p = s.get("https://security.snssdk.com/video/app/search/live/?version_code=730&device_platform=android" p = s.get("https://security.snssdk.com/video/app/search/live/?version_code=730&device_platform=android"
"&format=json&keyword={}".format(keyword)) "&format=json&keyword={}".format(keyword))
d = p.json() d = p.json()
if "data" not in d: if "data" in d:
for i in d["data"]: for i in d["data"]:
if i["block_type"] != 2: if i["block_type"] != 0:
continue continue
for _i in i["cells"]: for _i in i["cells"]:
ret.append(_i["room"]) ret.append(_i["room"])
return ret return ret
def updRoomInfo(self):
p = s.get("https://live.ixigua.com/api/room?anchorId={room}".format(room=self.room))
if DEBUG:
print(p.text)
d = p.json()
if "data" not in d or "title" not in d["data"] or "id" not in d["data"]:
self.apiChangedError("无法获取RoomID请与我联系")
return
self.isValidRoom = True
self._rawRoomInfo = d["data"]
self.roomLiver = User(d)
self.roomTitle = d["data"]["title"]
self.roomID = d["data"]["id"]
self._updateRoomInfo(d)
if "status" in d["data"] and d["data"]["status"] == 2:
self.isLive = True
else:
self.isLive = False
def getDanmaku(self): def getDanmaku(self):
if not self.isValidRoom: if not self.isValidRoom:
self.updRoomInfo()
return return
p = s.get("https://i.snssdk.com/videolive/im/get_msg?cursor={cursor}&room_id={roomID}" p = s.get("https://i.snssdk.com/videolive/im/get_msg?cursor={cursor}&room_id={roomID}"
"&version_code=730&device_platform=android".format( "&version_code=730&device_platform=android".format(
@ -133,9 +163,6 @@ class XiGuaLiveApi:
self._cursor = d["extra"]["cursor"] self._cursor = d["extra"]["cursor"]
if DEBUG: if DEBUG:
print("Cursor", self._cursor) print("Cursor", self._cursor)
if len(d['data']) == 0:
self.updRoomInfo()
return
for i in d['data']: for i in d['data']:
if DEBUG: if DEBUG:
print(i) print(i)
@ -148,7 +175,7 @@ class XiGuaLiveApi:
elif i["common"]['method'] == "VideoLiveRoomAdMessage": elif i["common"]['method'] == "VideoLiveRoomAdMessage":
self.onAd(i) self.onAd(i)
elif i["common"]['method'] == "VideoLiveChatMessage": elif i["common"]['method'] == "VideoLiveChatMessage":
self.onChat(Chat(i)) self.onChat(Chat(i, self.lottery))
elif i["common"]['method'] == "VideoLiveMemberMessage": elif i["common"]['method'] == "VideoLiveMemberMessage":
self._updateRoomInfo(i) self._updateRoomInfo(i)
self.onEnter(MemberMsg(i)) self.onEnter(MemberMsg(i))
@ -162,30 +189,41 @@ class XiGuaLiveApi:
self.onLike(User(i)) self.onLike(User(i))
else: else:
pass pass
if self.lottery is None or self.lottery.ID == 0:
self.lottery = Lottery(i)
self._updRoomCount += 1
if self.lottery is not None and self.lottery.ID != 0:
self.lottery.update()
if self.lottery.isFinished:
self.onLottery(self.lottery)
self.lottery = None
if self._updRoomCount > 120 or len(d['data']) == 0:
self.updRoomInfo()
self._updRoomCount = 0
return
if __name__ == "__main__": if __name__ == "__main__":
room = 97621754276 # 永恒 name = "永恒de草薙"
# room = 75366565294 if len(sys.argv) > 2:
# room = 83940182312 #Dae
if len(sys.argv) > 1:
if sys.argv[-1] == "d": if sys.argv[-1] == "d":
DEBUG = True DEBUG = True
try: name = sys.argv[1]
room = int(sys.argv[1])
except ValueError:
pass
print("西瓜直播弹幕助手 by JerryYan") print("西瓜直播弹幕助手 by JerryYan")
api = XiGuaLiveApi(room) api = XiGuaLiveApi(name)
print("进入", api.roomLiver, "的直播间")
if not api.isValidRoom: if not api.isValidRoom:
print(api.roomID)
input("房间不存在") input("房间不存在")
sys.exit() sys.exit()
print("进入", api.roomLiver, "的直播间")
print("=" * 30) print("=" * 30)
while True: while True:
if api.isLive: if api.isLive:
try: try:
api.getDanmaku() api.getDanmaku()
except requests.exceptions.BaseHTTPError:
print("网络错误,请确认网络")
time.sleep(5)
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1) time.sleep(1)

View File

@ -2,6 +2,7 @@
import os import os
import re import re
import shutil
from datetime import datetime from datetime import datetime
import rsa import rsa
@ -11,6 +12,8 @@ import hashlib
import requests import requests
from urllib import parse from urllib import parse
from config import config
class VideoPart: class VideoPart:
def __init__(self, path, title='', desc=''): def __init__(self, path, title='', desc=''):
@ -222,7 +225,7 @@ class Bilibili:
"timeout": 900, "timeout": 900,
"auth": "os=upos&cdn=upcdnws&uid=&net_state=4&device=&build=&os_version=&ak=×tamp=&sign=", "auth": "os=upos&cdn=upcdnws&uid=&net_state=4&device=&build=&os_version=&ak=×tamp=&sign=",
"OK": 1 "OK": 1
} }
""" """
json = r.json() json = r.json()
upos_uri = json['upos_uri'] upos_uri = json['upos_uri']
@ -322,8 +325,12 @@ class Bilibili:
"videos": self.videos} "videos": self.videos}
) )
print(r.text) print(r.text)
for _p in self.files: if config["mv"]:
os.remove(_p.path) for _p in self.files:
shutil.move(_p.path, config["mtd"])
elif config["del"]:
for _p in self.files:
os.remove(_p.path)
def appendUpload(self, def appendUpload(self,
aid, aid,
@ -422,8 +429,6 @@ class Bilibili:
"videos": self.videos} "videos": self.videos}
) )
print(r.text) print(r.text)
for _p in self.files:
os.remove(_p.path)
def addChannel(self, name, intro=''): def addChannel(self, name, intro=''):
""" """

View File

@ -23,12 +23,16 @@ class downloader(XiGuaLiveApi):
self.updPlayList() self.updPlayList()
def updPlayList(self): def updPlayList(self):
if "playInfo" not in self._rawRoomInfo or "Main" not in self._rawRoomInfo["playInfo"]: if self.isLive:
if self.playlist is None: if "stream_url" in self._rawRoomInfo:
self.apiChangedError("无法获取直播链接") if self.playlist is None:
self.playlist = False self.apiChangedError("无法获取直播链接")
self.playlist = False
else:
self.playlist = self._rawRoomInfo["stream_url"]["alternate_pull_url"]
self.playlist = self.playlist.replace("_uhd","").replace("_sd","").replace("_ld","")
else: else:
self.playlist = self._rawRoomInfo["playInfo"]["Main"]["1"]["Url"]["HlsUrl"] print("未开播,等待开播")
def onLike(self, user): def onLike(self, user):
pass pass
@ -75,8 +79,11 @@ class downloader(XiGuaLiveApi):
print("{} : Add Sequence {}".format(datetime.strftime(datetime.now(), "%y%m%d %H%M"), print("{} : Add Sequence {}".format(datetime.strftime(datetime.now(), "%y%m%d %H%M"),
len(self.files))) len(self.files)))
q.put(i) q.put(i)
else:
print("PlayList {}".format(self.playlist))
self.genNewName() self.genNewName()
def genNewName(self): def genNewName(self):
if len(self.files) > 800: if len(self.files) > 800:
q.put(True) q.put(True)
@ -119,7 +126,7 @@ def upload(date=datetime.strftime(datetime.now(), "%Y_%m_%d")):
if i is True: if i is True:
print("自动投稿中,请稍后") print("自动投稿中,请稍后")
b.finishUpload(config["t_t"].format(date), 17, config["tag"], config["des"], b.finishUpload(config["t_t"].format(date), 17, config["tag"], config["des"],
source="https://live.ixigua.com/userlive/97621754276", no_reprint=0) source=config["src"], no_reprint=0)
break break
print("{} : Upload {}".format(datetime.strftime(datetime.now(), "%y%m%d %H%M"), i)) print("{} : Upload {}".format(datetime.strftime(datetime.now(), "%y%m%d %H%M"), i))
try: try:
@ -134,18 +141,15 @@ b = Bilibili()
b.login(config["b_u"], config["b_p"]) b.login(config["b_u"], config["b_p"])
if __name__ == "__main__": if __name__ == "__main__":
room = 97621754276 # 永恒 name = "永恒de草薙"
# room = 75366565294 # room = 75366565294
# room = 83940182312 #Dae # room = 83940182312 #Dae
# room = 5947850784 #⑦ # room = 5947850784 #⑦
# room = 58649240617 #戏 # room = 58649240617 #戏
if len(sys.argv) > 1: if len(sys.argv) > 1:
try: name = sys.argv[1]
room = int(sys.argv[1])
except ValueError:
pass
print("西瓜直播录播助手 by JerryYan") print("西瓜直播录播助手 by JerryYan")
api = downloader(room) api = downloader(name)
print("进入", api.roomLiver, "的直播间") print("进入", api.roomLiver, "的直播间")
if not api.isValidRoom: if not api.isValidRoom:
input("房间不存在") input("房间不存在")
@ -168,10 +172,7 @@ if __name__ == "__main__":
ut = threading.Thread(target=upload, args=(d,)) ut = threading.Thread(target=upload, args=(d,))
ut.setDaemon(True) ut.setDaemon(True)
ut.start() ut.start()
try: api.preDownload()
api.preDownload()
except:
pass
time.sleep(3) time.sleep(3)
else: else:
if d is not None: if d is not None:
@ -181,7 +182,8 @@ if __name__ == "__main__":
uq.put(True) uq.put(True)
isUpload = False isUpload = False
else: else:
pass del config
from config import config
# print("主播未开播等待1分钟后重试") # print("主播未开播等待1分钟后重试")
time.sleep(60) time.sleep(60)
api.updRoomInfo() api.updRoomInfo()