mirror of
https://github.com/nexus-stc/hyperboria
synced 2024-12-21 09:07:46 +01:00
7389f85ef2
- Move fancy naming to Hub - Adopt translations - Fix long authors list in bot - Support CJK in scitech - Fixed pylon bug with decoding improper unicode ch... GitOrigin-RevId: 74f73c44f749a71cb65dd5ddd3416f32a83d329f
38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
import re
|
|
from typing import AsyncIterable
|
|
|
|
from .base import (
|
|
Md5Source,
|
|
PreparedRequest,
|
|
)
|
|
|
|
|
|
class LibgenMd5Source(Md5Source):
|
|
base_url = 'http://libgen.gs'
|
|
resolve_timeout = 10
|
|
|
|
async def resolve_lg(self, session, url):
|
|
async with session.get(
|
|
url,
|
|
timeout=self.resolve_timeout
|
|
) as resp:
|
|
downloaded_page_fiction = await resp.text()
|
|
match = re.search(
|
|
'https?://.*/get\\.php\\?md5=.*&key=[A-Za-z0-9]+',
|
|
downloaded_page_fiction,
|
|
re.IGNORECASE,
|
|
)
|
|
if match:
|
|
return PreparedRequest(method='get', url=match.group())
|
|
|
|
async def resolve(self) -> AsyncIterable[PreparedRequest]:
|
|
async with self.get_resolve_session() as session:
|
|
url = f'{self.base_url}/ads.php?md5={self.md5}'
|
|
result = await self.resolve_lg(session, url)
|
|
if result:
|
|
yield result
|
|
url = f'{self.base_url}/foreignfiction/ads.php?md5={self.md5}'
|
|
result = await self.resolve_lg(session, url)
|
|
if result:
|
|
yield result
|