Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
refactor: do not shadow builtins (aio)
NTFSvolume6db0fd579497
diff --git a/cyberdrop_dl/aio.py b/cyberdrop_dl/aio.pyindex a08c2f55b..416b15d57 100644--- a/cyberdrop_dl/aio.py+++ b/cyberdrop_dl/aio.py@@ -4,7 +4,6 @@from __future__ import annotationsimport asyncio-import builtinsimport contextlibimport dataclassesimport sys@@ -121,24 +120,28 @@ class _AsyncChain:yield value@staticmethod- async def yield_this[T](*items: T) -> AsyncGenerator[T]:- for item in items:- yield item+ def yield_this[T](*items: T) -> AsyncGenerator[T]:+ return to_async_iterable(items)+++async def to_async_iterable[T](items: Iterable[T]) -> AsyncGenerator[T]:+ for item in items:+ yield itemchain = _AsyncChain()-async def next[T](async_iterator: AsyncIterator[T]) -> T:+async def async_next[T](async_iterator: AsyncIterator[T]) -> T:try:- return await builtins.anext(async_iterator)+ return await anext(async_iterator)except StopAsyncIteration as e:raise e.__cause__ or e from Noneasync def peek_first[T](async_iterable: AsyncIterable[T], /) -> tuple[T, AsyncGenerator[T, None]]:async_iterator = aiter(async_iterable)- first = await next(async_iterator)+ first = await async_next(async_iterator)async def replay_gen():yield first@@ -237,7 +240,7 @@ class AsyncIteratorWrapper[T]:async def __anext__(self) -> T:if self._iterator is None:self._iterator = iter(await self._coro)- value = await asyncio.to_thread(builtins.next, self._iterator, MISSING)+ value = await asyncio.to_thread(next, self._iterator, MISSING)if value is MISSING:raise StopAsyncIteration from None@@ -423,7 +426,7 @@ async def map_tuples[*Ts, R](while True:await semaphore.acquire()try:- idx, params = builtins.next(pending)+ idx, params = next(pending)except StopIteration:semaphore.release()break@@ -454,7 +457,7 @@ async def as_completed[*Ts, R](async def worker() -> None:while not shutdown.is_set():try:- args = builtins.next(params)+ args = next(params)except StopIteration:returndiff --git a/cyberdrop_dl/crawlers/whyp_it.py b/cyberdrop_dl/crawlers/whyp_it.pyindex 386f8ae0d..56390c686 100644--- a/cyberdrop_dl/crawlers/whyp_it.py+++ b/cyberdrop_dl/crawlers/whyp_it.py@@ -53,7 +53,7 @@ class WhypItCrawler(Crawler):@error_handling_wrapperasync def user(self, scrape_item: ScrapeItem, user_id: str) -> None:pages = self.api.user_tracks(user_id)- tracks = tuple(await aio.next(pages))+ tracks = tuple(await aio.async_next(pages))title = self.create_title(tracks[0].user)scrape_item.setup_as_profile(title)self._iter_tracks(scrape_item, tracks)