mirror of
https://github.com/acgnhiki/blrec.git
synced 2025-01-13 20:00:37 +08:00
fix: fix danmaku uid and uname
```json {"cmd": "LOG_IN_NOTICE", "data": {"notice_msg": "为保护用户隐私,未登录无法查看他人昵称", "image_web": "http://i0.hdslb.com/bfs/dm/75e7c16b99208df259fe0a93354fd3440cbab412.png", "image_app": "http://i0.hdslb.com/bfs/dm/b632f7dcd3acf47deffb5f9ccc9546ae97a3415b.png"}} ``` close #164 close #177 close #178
This commit is contained in:
parent
fc7dd9035e
commit
7ccf898d3d
@ -15,6 +15,7 @@ from ..event.event_emitter import EventEmitter, EventListener
|
||||
from ..exception import exception_callback
|
||||
from ..logging.room_id import aio_task_with_room_id
|
||||
from ..utils.mixins import AsyncStoppableMixin
|
||||
from ..utils.string import extract_uid_from_cookie, extract_buvid_from_cookie
|
||||
from .api import AppApi, WebApi
|
||||
from .exceptions import DanmakuClientAuthError
|
||||
from .typing import ApiPlatform, Danmaku
|
||||
@ -59,6 +60,8 @@ class DanmakuClient(EventEmitter[DanmakuListener], AsyncStoppableMixin):
|
||||
self.session = session
|
||||
self.appapi = appapi
|
||||
self.webapi = webapi
|
||||
self._uid = 0
|
||||
self._buvid = ''
|
||||
self._room_id = room_id
|
||||
self.headers = headers or {}
|
||||
|
||||
@ -75,6 +78,9 @@ class DanmakuClient(EventEmitter[DanmakuListener], AsyncStoppableMixin):
|
||||
@headers.setter
|
||||
def headers(self, value: Dict[str, str]) -> None:
|
||||
self._headers = {**value, 'Connection': 'Upgrade'}
|
||||
cookie = self._headers.get('Cookie', '')
|
||||
self._uid = extract_uid_from_cookie(cookie) or 0
|
||||
self._buvid = extract_buvid_from_cookie(cookie) or ''
|
||||
|
||||
async def _do_start(self) -> None:
|
||||
await self._update_danmu_info()
|
||||
@ -119,7 +125,7 @@ class DanmakuClient(EventEmitter[DanmakuListener], AsyncStoppableMixin):
|
||||
self._host_index += 1
|
||||
if self._host_index >= len(self._danmu_info['host_list']):
|
||||
self._host_index = 0
|
||||
self._rotate_api_platform()
|
||||
# self._rotate_api_platform() # XXX: use web api only
|
||||
await self._update_danmu_info()
|
||||
raise
|
||||
else:
|
||||
@ -145,9 +151,10 @@ class DanmakuClient(EventEmitter[DanmakuListener], AsyncStoppableMixin):
|
||||
async def _send_auth(self) -> None:
|
||||
auth_msg = json.dumps(
|
||||
{
|
||||
'uid': 0,
|
||||
"uid": self._uid,
|
||||
'roomid': self._room_id, # must not be the short id!
|
||||
'protover': WS.BODY_PROTOCOL_VERSION_BROTLI,
|
||||
"buvid": self._buvid,
|
||||
'platform': 'web',
|
||||
'type': 2,
|
||||
'key': self._danmu_info['token'],
|
||||
|
@ -59,6 +59,6 @@ class StreamParser:
|
||||
self._stream_param_holder.use_alternative_stream = True
|
||||
else:
|
||||
self._stream_param_holder.use_alternative_stream = False
|
||||
self._stream_param_holder.rotate_api_platform()
|
||||
# self._stream_param_holder.rotate_api_platform() # XXX: use web api only # noqa
|
||||
except Exception:
|
||||
pass
|
||||
|
@ -148,7 +148,7 @@ class StreamURLResolver(AsyncCooperationMixin):
|
||||
'will using the primary stream url instead.'
|
||||
)
|
||||
self._stream_param_holder.use_alternative_stream = False
|
||||
self._stream_param_holder.rotate_api_platform()
|
||||
# self._stream_param_holder.rotate_api_platform() # XXX: use web api only
|
||||
except LiveRoomHidden:
|
||||
pass
|
||||
except LiveRoomLocked:
|
||||
|
File diff suppressed because one or more lines are too long
1
src/blrec/data/webapp/548.ea53a087779da599.js
Normal file
1
src/blrec/data/webapp/548.ea53a087779da599.js
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -10,6 +10,6 @@
|
||||
<body>
|
||||
<app-root></app-root>
|
||||
<noscript>Please enable JavaScript to continue using this application.</noscript>
|
||||
<script src="runtime.ede29de4183c4835.js" type="module"></script><script src="polyfills.4e5433063877ea34.js" type="module"></script><script src="main.f21b7d831ad9cafb.js" type="module"></script>
|
||||
<script src="runtime.34b6285f086501af.js" type="module"></script><script src="polyfills.4e5433063877ea34.js" type="module"></script><script src="main.f21b7d831ad9cafb.js" type="module"></script>
|
||||
|
||||
</body></html>
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"configVersion": 1,
|
||||
"timestamp": 1679555877254,
|
||||
"timestamp": 1695440376157,
|
||||
"index": "/index.html",
|
||||
"assetGroups": [
|
||||
{
|
||||
@ -12,17 +12,17 @@
|
||||
},
|
||||
"urls": [
|
||||
"/103.4a2aea63cc3bf42b.js",
|
||||
"/287.bce56b4b2bd030eb.js",
|
||||
"/287.360829ef4dfc7f0e.js",
|
||||
"/386.2404f3bc252e1df3.js",
|
||||
"/503.6553f508f4a9247d.js",
|
||||
"/548.fd78f28272b50729.js",
|
||||
"/548.ea53a087779da599.js",
|
||||
"/688.7032fddba7983cf6.js",
|
||||
"/common.1fc175bce139f4df.js",
|
||||
"/index.html",
|
||||
"/main.f21b7d831ad9cafb.js",
|
||||
"/manifest.webmanifest",
|
||||
"/polyfills.4e5433063877ea34.js",
|
||||
"/runtime.ede29de4183c4835.js",
|
||||
"/runtime.34b6285f086501af.js",
|
||||
"/styles.ae81e04dfa5b2860.css"
|
||||
],
|
||||
"patterns": []
|
||||
@ -1635,10 +1635,10 @@
|
||||
"dataGroups": [],
|
||||
"hashTable": {
|
||||
"/103.4a2aea63cc3bf42b.js": "2711817f2977bfdc18c34fee4fe9385fe012bb22",
|
||||
"/287.bce56b4b2bd030eb.js": "094898df47377213f62f6f207fa65111631fb85f",
|
||||
"/287.360829ef4dfc7f0e.js": "2f8cb4a318c877840b29d84752e40ed698321e67",
|
||||
"/386.2404f3bc252e1df3.js": "f937945645579b9651be2666f70cec2c5de4e367",
|
||||
"/503.6553f508f4a9247d.js": "0878ea0e91bfd5458dd55875561e91060ecb0837",
|
||||
"/548.fd78f28272b50729.js": "8d78077fa8ecc33314065e4e88aae6398b04af61",
|
||||
"/548.ea53a087779da599.js": "efcdeae60239e68f14b9e410d4bfe64ecb592382",
|
||||
"/688.7032fddba7983cf6.js": "eae55044529782a51b7e534365255bbfa5522b05",
|
||||
"/assets/animal/panda.js": "fec2868bb3053dd2da45f96bbcb86d5116ed72b1",
|
||||
"/assets/animal/panda.svg": "bebd302cdc601e0ead3a6d2710acf8753f3d83b1",
|
||||
@ -3234,11 +3234,11 @@
|
||||
"/assets/twotone/warning.js": "fb2d7ea232f3a99bf8f080dbc94c65699232ac01",
|
||||
"/assets/twotone/warning.svg": "8c7a2d3e765a2e7dd58ac674870c6655cecb0068",
|
||||
"/common.1fc175bce139f4df.js": "af1775164711ec49e5c3a91ee45bd77509c17c54",
|
||||
"/index.html": "7ec3f85e632f8c350df664fe8b676d7d8145ce7a",
|
||||
"/index.html": "16375e9b931dcf8a92d56b4a860ab95fb622e08b",
|
||||
"/main.f21b7d831ad9cafb.js": "fc51efa446c2ac21ee17e165217dd3faeacc5290",
|
||||
"/manifest.webmanifest": "62c1cb8c5ad2af551a956b97013ab55ce77dd586",
|
||||
"/polyfills.4e5433063877ea34.js": "68159ab99e0608976404a17132f60b5ceb6f12d2",
|
||||
"/runtime.ede29de4183c4835.js": "67c63422212cd6ccb620031b831eacb361b0ee9f",
|
||||
"/runtime.34b6285f086501af.js": "9ebaf308e01a4110d64e264057c87060e0d629c7",
|
||||
"/styles.ae81e04dfa5b2860.css": "5933b4f1c4d8fcc1891b68940ee78af4091472b7"
|
||||
},
|
||||
"navigationUrls": [
|
||||
|
@ -1 +1 @@
|
||||
(()=>{"use strict";var e,v={},m={};function r(e){var n=m[e];if(void 0!==n)return n.exports;var t=m[e]={exports:{}};return v[e](t,t.exports,r),t.exports}r.m=v,e=[],r.O=(n,t,f,o)=>{if(!t){var a=1/0;for(i=0;i<e.length;i++){for(var[t,f,o]=e[i],c=!0,u=0;u<t.length;u++)(!1&o||a>=o)&&Object.keys(r.O).every(p=>r.O[p](t[u]))?t.splice(u--,1):(c=!1,o<a&&(a=o));if(c){e.splice(i--,1);var l=f();void 0!==l&&(n=l)}}return n}o=o||0;for(var i=e.length;i>0&&e[i-1][2]>o;i--)e[i]=e[i-1];e[i]=[t,f,o]},r.n=e=>{var n=e&&e.__esModule?()=>e.default:()=>e;return r.d(n,{a:n}),n},r.d=(e,n)=>{for(var t in n)r.o(n,t)&&!r.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:n[t]})},r.f={},r.e=e=>Promise.all(Object.keys(r.f).reduce((n,t)=>(r.f[t](e,n),n),[])),r.u=e=>(592===e?"common":e)+"."+{103:"4a2aea63cc3bf42b",287:"bce56b4b2bd030eb",386:"2404f3bc252e1df3",503:"6553f508f4a9247d",548:"fd78f28272b50729",592:"1fc175bce139f4df",688:"7032fddba7983cf6"}[e]+".js",r.miniCssF=e=>{},r.o=(e,n)=>Object.prototype.hasOwnProperty.call(e,n),(()=>{var e={},n="blrec:";r.l=(t,f,o,i)=>{if(e[t])e[t].push(f);else{var a,c;if(void 0!==o)for(var u=document.getElementsByTagName("script"),l=0;l<u.length;l++){var d=u[l];if(d.getAttribute("src")==t||d.getAttribute("data-webpack")==n+o){a=d;break}}a||(c=!0,(a=document.createElement("script")).type="module",a.charset="utf-8",a.timeout=120,r.nc&&a.setAttribute("nonce",r.nc),a.setAttribute("data-webpack",n+o),a.src=r.tu(t)),e[t]=[f];var s=(g,p)=>{a.onerror=a.onload=null,clearTimeout(b);var _=e[t];if(delete e[t],a.parentNode&&a.parentNode.removeChild(a),_&&_.forEach(h=>h(p)),g)return g(p)},b=setTimeout(s.bind(null,void 0,{type:"timeout",target:a}),12e4);a.onerror=s.bind(null,a.onerror),a.onload=s.bind(null,a.onload),c&&document.head.appendChild(a)}}})(),r.r=e=>{typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e;r.tt=()=>(void 0===e&&(e={createScriptURL:n=>n},typeof trustedTypes<"u"&&trustedTypes.createPolicy&&(e=trustedTypes.createPolicy("angular#bundler",e))),e)})(),r.tu=e=>r.tt().createScriptURL(e),r.p="",(()=>{var e={666:0};r.f.j=(f,o)=>{var i=r.o(e,f)?e[f]:void 0;if(0!==i)if(i)o.push(i[2]);else if(666!=f){var a=new Promise((d,s)=>i=e[f]=[d,s]);o.push(i[2]=a);var c=r.p+r.u(f),u=new Error;r.l(c,d=>{if(r.o(e,f)&&(0!==(i=e[f])&&(e[f]=void 0),i)){var s=d&&("load"===d.type?"missing":d.type),b=d&&d.target&&d.target.src;u.message="Loading chunk "+f+" failed.\n("+s+": "+b+")",u.name="ChunkLoadError",u.type=s,u.request=b,i[1](u)}},"chunk-"+f,f)}else e[f]=0},r.O.j=f=>0===e[f];var n=(f,o)=>{var u,l,[i,a,c]=o,d=0;if(i.some(b=>0!==e[b])){for(u in a)r.o(a,u)&&(r.m[u]=a[u]);if(c)var s=c(r)}for(f&&f(o);d<i.length;d++)r.o(e,l=i[d])&&e[l]&&e[l][0](),e[l]=0;return r.O(s)},t=self.webpackChunkblrec=self.webpackChunkblrec||[];t.forEach(n.bind(null,0)),t.push=n.bind(null,t.push.bind(t))})()})();
|
||||
(()=>{"use strict";var e,v={},m={};function r(e){var n=m[e];if(void 0!==n)return n.exports;var t=m[e]={exports:{}};return v[e](t,t.exports,r),t.exports}r.m=v,e=[],r.O=(n,t,f,o)=>{if(!t){var a=1/0;for(i=0;i<e.length;i++){for(var[t,f,o]=e[i],c=!0,u=0;u<t.length;u++)(!1&o||a>=o)&&Object.keys(r.O).every(p=>r.O[p](t[u]))?t.splice(u--,1):(c=!1,o<a&&(a=o));if(c){e.splice(i--,1);var l=f();void 0!==l&&(n=l)}}return n}o=o||0;for(var i=e.length;i>0&&e[i-1][2]>o;i--)e[i]=e[i-1];e[i]=[t,f,o]},r.n=e=>{var n=e&&e.__esModule?()=>e.default:()=>e;return r.d(n,{a:n}),n},r.d=(e,n)=>{for(var t in n)r.o(n,t)&&!r.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:n[t]})},r.f={},r.e=e=>Promise.all(Object.keys(r.f).reduce((n,t)=>(r.f[t](e,n),n),[])),r.u=e=>(592===e?"common":e)+"."+{103:"4a2aea63cc3bf42b",287:"360829ef4dfc7f0e",386:"2404f3bc252e1df3",503:"6553f508f4a9247d",548:"ea53a087779da599",592:"1fc175bce139f4df",688:"7032fddba7983cf6"}[e]+".js",r.miniCssF=e=>{},r.o=(e,n)=>Object.prototype.hasOwnProperty.call(e,n),(()=>{var e={},n="blrec:";r.l=(t,f,o,i)=>{if(e[t])e[t].push(f);else{var a,c;if(void 0!==o)for(var u=document.getElementsByTagName("script"),l=0;l<u.length;l++){var d=u[l];if(d.getAttribute("src")==t||d.getAttribute("data-webpack")==n+o){a=d;break}}a||(c=!0,(a=document.createElement("script")).type="module",a.charset="utf-8",a.timeout=120,r.nc&&a.setAttribute("nonce",r.nc),a.setAttribute("data-webpack",n+o),a.src=r.tu(t)),e[t]=[f];var s=(g,p)=>{a.onerror=a.onload=null,clearTimeout(b);var _=e[t];if(delete e[t],a.parentNode&&a.parentNode.removeChild(a),_&&_.forEach(h=>h(p)),g)return g(p)},b=setTimeout(s.bind(null,void 0,{type:"timeout",target:a}),12e4);a.onerror=s.bind(null,a.onerror),a.onload=s.bind(null,a.onload),c&&document.head.appendChild(a)}}})(),r.r=e=>{typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e;r.tt=()=>(void 0===e&&(e={createScriptURL:n=>n},typeof trustedTypes<"u"&&trustedTypes.createPolicy&&(e=trustedTypes.createPolicy("angular#bundler",e))),e)})(),r.tu=e=>r.tt().createScriptURL(e),r.p="",(()=>{var e={666:0};r.f.j=(f,o)=>{var i=r.o(e,f)?e[f]:void 0;if(0!==i)if(i)o.push(i[2]);else if(666!=f){var a=new Promise((d,s)=>i=e[f]=[d,s]);o.push(i[2]=a);var c=r.p+r.u(f),u=new Error;r.l(c,d=>{if(r.o(e,f)&&(0!==(i=e[f])&&(e[f]=void 0),i)){var s=d&&("load"===d.type?"missing":d.type),b=d&&d.target&&d.target.src;u.message="Loading chunk "+f+" failed.\n("+s+": "+b+")",u.name="ChunkLoadError",u.type=s,u.request=b,i[1](u)}},"chunk-"+f,f)}else e[f]=0},r.O.j=f=>0===e[f];var n=(f,o)=>{var u,l,[i,a,c]=o,d=0;if(i.some(b=>0!==e[b])){for(u in a)r.o(a,u)&&(r.m[u]=a[u]);if(c)var s=c(r)}for(f&&f(o);d<i.length;d++)r.o(e,l=i[d])&&e[l]&&e[l][0](),e[l]=0;return r.O(s)},t=self.webpackChunkblrec=self.webpackChunkblrec||[];t.forEach(n.bind(null,0)),t.push=n.bind(null,t.push.bind(t))})()})();
|
@ -230,6 +230,8 @@ class RecordTask:
|
||||
@user_agent.setter
|
||||
def user_agent(self, value: str) -> None:
|
||||
self._live.user_agent = value
|
||||
if hasattr(self, '_danmaku_client'):
|
||||
self._danmaku_client.headers = self._live.headers
|
||||
|
||||
@property
|
||||
def cookie(self) -> str:
|
||||
@ -238,6 +240,8 @@ class RecordTask:
|
||||
@cookie.setter
|
||||
def cookie(self, value: str) -> None:
|
||||
self._live.cookie = value
|
||||
if hasattr(self, '_danmaku_client'):
|
||||
self._danmaku_client.headers = self._live.headers
|
||||
|
||||
@property
|
||||
def danmu_uname(self) -> bool:
|
||||
|
@ -287,12 +287,14 @@ class RecordTaskManager:
|
||||
restart_danmaku_client: bool = True,
|
||||
) -> None:
|
||||
task = self._get_task(room_id)
|
||||
# avoid unnecessary updates that will interrupt connections
|
||||
if task.user_agent == settings.user_agent and task.cookie == settings.cookie:
|
||||
return
|
||||
task.user_agent = settings.user_agent
|
||||
task.cookie = settings.cookie
|
||||
if restart_danmaku_client:
|
||||
changed = False
|
||||
if task.user_agent != settings.user_agent:
|
||||
task.user_agent = settings.user_agent
|
||||
changed = True
|
||||
if task.cookie != settings.cookie:
|
||||
task.cookie = settings.cookie
|
||||
changed = True
|
||||
if changed and restart_danmaku_client:
|
||||
await task.restart_danmaku_client()
|
||||
|
||||
def apply_task_output_settings(
|
||||
|
@ -1,16 +1,29 @@
|
||||
import re
|
||||
from typing import Optional
|
||||
|
||||
|
||||
def snake_case(string: str) -> str:
|
||||
return re.sub(
|
||||
r'([a-z])([A-Z])',
|
||||
lambda m: m.group(1) + '_' + m.group(2).lower(),
|
||||
string
|
||||
r'([a-z])([A-Z])', lambda m: m.group(1) + '_' + m.group(2).lower(), string
|
||||
)
|
||||
|
||||
|
||||
def camel_case(string: str) -> str:
|
||||
words = string.split('_')
|
||||
return ''.join(
|
||||
[words[0].casefold()] + [word.capitalize() for word in words[1:]]
|
||||
)
|
||||
return ''.join([words[0].casefold()] + [word.capitalize() for word in words[1:]])
|
||||
|
||||
|
||||
def extract_uid_from_cookie(cookie: str) -> Optional[int]:
|
||||
match = re.search(r'DedeUserID=(\d+);', cookie)
|
||||
if match:
|
||||
return int(match.group(1))
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def extract_buvid_from_cookie(cookie: str) -> Optional[str]:
|
||||
match = re.search(r'buvid3=([\w-]+);', cookie)
|
||||
if match:
|
||||
return match.group(1)
|
||||
else:
|
||||
return None
|
||||
|
@ -118,4 +118,8 @@ a.setting-item {
|
||||
.setting-value {
|
||||
color: #5f6368;
|
||||
font-weight: 400;
|
||||
|
||||
width: 100%;
|
||||
max-height: 3em;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user