Skip to content

Commit

Permalink
refactor with strategy pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
simonsmh committed Jun 7, 2024
1 parent 828f7a1 commit e3cd881
Show file tree
Hide file tree
Showing 24 changed files with 1,121 additions and 1,312 deletions.
3 changes: 1 addition & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ python-telegram-bot = {version = ">=20", extras = ["all"]}
tortoise-orm = {extras = ["accel"], version = "*"}
telegraph = {extras = ["aio"], version = "*"}
uvicorn = "*"
asyncmy = "*"
redis = "*"

[dev-packages]
pytest = "*"
pytest-asyncio = "*"

[requires]
python_version = "3.11"
python_version = "3.12"
514 changes: 190 additions & 324 deletions Pipfile.lock

Large diffs are not rendered by default.

15 changes: 7 additions & 8 deletions biliparser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,38 @@

import httpx

from .model import Audio, Live, Opus, Read, Video
from .parser import parse_audio, parse_live, parse_opus, parse_read, parse_video
from .strategy import Audio, Live, Opus, Read, Video
from .utils import ParserException, headers, logger, retry_catcher


@retry_catcher
async def __feed_parser(client: httpx.AsyncClient, url: str):
# bypass b23 short link
if re.search(r"BV\w{10}|av\d+|ep\d+|ss\d+", url):
return await parse_video(client, url if "/" in url else f"b23.tv/{url}")
return await Video(url if "/" in url else f"b23.tv/{url}", client).handle()
r = await client.get(url)
url = str(r.url)
logger.debug(f"URL: {url}")
# main video
if re.search(r"video|bangumi/play|festival", url):
return await parse_video(client, url)
return await Video(url, client).handle()
# au audio
elif "read" in url:
return await parse_read(client, url)
return await Read(url, client).handle()
# au audio
elif "audio" in url:
return await parse_audio(client, url)
return await Audio(url, client).handle()
# live image
elif "live" in url:
return await parse_live(client, url)
return await Live(url, client).handle()
# API link blackboard link user space link
elif re.search(
r"^https?:\/\/(?:api|www\.bilibili\.com\/blackboard|space\.bilibili\.com)", url
):
pass
# dynamic opus
elif re.search(r"^https?:\/\/[th]\.|dynamic|opus", url):
return await parse_opus(client, url)
return await Opus(url, client).handle()
raise ParserException("URL错误", url)


Expand Down
14 changes: 0 additions & 14 deletions biliparser/model/audio.py

This file was deleted.

12 changes: 0 additions & 12 deletions biliparser/model/live.py

This file was deleted.

69 changes: 0 additions & 69 deletions biliparser/model/opus.py

This file was deleted.

13 changes: 0 additions & 13 deletions biliparser/model/read.py

This file was deleted.

56 changes: 0 additions & 56 deletions biliparser/model/video.py

This file was deleted.

5 changes: 0 additions & 5 deletions biliparser/parser/__init__.py

This file was deleted.

122 changes: 0 additions & 122 deletions biliparser/parser/audio_parser.py

This file was deleted.

Loading

0 comments on commit e3cd881

Please sign in to comment.