-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
102 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[MASTER] | ||
disable=C0114,C0115,C0116,W1203,C0301,C0411,C0412,E0611,R0902,R0915,R0913,R0903,R0914,R0912,C0207,R0916 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
from alphacoders_downloader.exceptions import WallpapersNotFounds | ||
from alphacoders_downloader.util.cursor import HiddenCursor, show | ||
from alphacoders_downloader.util.progress_bar import ProgressBar | ||
from alphacoders_downloader import __version__, __license__ | ||
from alphacoders_downloader.util.spinner import Spinner | ||
from bs4 import BeautifulSoup | ||
from typing import Union | ||
|
@@ -39,36 +40,36 @@ async def fetch_images(self, image_url: str): | |
images_name_file = images_name_file_thumb.split('-')[len(images_name_file_thumb.split('-')) - 1] | ||
if os.path.isfile(os.path.join(self.path, images_name_file)) is False: | ||
image_url = image_url.replace(images_name_file_thumb, '') + images_name_file | ||
async with self.client_session.head(image_url) as r: | ||
file_size = int(r.headers['Content-Length']) | ||
async with self.client_session.head(image_url) as request: | ||
file_size = int(request.headers['Content-Length']) | ||
self.total_size_to_download += file_size | ||
|
||
self.images_list.append([image_url, images_name_file, file_size]) | ||
|
||
async def parse_url(self, url: str): | ||
async with self.client_session.get(url, cookies={'AlphaCodersView': 'paged'}) as r: | ||
page = BeautifulSoup(await r.text(), 'html.parser') | ||
async with self.client_session.get(url, cookies={'AlphaCodersView': 'paged'}) as request: | ||
page = BeautifulSoup(await request.text(), 'html.parser') | ||
|
||
find_images_urls = page.find('div', {'id': 'page_container'}).find_all('div', 'thumb-container-big') | ||
|
||
if find_images_urls is None: | ||
raise WallpapersNotFounds(url) | ||
else: | ||
for link in find_images_urls: | ||
href = str(link.find('img').get('src')) | ||
|
||
if (href.startswith('https://images') or href.startswith( | ||
'https://mfiles')) and href not in self.temp_images_list: | ||
self.temp_images_list.append(href) | ||
for a_element in find_images_urls: | ||
href = str(a_element.find('img').get('src')) | ||
|
||
if (href.startswith('https://images') or href.startswith('https://mfiles')) and href not in \ | ||
self.temp_images_list: | ||
self.temp_images_list.append(href) | ||
|
||
self.links_got += 1 | ||
self.links_got += 1 | ||
|
||
a_element = page.find('div', {'class': 'pagination-simple center'}).find_all('a') | ||
a_elements = page.find('div', {'class': 'pagination-simple center'}).find_all('a') | ||
changed_element = None | ||
if a_element is not None and a_element: | ||
for x in a_element: | ||
if x.text.strip() == 'Next >>': | ||
changed_element = x | ||
if a_elements is not None and a_elements: | ||
for a_element in a_elements: | ||
if a_element.text.strip() == 'Next >>': | ||
changed_element = a_element | ||
break | ||
if changed_element is not None: | ||
url = changed_element.get('href') | ||
|
@@ -90,13 +91,13 @@ async def download(self, element: list): | |
headers['Range'] = f'bytes={file_size}-' | ||
file_downloaded = 0 | ||
|
||
async with self.client_session.get(element[0], headers=headers) as r: | ||
async with self.client_session.get(element[0], headers=headers) as request: | ||
try: | ||
write_mode = 'ab' if temp_file_exist else 'wb' | ||
async with aiofiles.open(temp_path, write_mode) as f: | ||
async with aiofiles.open(temp_path, write_mode) as file: | ||
try: | ||
async for data in r.content.iter_chunked(1024): | ||
await f.write(data) | ||
async for data in request.content.iter_chunked(1024): | ||
await file.write(data) | ||
|
||
file_downloaded += len(data) | ||
self.progress_bar.progress(len(data)) | ||
|
@@ -150,10 +151,8 @@ async def download(command_return: dict): | |
|
||
@staticmethod | ||
def get_version(_): | ||
from alphacoders_downloader import __version__, __license__ | ||
|
||
version_text = f'\033[1mAlphacodersDownloader {__version__}\033[0m\n' | ||
version_text += f'Created by \033[1mAsthowen\033[0m - \033[[email protected]\033[0m\n' | ||
version_text += 'Created by \033[1mAsthowen\033[0m - \033[[email protected]\033[0m\n' | ||
version_text += f'License: \033[1m{__license__}\033[0m' | ||
|
||
print(version_text) | ||
|
@@ -196,16 +195,18 @@ async def main(): | |
|
||
|
||
def start(): | ||
# pylint: disable=W0703 | ||
try: | ||
os.get_terminal_size(0) | ||
asyncio.get_event_loop().run_until_complete(main()) | ||
except OSError: | ||
print_error('Your terminal does not support all the features needed for AlphacodersDownloader, please use another one.') | ||
print_error('Your terminal does not support all the features needed for AlphacodersDownloader, please use ' | ||
'another one.') | ||
show() | ||
except KeyboardInterrupt: | ||
clear_line() | ||
print('Stop the script...') | ||
show() | ||
except Exception as e: | ||
print_error(str(e)) | ||
except Exception as exception: | ||
print_error(str(exception)) | ||
show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
[metadata] | ||
name = AlphacodersDownloader | ||
version = attr: alphacoders_downloader.__version__ | ||
url = https://github.com/Asthowen/AlphacodersDownloader | ||
project_urls = | ||
GitHub: issues = https://github.com/Asthowen/AlphacodersDownloader/issues | ||
GitHub: repo = https://github.com/Asthowen/AlphacodersDownloader | ||
description = A script for download wallpapers on https://alphacoders.com. | ||
long_description = file: README.md | ||
long_description_content_type = text/markdown | ||
maintainer = Asthowen<[email protected]> | ||
maintainer_email = [email protected] | ||
license = GPLv3 | ||
license_files = LICENSE | ||
classifiers = | ||
Development Status :: 5 - Production/Stable | ||
|
||
Framework :: AsyncIO | ||
|
||
Intended Audience :: Developers | ||
|
||
License :: OSI Approved :: GNU General Public License v3 (GPLv3) | ||
|
||
Operating System :: POSIX | ||
Operating System :: MacOS :: MacOS X | ||
Operating System :: Microsoft :: Windows | ||
|
||
Programming Language :: Python | ||
Programming Language :: Python :: 3 | ||
Programming Language :: Python :: 3.7 | ||
Programming Language :: Python :: 3.8 | ||
Programming Language :: Python :: 3.9 | ||
Programming Language :: Python :: 3.10 | ||
|
||
Topic :: Internet :: WWW/HTTP | ||
|
||
[options] | ||
python_requires = >=3.7 | ||
packages = find: | ||
# https://setuptools.readthedocs.io/en/latest/setuptools.html#setting-the-zip-safe-flag | ||
zip_safe = False | ||
include_package_data = True | ||
|
||
install_requires = | ||
beautifulsoup4 >= 4 | ||
setproctitle >= 1.3.1 | ||
aiofiles >= 0.8.0 | ||
aiohttp >= 3.8 |