mirror of
https://github.com/nexus-stc/hyperboria
synced 2024-12-30 13:35:49 +01:00
d51e5ab65d
- fix: Translation fixes - fix: Various fixes - feat: PB translations, configuration changes - fix: Bugfixes GitOrigin-RevId: 55f8b148c42a296162fc707c36a5146ca0073b4b
53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
import re
|
|
from typing import AsyncIterable
|
|
|
|
from library.logging import error_log
|
|
from nexus.pylon.exceptions import RegexNotFoundError
|
|
|
|
from .base import (
|
|
Md5Source,
|
|
PreparedRequest,
|
|
)
|
|
|
|
|
|
class LibgenNewSource(Md5Source):
|
|
async def resolve(self) -> AsyncIterable[PreparedRequest]:
|
|
async with self.get_resolve_session() as session:
|
|
url = f'{self.base_url}/main/{self.md5.upper()}'
|
|
async with session.get(
|
|
url,
|
|
timeout=self.resolve_timeout
|
|
) as resp:
|
|
downloaded_page = await resp.text()
|
|
match_ipfs = re.search(
|
|
'https://ipfs.io/ipfs/[A-Za-z0-9]+',
|
|
downloaded_page,
|
|
re.IGNORECASE,
|
|
)
|
|
if match_ipfs:
|
|
yield PreparedRequest(method='get', url=match_ipfs.group(), ssl=self.ssl)
|
|
match_cf = re.search(
|
|
'https://cloudflare-ipfs.com/ipfs/[A-Za-z0-9]+',
|
|
downloaded_page,
|
|
re.IGNORECASE,
|
|
)
|
|
if match_cf:
|
|
yield PreparedRequest(method='get', url=match_cf.group(), ssl=self.ssl)
|
|
match_infura = re.search(
|
|
'https://ipfs.infura.io/ipfs/[A-Za-z0-9]+',
|
|
downloaded_page,
|
|
re.IGNORECASE,
|
|
)
|
|
if match_infura:
|
|
yield PreparedRequest(method='get', url=match_infura.group(), ssl=self.ssl)
|
|
|
|
if not match_cf or not match_infura or not match_ipfs:
|
|
error_log(RegexNotFoundError(url=url))
|
|
|
|
|
|
class LibraryLolSource(LibgenNewSource):
|
|
base_url = 'http://library.lol'
|
|
resolve_timeout = 10
|
|
ssl = False
|
|
timeout = 30
|