Skip to content

Commit 74acac3

Browse files
committed
fix: hint
1 parent a236e77 commit 74acac3

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

snapsave/snapsave.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from asyncio.tasks import ensure_future, gather
33
from io import BufferedWriter, BytesIO
44
from ast import literal_eval
5-
from typing import Any, Literal, Optional, Union
5+
from typing import Any, Generator, Literal, Optional, Union
66
import httpx
77
from httpx import AsyncClient
88
from .decoder import decoder
@@ -13,6 +13,7 @@
1313
def translate(text: str) -> bool:
1414
return text.lower() in ['iya', 'yes']
1515

16+
1617
class Regex:
1718
URL_FILTER = re.compile(r'(https?://[\w+&=\.%\-_/?;]+)')
1819
ORIGIN_URL = re.compile(r'https?://[\w\.-]+/')
@@ -134,7 +135,7 @@ async def get_size(self) -> int:
134135
'GET',
135136
self.url_v
136137
).__aenter__()
137-
).headers["Content-Length"])
138+
).headers.get("Content-Length", 0))
138139

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

161+
160162
class Videos(list):
163+
161164
def __init__(self, cover: str):
162165
super().__init__()
163166
self.cover = cover
164167

168+
def __getitem__(self, i) -> FacebookVideo:
169+
return super().__getitem__(i)
170+
171+
def __iter__(self) -> Generator[FacebookVideo, None, None]:
172+
yield from super().__iter__()
173+
165174

166175
class Fb(AsyncClient):
167176

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

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

197-
async def extract_content(self, src: str) -> list[FacebookVideo]:
198-
data = Videos(Regex.COVER.findall(src)[0])
206+
async def extract_content(self, src: str) -> Videos:
207+
data = []
199208
n = Regex.TABLE.findall(src)[0].replace('\\"', '"')
200209
for url, res, render in zip(
201210
Regex.URL_FILTER.findall(n),
@@ -214,9 +223,11 @@ async def extract_content(self, src: str) -> list[FacebookVideo]:
214223
translate(render),
215224
fsize
216225
))
217-
return sorted_video(data)
226+
data2 = Videos(Regex.COVER.findall(src)[0])
227+
data2.extend(sorted_video(data))
228+
return data2
218229

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

0 commit comments

Comments
 (0)