-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
21 changed files
with
366 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "3.5.0" | ||
__version__ = "3.5.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from ._api import parse_body, request | ||
from ._api import CMD, pack_proto, parse_body, request_http, request_ws |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,127 @@ | ||
import datetime | ||
import sys | ||
import time | ||
|
||
import yarl | ||
|
||
from ...__version__ import __version__ | ||
from ...const import APP_BASE_HOST, APP_SECURE_SCHEME, POST_VERSION | ||
from ...core import HttpCore | ||
from ...core import Account, HttpCore, WsCore | ||
from ...exception import TiebaServerError, TiebaValueError | ||
from ...helper import log_success, parse_json | ||
from ...helper import log_success | ||
from .protobuf import AddPostReqIdl_pb2, AddPostResIdl_pb2 | ||
|
||
CMD = 309731 | ||
|
||
|
||
def parse_body(body: bytes) -> None: | ||
res_json = parse_json(body) | ||
if code := int(res_json['error_code']): | ||
raise TiebaServerError(code, res_json['error_msg']) | ||
if int(res_json['info']['need_vcode']): | ||
res_proto = AddPostResIdl_pb2.AddPostResIdl() | ||
res_proto.ParseFromString(body) | ||
|
||
if code := res_proto.error.errorno: | ||
raise TiebaServerError(code, res_proto.error.errmsg) | ||
if int(res_proto.data.info.need_vcode): | ||
raise TiebaValueError("Need verify code") | ||
|
||
|
||
async def request(http_core: HttpCore, fname: str, fid: int, tid: int, content: str) -> bool: | ||
core = http_core.account | ||
data = [ | ||
('BDUSS', core._BDUSS), | ||
('_client_id', core._client_id), | ||
('_client_type', '2'), | ||
('_client_version', POST_VERSION), | ||
('_phone_imei', '000000000000000'), | ||
('anonymous', '1'), | ||
('barrage_time', '0'), | ||
('can_no_forum', '0'), | ||
('content', content), | ||
('cuid', core.cuid), | ||
('cuid_galaxy2', core.cuid_galaxy2), | ||
('cuid_gid', ''), | ||
('fid', fid), | ||
('from', '1021099l'), | ||
('from_forum_id', 'null'), | ||
('is_ad', '0'), | ||
('is_barrage', '0'), | ||
('is_feedback', '0'), | ||
('kw', fname), | ||
('model', 'M2012K11AC'), | ||
('net_type', '1'), | ||
('new_vcode', '1'), | ||
('post_from', '3'), | ||
('reply_uid', 'null'), | ||
('stoken', core._STOKEN), | ||
('subapp_type', 'mini'), | ||
('tbs', core._tbs), | ||
('tid', tid), | ||
('timestamp', int(time.time() * 1000)), | ||
('v_fid', ''), | ||
('v_fname', ''), | ||
('vcode_tag', '12'), | ||
('z_id', core._z_id), | ||
] | ||
|
||
request = http_core.pack_form_request( | ||
yarl.URL.build(scheme=APP_SECURE_SCHEME, host=APP_BASE_HOST, path="/c/c/post/add"), data | ||
def pack_proto(account: Account, fname: str, fid: int, tid: int, show_name: str, content: str) -> bytes: | ||
req_proto = AddPostReqIdl_pb2.AddPostReqIdl() | ||
req_proto.data.common.BDUSS = account._BDUSS | ||
req_proto.data.common._client_type = 2 | ||
req_proto.data.common._client_version = POST_VERSION | ||
req_proto.data.common._client_id = account.client_id | ||
req_proto.data.common._phone_imei = '000000000000000' | ||
req_proto.data.common._from = '1008621x' | ||
req_proto.data.common.cuid = account.cuid_galaxy2 | ||
current_ts = time.time() | ||
current_tsms = int(current_ts * 1000) | ||
current_dt = datetime.datetime.fromtimestamp(current_ts) | ||
req_proto.data.common._timestamp = current_tsms | ||
req_proto.data.common.model = 'SM-G988N' | ||
req_proto.data.common.tbs = account._tbs | ||
req_proto.data.common.net_type = 1 | ||
req_proto.data.common.pversion = '1.0.3' | ||
req_proto.data.common._os_version = '9' | ||
req_proto.data.common.brand = 'samsung' | ||
req_proto.data.common.lego_lib_version = '3.0.0' | ||
req_proto.data.common.applist = '' | ||
req_proto.data.common.stoken = account._STOKEN | ||
req_proto.data.common.z_id = account._z_id | ||
req_proto.data.common.cuid_galaxy2 = account._cuid_galaxy2 | ||
req_proto.data.common.cuid_gid = '' | ||
req_proto.data.common.c3_aid = account.c3_aid | ||
req_proto.data.common.sample_id = account._sample_id | ||
req_proto.data.common.scr_w = 720 | ||
req_proto.data.common.scr_w = 1280 | ||
req_proto.data.common.scr_dip = 1.5 | ||
req_proto.data.common.q_type = 0 | ||
req_proto.data.common.is_teenager = 0 | ||
req_proto.data.common.sdk_ver = '2.34.0' | ||
req_proto.data.common.framework_ver = '3340042' | ||
req_proto.data.common.naws_game_ver = '1038000' | ||
req_proto.data.common.active_timestamp = current_tsms - 86400 * 30 | ||
req_proto.data.common.first_install_time = current_tsms - 86400 * 30 | ||
req_proto.data.common.last_update_time = current_tsms - 86400 * 30 | ||
req_proto.data.common.event_day = f'{current_dt.year}{current_dt.month}{current_dt.day}' | ||
req_proto.data.common.android_id = account.android_id | ||
req_proto.data.common.cmode = 1 | ||
req_proto.data.common.start_scheme = '' | ||
req_proto.data.common.start_type = 1 | ||
req_proto.data.common.idfv = '0' | ||
req_proto.data.common.extra = '' | ||
req_proto.data.common.user_agent = f'aiotieba/{__version__}' | ||
req_proto.data.common.personalized_rec_switch = 1 | ||
req_proto.data.common.device_score = '0.4' | ||
|
||
req_proto.data.anonymous = '1' | ||
req_proto.data.can_no_forum = '0' | ||
req_proto.data.is_feedback = '0' | ||
req_proto.data.takephoto_num = '0' | ||
req_proto.data.entrance_type = '0' | ||
req_proto.data.vcode_tag = '12' | ||
req_proto.data.new_vcode = '1' | ||
req_proto.data.content = content | ||
req_proto.data.fid = str(fid) | ||
req_proto.data.v_fid = '' | ||
req_proto.data.v_fname = '' | ||
req_proto.data.kw = fname | ||
req_proto.data.is_barrage = '0' | ||
req_proto.data.from_fourm_id = str(fid) | ||
req_proto.data.tid = str(tid) | ||
req_proto.data.is_ad = '0' | ||
req_proto.data.post_from = '3' | ||
req_proto.data.name_show = show_name | ||
req_proto.data.is_pictxt = '0' | ||
req_proto.data.show_custom_figure = 0 | ||
req_proto.data.is_show_bless = 0 | ||
|
||
return req_proto.SerializeToString() | ||
|
||
|
||
async def request_http(http_core: HttpCore, fname: str, fid: int, tid: int, show_name: str, content: str) -> bool: | ||
data = pack_proto(http_core.account, fname, fid, tid, show_name, content) | ||
|
||
request = http_core.pack_proto_request( | ||
yarl.URL.build(scheme=APP_SECURE_SCHEME, host=APP_BASE_HOST, path="/c/c/post/add", query_string=f"cmd={CMD}"), | ||
data, | ||
) | ||
|
||
__log__ = f"fname={fname} tid={tid}" | ||
|
||
body = await http_core.net_core.send_request(request, read_bufsize=2 * 1024) | ||
body = await http_core.net_core.send_request(request, read_bufsize=1024) | ||
parse_body(body) | ||
|
||
log_success(sys._getframe(1), __log__) | ||
return True | ||
|
||
|
||
async def request_ws(ws_core: WsCore, fname: str, fid: int, tid: int, show_name: str, content: str) -> bool: | ||
data = pack_proto(ws_core.account, fname, fid, tid, show_name, content) | ||
|
||
__log__ = f"fname={fname} tid={tid}" | ||
|
||
response = await ws_core.send(data, CMD) | ||
parse_body(await response.read()) | ||
|
||
log_success(sys._getframe(1), __log__) | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// tbclient.AddPost.AddPostReqIdl | ||
syntax = "proto3"; | ||
|
||
import "CommonReq.proto"; | ||
|
||
message AddPostReqIdl { | ||
message DataReq { | ||
CommonReq common = 1; | ||
string anonymous = 6; | ||
string can_no_forum = 7; | ||
string is_feedback = 8; | ||
string takephoto_num = 9; | ||
string entrance_type = 10; | ||
string vcode_tag = 16; | ||
string new_vcode = 18; | ||
string content = 19; | ||
string fid = 26; | ||
string v_fid = 28; | ||
string v_fname = 29; | ||
string kw = 30; | ||
string is_barrage = 31; | ||
string barrage_time = 32; | ||
string from_fourm_id = 44; | ||
string tid = 45; | ||
string is_ad = 51; | ||
string post_from = 55; | ||
string name_show = 58; | ||
string is_pictxt = 60; | ||
int32 show_custom_figure = 64; | ||
int32 is_show_bless = 67; | ||
} | ||
DataReq data = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""Generated protocol buffer code.""" | ||
from google.protobuf import descriptor as _descriptor | ||
from google.protobuf import descriptor_pool as _descriptor_pool | ||
from google.protobuf import symbol_database as _symbol_database | ||
from google.protobuf.internal import builder as _builder | ||
|
||
_sym_db = _symbol_database.Default() | ||
|
||
|
||
from ..._protobuf import CommonReq_pb2 as CommonReq__pb2 | ||
|
||
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile( | ||
b'\n\x13\x41\x64\x64PostReqIdl.proto\x1a\x0f\x43ommonReq.proto\"\x82\x04\n\rAddPostReqIdl\x12$\n\x04\x64\x61ta\x18\x01 \x01(\x0b\x32\x16.AddPostReqIdl.DataReq\x1a\xca\x03\n\x07\x44\x61taReq\x12\x1a\n\x06\x63ommon\x18\x01 \x01(\x0b\x32\n.CommonReq\x12\x11\n\tanonymous\x18\x06 \x01(\t\x12\x14\n\x0c\x63\x61n_no_forum\x18\x07 \x01(\t\x12\x13\n\x0bis_feedback\x18\x08 \x01(\t\x12\x15\n\rtakephoto_num\x18\t \x01(\t\x12\x15\n\rentrance_type\x18\n \x01(\t\x12\x11\n\tvcode_tag\x18\x10 \x01(\t\x12\x11\n\tnew_vcode\x18\x12 \x01(\t\x12\x0f\n\x07\x63ontent\x18\x13 \x01(\t\x12\x0b\n\x03\x66id\x18\x1a \x01(\t\x12\r\n\x05v_fid\x18\x1c \x01(\t\x12\x0f\n\x07v_fname\x18\x1d \x01(\t\x12\n\n\x02kw\x18\x1e \x01(\t\x12\x12\n\nis_barrage\x18\x1f \x01(\t\x12\x14\n\x0c\x62\x61rrage_time\x18 \x01(\t\x12\x15\n\rfrom_fourm_id\x18, \x01(\t\x12\x0b\n\x03tid\x18- \x01(\t\x12\r\n\x05is_ad\x18\x33 \x01(\t\x12\x11\n\tpost_from\x18\x37 \x01(\t\x12\x11\n\tname_show\x18: \x01(\t\x12\x11\n\tis_pictxt\x18< \x01(\t\x12\x1a\n\x12show_custom_figure\x18@ \x01(\x05\x12\x15\n\ris_show_bless\x18\x43 \x01(\x05\x62\x06proto3' | ||
) | ||
|
||
_globals = globals() | ||
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) | ||
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'AddPostReqIdl_pb2', _globals) | ||
if _descriptor._USE_C_DESCRIPTORS is False: | ||
DESCRIPTOR._options = None | ||
_globals['_ADDPOSTREQIDL']._serialized_start = 41 | ||
_globals['_ADDPOSTREQIDL']._serialized_end = 555 | ||
_globals['_ADDPOSTREQIDL_DATAREQ']._serialized_start = 97 | ||
_globals['_ADDPOSTREQIDL_DATAREQ']._serialized_end = 555 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// tbclient.AddPost.AddPostResIdl | ||
syntax = "proto3"; | ||
|
||
import "Error.proto"; | ||
|
||
message AddPostResIdl { | ||
Error error = 1; | ||
message DataRes { | ||
string video_id = 4; | ||
string msg = 5; | ||
string pre_msg = 6; | ||
string color_msg = 7; | ||
message PostAntiInfo { | ||
string need_vcode = 3; | ||
} | ||
PostAntiInfo info = 14; | ||
} | ||
DataRes data = 2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"""Generated protocol buffer code.""" | ||
from google.protobuf import descriptor as _descriptor | ||
from google.protobuf import descriptor_pool as _descriptor_pool | ||
from google.protobuf import symbol_database as _symbol_database | ||
from google.protobuf.internal import builder as _builder | ||
|
||
_sym_db = _symbol_database.Default() | ||
|
||
|
||
from ..._protobuf import Error_pb2 as Error__pb2 | ||
|
||
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile( | ||
b'\n\x13\x41\x64\x64PostResIdl.proto\x1a\x0b\x45rror.proto\"\xf2\x01\n\rAddPostResIdl\x12\x15\n\x05\x65rror\x18\x01 \x01(\x0b\x32\x06.Error\x12$\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32\x16.AddPostResIdl.DataRes\x1a\xa3\x01\n\x07\x44\x61taRes\x12\x10\n\x08video_id\x18\x04 \x01(\t\x12\x0b\n\x03msg\x18\x05 \x01(\t\x12\x0f\n\x07pre_msg\x18\x06 \x01(\t\x12\x11\n\tcolor_msg\x18\x07 \x01(\t\x12\x31\n\x04info\x18\x0e \x01(\x0b\x32#.AddPostResIdl.DataRes.PostAntiInfo\x1a\"\n\x0cPostAntiInfo\x12\x12\n\nneed_vcode\x18\x03 \x01(\tb\x06proto3' | ||
) | ||
|
||
_globals = globals() | ||
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) | ||
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'AddPostResIdl_pb2', _globals) | ||
if _descriptor._USE_C_DESCRIPTORS is False: | ||
DESCRIPTOR._options = None | ||
_globals['_ADDPOSTRESIDL']._serialized_start = 37 | ||
_globals['_ADDPOSTRESIDL']._serialized_end = 279 | ||
_globals['_ADDPOSTRESIDL_DATARES']._serialized_start = 116 | ||
_globals['_ADDPOSTRESIDL_DATARES']._serialized_end = 279 | ||
_globals['_ADDPOSTRESIDL_DATARES_POSTANTIINFO']._serialized_start = 245 | ||
_globals['_ADDPOSTRESIDL_DATARES_POSTANTIINFO']._serialized_end = 279 |
Oops, something went wrong.