Skip to content

Commit

Permalink
fix: hint
Browse files Browse the repository at this point in the history
  • Loading branch information
krypton-byte committed Aug 16, 2022
1 parent a236e77 commit 74acac3
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions snapsave/snapsave.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from asyncio.tasks import ensure_future, gather
from io import BufferedWriter, BytesIO
from ast import literal_eval
from typing import Any, Literal, Optional, Union
from typing import Any, Generator, Literal, Optional, Union
import httpx
from httpx import AsyncClient
from .decoder import decoder
Expand All @@ -13,6 +13,7 @@
def translate(text: str) -> bool:
return text.lower() in ['iya', 'yes']


class Regex:
URL_FILTER = re.compile(r'(https?://[\w+&=\.%\-_/?;]+)')
ORIGIN_URL = re.compile(r'https?://[\w\.-]+/')
Expand Down Expand Up @@ -134,7 +135,7 @@ async def get_size(self) -> int:
'GET',
self.url_v
).__aenter__()
).headers["Content-Length"])
).headers.get("Content-Length", 0))

async def download(
self,
Expand All @@ -157,11 +158,19 @@ def __repr__(self) -> str:
return f'{self.quality.value}::render={self.render}' + ('::'+[
'SD', 'HD'][self.is_hd] if self.is_hd or self.is_sd else '')


class Videos(list):

def __init__(self, cover: str):
super().__init__()
self.cover = cover

def __getitem__(self, i) -> FacebookVideo:
return super().__getitem__(i)

def __iter__(self) -> Generator[FacebookVideo, None, None]:
yield from super().__iter__()


class Fb(AsyncClient):

Expand All @@ -173,7 +182,7 @@ def __init__(self):
'Chrome/101.0.4994.167 Safari/537.36'
}

async def from_url(self, url: str) -> list[FacebookVideo]:
async def from_url(self, url: str) -> Videos:
await self.get('https://snapsave.app/id')
resp = await self.post(
'https://snapsave.app/action.php?lang=id',
Expand All @@ -194,8 +203,8 @@ async def from_url(self, url: str) -> list[FacebookVideo]:
))
return await self.extract_content(dec)

async def extract_content(self, src: str) -> list[FacebookVideo]:
data = Videos(Regex.COVER.findall(src)[0])
async def extract_content(self, src: str) -> Videos:
data = []
n = Regex.TABLE.findall(src)[0].replace('\\"', '"')
for url, res, render in zip(
Regex.URL_FILTER.findall(n),
Expand All @@ -214,9 +223,11 @@ async def extract_content(self, src: str) -> list[FacebookVideo]:
translate(render),
fsize
))
return sorted_video(data)
data2 = Videos(Regex.COVER.findall(src)[0])
data2.extend(sorted_video(data))
return data2

async def from_html(self, html: str) -> list[FacebookVideo]:
async def from_html(self, html: str) -> Videos:
resp = await self.post(
'https://snapsave.app/download-private-video',
data={
Expand Down

0 comments on commit 74acac3

Please sign in to comment.