Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 3651f6b
Author: 龙打野 <[email protected]>
Date:   Thu Feb 1 16:39:32 2024 +0800

    Squashed commit of the following:

    commit d753997
    Author: 龙打野 <[email protected]>
    Date:   Thu Feb 1 16:27:50 2024 +0800

        Update aid_bvid_transformer.py

    commit f010d9a
    Author: 龙打野 <[email protected]>
    Date:   Thu Feb 1 12:56:58 2024 +0800

        server video

    commit 7c52fb0
    Author: 龙打野 <[email protected]>
    Date:   Thu Feb 1 12:28:33 2024 +0800

        111

    commit 31015ab
    Author: 龙打野 <[email protected]>
    Date:   Thu Feb 1 12:22:21 2024 +0800

        111

    commit d849479
    Merge: 7febcc3 13c8860
    Author: 龙打野 <[email protected]>
    Date:   Thu Feb 1 12:05:30 2024 +0800

        Merge remote-tracking branch 'upstream/main'

    commit 7febcc3
    Author: 龙打野 <[email protected]>
    Date:   Thu Feb 1 11:15:20 2024 +0800

        Update video.py

    commit eb44ffa
    Author: z0z0r4 <[email protected]>
    Date:   Sat Jan 6 12:17:43 2024 +0800

        Update channel_series.py

    commit 2461d64
    Author: 龙打野 <[email protected]>
    Date:   Fri Jan 12 21:11:42 2024 +0800

        Revert "Merge pull request Nemo2011#629 from TimG233/channel_series_ua"

        This reverts commit 377c6aa.

    commit 377c6aa
    Author: z0z0r4 <[email protected]>
    Date:   Sat Jan 6 12:18:23 2024 +0800

        Merge pull request Nemo2011#629 from TimG233/channel_series_ua

        fix: returns 412 msg for channel series by adding ua

    commit 36a248b
    Author: z0z0r4 <[email protected]>
    Date:   Thu Dec 28 04:29:25 2023 +0000

        fix: detect dolby failed

        Nemo2011#613

    commit 5253cfb
    Merge: a616b6d 11c33b1
    Author: 龙打野 <[email protected]>
    Date:   Wed Dec 27 00:41:41 2023 +0800

        Merge branch 'Nemo2011:main' into main

    commit a616b6d
    Author: 龙打野 <[email protected]>
    Date:   Wed Dec 27 00:39:28 2023 +0800

        Update server.py

    commit 329a54c
    Author: 龙打野 <[email protected]>
    Date:   Mon Dec 4 15:35:27 2023 +0800

        Update video.py

    commit 75d3556
    Author: 龙打野 <[email protected]>
    Date:   Sun Dec 3 19:50:46 2023 +0800

        Update server.py

    commit 6d456d8
    Author: 龙打野 <[email protected]>
    Date:   Sun Dec 3 18:12:32 2023 +0800

        Update server.py

    commit ec60350
    Author: 龙打野 <[email protected]>
    Date:   Sun Dec 3 18:02:08 2023 +0800

        Update server.py

    commit eb5430c
    Author: 龙打野 <[email protected]>
    Date:   Sun Dec 3 17:06:04 2023 +0800

        111

    commit 79d2927
    Author: 龙打野 <[email protected]>
    Date:   Sun Dec 3 03:23:23 2023 +0800

        server2

    commit 31ce6f9
    Author: 龙打野 <[email protected]>
    Date:   Wed Nov 22 18:47:25 2023 +0800

        Update channel_series.py

    commit 81334e4
    Author: 龙打野 <[email protected]>
    Date:   Fri Nov 17 11:41:33 2023 +0800

        Update server.py

    commit d27e687
    Author: 龙打野 <[email protected]>
    Date:   Fri Nov 17 10:28:06 2023 +0800

        Update server.py

    commit 79004c8
    Author: 龙打野 <[email protected]>
    Date:   Thu Nov 16 16:06:32 2023 +0800

        Update server.py

    commit 9e302eb
    Author: 龙打野 <[email protected]>
    Date:   Tue Nov 14 13:00:50 2023 +0800

        111

    commit ed32c56
    Author: 龙打野 <[email protected]>
    Date:   Tue Oct 24 14:26:18 2023 +0800

        Update .gitignore

    commit 805e98a
    Merge: 59fc4a3 f677179
    Author: 龙打野 <[email protected]>
    Date:   Thu Oct 19 16:43:04 2023 +0800

        Merge branch 'Nemo2011:main' into main

    commit 59fc4a3
    Author: 龙打野 <[email protected]>
    Date:   Fri Oct 13 17:22:29 2023 +0800

        111

    commit 406a5fb
    Author: 龙打野 <[email protected]>
    Date:   Tue Sep 19 23:02:57 2023 +0800

        Update README.md

    commit ad811bd
    Author: 龙打野 <[email protected]>
    Date:   Tue Sep 19 17:04:05 2023 +0800

        Update README.md

    commit 958b1f9
    Author: 龙打野 <[email protected]>
    Date:   Tue Sep 19 16:53:10 2023 +0800

        Update README.md

    commit eb45897
    Author: 龙打野 <[email protected]>
    Date:   Tue Sep 19 16:50:57 2023 +0800

        Update mock_server.py

    commit 1e138a0
    Author: 龙打野 <[email protected]>
    Date:   Tue Sep 19 16:47:49 2023 +0800

        Update README.md

    commit dd39849
    Author: 龙打野 <[email protected]>
    Date:   Tue Sep 19 16:29:49 2023 +0800

        server

    commit 461558e
    Author: 龙打野 <[email protected]>
    Date:   Tue Sep 19 11:08:46 2023 +0800

        server

    commit c0c6931
    Author: 龙打野 <[email protected]>
    Date:   Mon Sep 18 23:38:05 2023 +0800

        server

    commit 17e9b51
    Author: 龙打野 <[email protected]>
    Date:   Mon Sep 18 15:53:57 2023 +0800

        server

    commit f8878ce
    Author: 龙打野 <[email protected]>
    Date:   Mon Sep 18 15:53:47 2023 +0800

        fix

    commit 9eb9791
    Merge: 353b5a1 5ad6310
    Author: 龙打野 <[email protected]>
    Date:   Mon Sep 18 09:22:42 2023 +0800

        Merge branch 'Nemo2011:main' into main

    commit 353b5a1
    Author: 龙打野 <[email protected]>
    Date:   Fri Sep 15 18:00:43 2023 +0800

        server

    commit b64642d
    Author: 龙打野 <[email protected]>
    Date:   Fri Sep 15 17:03:21 2023 +0800

        server

    commit 8339ab5
    Author: 龙打野 <[email protected]>
    Date:   Thu Sep 14 18:12:49 2023 +0800

        Create main.py
  • Loading branch information
nooblong committed Nov 11, 2024
1 parent 85ca8c7 commit a4e529c
Show file tree
Hide file tree
Showing 2 changed files with 242 additions and 0 deletions.
26 changes: 26 additions & 0 deletions bilibili_api/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,32 @@ async def get_download_url(
}
return await Api(**api, credential=self.credential, wbi=True).update_params(**params).result

class AudioQuality(Enum):
"""
视频的音频流清晰度枚举
- _64K: 64K
- _132K: 132K
- _192K: 192K
- HI_RES: Hi-Res 无损
- DOLBY: 杜比全景声
"""

_64K = 30216
_132K = 30232
DOLBY = 30250
HI_RES = 30251
_192K = 30280

async def my_detect(self, cid=None,
audio_max_quality: AudioQuality = AudioQuality.HI_RES):
if cid is None:
info = await self.get_download_url()
else:
info = await self.get_download_url(cid=cid)
detecter = VideoDownloadURLDataDetecter(info)
return detecter.detect_best_streams(audio_max_quality=audio_max_quality)

async def get_related(self) -> dict:
"""
获取相关视频信息。
Expand Down
216 changes: 216 additions & 0 deletions server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
import enum
import inspect
import sys

import httpx
from sanic import Sanic, json
from bilibili_api import *
from bilibili_api.channel_series import ChannelSeriesType, ChannelOrder
from bilibili_api.comment import CommentResourceType
from bilibili_api.search import SearchObjectType

app = Sanic("SimpleNetworkAccess")


def enum_to_value(obj):
if isinstance(obj, enum.Enum):
return obj.value
elif isinstance(obj, dict):
return {key: enum_to_value(value) for key, value in obj.items()}
elif isinstance(obj, list):
return [enum_to_value(item) for item in obj]
elif hasattr(obj, '__dict__'):
return {key: enum_to_value(value) for key, value in vars(obj).items()}
else:
return obj


@app.get("/<package:str>/<clazz:str>/<func:str>")
async def req_by_clazz(request, package, clazz, func):
try:
package_attr = getattr(sys.modules[__name__], package)
clazz_attr = getattr(package_attr, clazz)
clazz_params = inspect.signature(clazz_attr).parameters
cred_obj = None
cred_dict = dict()
clazz_dict = dict()
for i in request.args:
if i == "sessdata" or i == "bili_jct" or i == "buvid3" or i == "ac_time_value":
cred_dict[i] = request.args[i][0]
# continue
if i in clazz_params.keys():
clazz_dict[i] = request.args[i][0]

special_param(clazz_dict, clazz)

if cred_dict:
cred_obj = Credential(**cred_dict)

if "credential" in clazz_params.keys():
clazz_dict["credential"] = cred_obj

func_dict = dict()
clazz_obj = clazz_attr(**clazz_dict)
func_attr = getattr(clazz_obj, func)
func_params = inspect.signature(func_attr).parameters

if "credential" in func_params.keys():
func_dict["credential"] = cred_obj

for i in request.args:
if i in func_params.keys():
func_dict[i] = request.args[i][0]

special_param(func_dict, func)

if inspect.isasyncgenfunction(func_attr) or inspect.iscoroutinefunction(func_attr):
result = await func_attr(**func_dict)
else:
result = func_attr(**func_dict)
result_no_enum = enum_to_value(result)

except Exception as e:
wrap_result = dict()
wrap_result["code"] = -1
wrap_result["message"] = str(e)
return json(wrap_result)

wrap_result = dict()
wrap_result["code"] = 0
wrap_result["data"] = result_no_enum
return json(wrap_result)


@app.get("/<package:str>/<func:str>")
async def req_by_static(request, package, func):
try:
package_attr = getattr(sys.modules[__name__], package)
func_attr = getattr(package_attr, func)
func_params = inspect.signature(func_attr).parameters
cred_obj = None
cred_dict = dict()
func_dict = dict()

for i in request.args:
if i == "sessdata" or i == "bili_jct" or i == "buvid3" or i == "ac_time_value":
cred_dict[i] = request.args[i][0]
# continue
if i in func_params:
func_dict[i] = request.args[i][0]

if cred_dict:
cred_obj = Credential(**cred_dict)

if package == "Credential":
func_attr = getattr(cred_obj, func)

if "credential" in func_params.keys():
func_dict["credential"] = cred_obj

special_param(func_dict, package)

if inspect.isasyncgenfunction(func_attr) or inspect.iscoroutinefunction(func_attr):
result = await func_attr(**func_dict)
else:
result = func_attr(**func_dict)
result_no_enum = enum_to_value(result)

except Exception as e:
wrap_result = dict()
wrap_result["code"] = -1
wrap_result["message"] = str(e)
return json(wrap_result)

wrap_result = dict()
wrap_result["code"] = 0
wrap_result["data"] = result_no_enum
return json(wrap_result)


@app.get("addListener/<package:str>/<clazz:str>/<event_type:str>")
async def add_listener(request, package, clazz, event_type):
call_back_url = request.args["url"][0]
del request.args["url"]
package_attr = getattr(sys.modules[__name__], package)
clazz_attr = getattr(package_attr, clazz)
clazz_params = inspect.signature(clazz_attr).parameters
cred_obj = None
cred_dict = dict()
clazz_dict = dict()
for i in request.args:
if i == "sessdata" or i == "bili_jct" or i == "buvid3" or i == "ac_time_value":
cred_dict[i] = request.args[i][0]
continue
if i in clazz_params.keys():
clazz_dict[i] = request.args[i][0]

if cred_dict:
cred_obj = Credential(**cred_dict)

if "credential" in clazz_params.keys():
clazz_dict["credential"] = cred_obj

func_dict = dict()
clazz_obj = clazz_attr(**clazz_dict)
func_attr = getattr(clazz_obj, "add_event_listener")

async def call_back(event):
httpx.post(call_back_url, json=event.__dict__)
print("event: ", event)

func_dict["name"] = event_type
func_dict["handler"] = call_back
func_attr(**func_dict)
run = getattr(clazz_obj, "run")
asyncio.create_task(run())
return json({"result": "ok"})


if __name__ == '__main__':
app.run(host="0.0.0.0", port=9000, dev=False)

# 生成一个 Credential 对象
# credential = Credential(sessdata="",
# bili_jct="", ac_time_value="")
#
# # 检查 Credential 是否需要刷新
# print(sync(credential.check_refresh()))
#
# print(sync(credential.check_valid()))
#
# # 刷新 Credential
# # sync(credential.refresh())
#
# print(credential.ac_time_value)
# print(credential.sessdata)
# print(credential.bili_jct)
# print(credential.buvid3)


def special_param(param_map, function_name):
for key, value in param_map.items():
if key == "credential":
continue
if ":parse" in value:
process = value.replace(":parse", "")
param_map[key] = eval(process)

# if function_name.lower() == "comment" and "type_" in param_map:
# val = int(param_map["type_"])
# obj = CommentResourceType(val)
# param_map["type_"] = obj
#
# if function_name.lower() == "search_by_type" and "search_type" in param_map:
# val = int(param_map["search_type"])
# obj = SearchObjectType(val)
# param_map["search_type"] = obj
#
# if function_name.lower() == "channelseries" and "type_" in param_map:
# val = int(param_map["type_"])
# obj = ChannelSeriesType(val)
# param_map["type_"] = obj
#
# if function_name.lower() == "get_videos" and "sort" in param_map:
# val = (param_map["sort"])
# obj = ChannelOrder(val)
# param_map["sort"] = obj

0 comments on commit a4e529c

Please sign in to comment.