diff --git a/examples/test.py b/examples/test.py index 13d4ff9..905f90b 100644 --- a/examples/test.py +++ b/examples/test.py @@ -18,10 +18,12 @@ async def on_progress(self, binaries: bytes): print(f'Download: %s ' % ((int(self.clength/self.length * 100)).__str__() + '%'), end='\r') async def on_finish(self, client: httpx.AsyncClient, response: httpx.Response): self.io.seek(0) + async def main(url): vid = await Fb().from_url(url) print(vid) dd = Download(await vid[1].get_size()) await vid[1].download(dd) open('video.mp4','wb').write(dd.io.getvalue()) + asyncio.run(main(url)) #type: ignore \ No newline at end of file diff --git a/snapsave/snapsave.py b/snapsave/snapsave.py index b584b92..32ed2cf 100644 --- a/snapsave/snapsave.py +++ b/snapsave/snapsave.py @@ -13,7 +13,6 @@ 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\.-]+/') @@ -23,6 +22,7 @@ class Regex: FROM_SNAPAPP = re.compile(r'^https?://snapsave\.app') QUALITY = re.compile(r'"video-quality">(\d+|Audio|HD|SD)') DECODER_ARGS = re.compile(r'\(\".*?,.*?,.*?,.*?,.*?.*?\)') + COVER = re.compile(r' list[FacebookVideo]: @@ -157,6 +157,11 @@ 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 + class Fb(AsyncClient): @@ -190,7 +195,7 @@ 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 = [] + data = Videos(Regex.COVER.findall(src)[0]) n = Regex.TABLE.findall(src)[0].replace('\\"', '"') for url, res, render in zip( Regex.URL_FILTER.findall(n),