mirror of
https://github.com/nexus-stc/hyperboria
synced 2024-12-21 17:17:47 +01:00
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 = 20
|