Skip to content

Commit

Permalink
Merge pull request #629 from TimG233/channel_series_ua
Browse files Browse the repository at this point in the history
fix: returns 412 msg for channel series by adding ua
  • Loading branch information
z0z0r4 authored Jan 6, 2024
2 parents 6f705c4 + f1ac6cd commit 0403813
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 26 deletions.
4 changes: 2 additions & 2 deletions bilibili_api/channel_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from .utils.utils import get_api
from .utils.credential import Credential
from .utils.network import Api
from .utils.network import Api, HEADERS

API_USER = get_api("user")
API = get_api("channel-series")
Expand Down Expand Up @@ -87,7 +87,7 @@ def __init__(
else:
api = API_USER["channel_series"]["info"]
params = {"series_id": self.id_}
resp = json.loads(httpx.get(api["url"], params=params).text)["data"]
resp = json.loads(httpx.get(api["url"], headers=HEADERS, params=params).text)['data']
if self.is_new:
self.meta = resp["info"]
self.meta["mid"] = resp["info"]["upper"]["mid"]
Expand Down
34 changes: 10 additions & 24 deletions bilibili_api/video_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,6 @@ async def _choose_line(line: Lines) -> dict:
return await _probe()


class Lines(Enum):
"""
可选线路
bupfetch 模式下 kodo 目前弃用 `{'error': 'no such bucket'}`
+ BDA2:百度
+ QN:七牛
+ WS:网宿
+ BLDSA:bldsa
"""

BDA2 = "bda2"
QN = "qn"
WS = "ws"
BLDSA = "bldsa"

LINES_INFO = {
"bda2": {
"os": "upos",
Expand Down Expand Up @@ -180,7 +163,7 @@ async def _choose_line(line: Lines) -> dict:
if line_info is not None:
return line_info
return await _probe()


class VideoUploaderPage:
"""
Expand Down Expand Up @@ -852,9 +835,9 @@ async def _preupload(self, page: VideoUploaderPage) -> dict:
if preupload["OK"] != 1:
self.dispatch(VideoUploaderEvents.PREUPLOAD_FAILED.value, {"page": page})
raise ApiException(json.dumps(preupload))
preupload = self._switch_upload_endpoint(self.line, preupload)
url = self._get_upload_url(self.line, preupload)

preupload = self._switch_upload_endpoint(preupload, self.line)
url = self._get_upload_url(preupload)

# 获取 upload_id
resp = await session.post(
Expand Down Expand Up @@ -1134,6 +1117,7 @@ def _switch_upload_endpoint(preupload: dict, line: dict = None) -> dict:
preupload["endpoint"] = re.sub(
r"upcdn(bda2|qn|ws)", f'upcdn{line["upcdn"]}', preupload["endpoint"]
)
return preupload # tbh not needed since it is ref type

@staticmethod
def _get_upload_url(preupload: dict) -> str:
Expand Down Expand Up @@ -1176,7 +1160,8 @@ async def _upload_chunk(
stream.close()

# 上传目标 URL
url = self._get_upload_url(self.line, preupload)
preupload = self._switch_upload_endpoint(preupload, self.line)
url = self._get_upload_url(preupload)

err_return = {
"ok": False,
Expand Down Expand Up @@ -1274,7 +1259,8 @@ async def _complete_page(
"biz_id": preupload["biz_id"],
}

url = self._get_upload_url(self.line, preupload)
preupload = self._switch_upload_endpoint(preupload, self.line)
url = self._get_upload_url(preupload)

session = get_session()

Expand Down Expand Up @@ -1533,7 +1519,7 @@ async def _submit(self):
data["csrf"] = self.credential.bili_jct
self.dispatch(VideoEditorEvents.PRE_SUBMIT.value)
try:
params = ({"csrf": self.credential.bili_jct, "t": int(time.time())},)
params = {"csrf": self.credential.bili_jct, "t": int(time.time())}
headers = {
"content-type": "application/json;charset=UTF-8",
"referer": "https://member.bilibili.com",
Expand Down

0 comments on commit 0403813

Please sign in to comment.