From 5b1a926e49c86da71f56888bec5a3ed3a4e8e3f0 Mon Sep 17 00:00:00 2001 From: 7x11x13 Date: Fri, 21 Mar 2025 13:45:58 -0400 Subject: [PATCH] Lint --- .gitignore | 3 ++- free_bandcamp_downloader/__main__.py | 13 ++++++++++--- .../bandcamp_http_adapter.py | 1 - .../bc_free_downloader.py | 19 ++++++++----------- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index f935c1b..aa87166 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ env *.egg-info *.log __pycache__ -notes \ No newline at end of file +notes +.DS_Store \ No newline at end of file diff --git a/free_bandcamp_downloader/__main__.py b/free_bandcamp_downloader/__main__.py index 4cf370a..71cd647 100644 --- a/free_bandcamp_downloader/__main__.py +++ b/free_bandcamp_downloader/__main__.py @@ -47,15 +47,20 @@ Formats: """ import dataclasses +import logging import sys import os import pprint -from typing import Set, Tuple +from typing import List, Set, Tuple from docopt import docopt from configparser import ConfigParser from free_bandcamp_downloader import __version__ -from free_bandcamp_downloader.bc_free_downloader import * +from free_bandcamp_downloader.bc_free_downloader import ( + AlbumInfo, + BCFreeDownloader, + BCFreeDownloaderOptions, +) from free_bandcamp_downloader import logger @@ -101,7 +106,9 @@ class Config: def options_from_config(config: Config): options = BCFreeDownloaderOptions() for field in dataclasses.fields(options): - setattr(options, field.name, config.parser["free-bandcamp-downloader"][field.name]) + setattr( + options, field.name, config.parser["free-bandcamp-downloader"][field.name] + ) return options diff --git a/free_bandcamp_downloader/bandcamp_http_adapter.py b/free_bandcamp_downloader/bandcamp_http_adapter.py index 48b0c2b..5916b7d 100644 --- a/free_bandcamp_downloader/bandcamp_http_adapter.py +++ b/free_bandcamp_downloader/bandcamp_http_adapter.py @@ -1,5 +1,4 @@ from requests.adapters import HTTPAdapter -from urllib3.util import Retry from urllib3.util.ssl_ import create_urllib3_context diff --git a/free_bandcamp_downloader/bc_free_downloader.py b/free_bandcamp_downloader/bc_free_downloader.py index 0b7b795..cf5f669 100644 --- a/free_bandcamp_downloader/bc_free_downloader.py +++ b/free_bandcamp_downloader/bc_free_downloader.py @@ -16,9 +16,10 @@ from http.cookiejar import MozillaCookieJar from typing import Dict, List, Optional, Tuple, TypedDict from urllib.parse import urljoin from guerrillamail import GuerrillaMailSession +from urllib3 import Retry from free_bandcamp_downloader import logger -from free_bandcamp_downloader.bandcamp_http_adapter import * +from free_bandcamp_downloader.bandcamp_http_adapter import BandcampHTTPAdapter class DownloadRet(TypedDict): @@ -101,10 +102,7 @@ class BCFreeDownloader: def _init_session(self): self.session = requests.Session() retries = Retry( - total = 10, - backoff_factor = 10, - backoff_max = 60, - allowed_methods = {"POST", "GET"} + total=10, backoff_factor=10, backoff_max=60, allowed_methods={"POST", "GET"} ) self.session.mount("https://", BandcampHTTPAdapter(max_retries=retries)) if self.options.cookies: @@ -116,7 +114,6 @@ class BCFreeDownloader: def _download_file(self, download_page_url: str, format: str) -> DownloadRet: soup = self.get_url_soup(download_page_url) - album_url = soup.find("div", class_="download-artwork").find("a").attrs["href"] data = json.loads(soup.find("div", {"id": "pagedata"}).attrs["data-blob"])[ "digital_items" @@ -189,7 +186,7 @@ class BCFreeDownloader: self, user_id: int, tralbum_data: Dict ) -> DownloadRet: logger.info("Downloading album from collection...") - logger.debug(f"Searching for album: '{tralbum_data["current"]["title"]}'") + logger.debug(f"Searching for album: '{tralbum_data['current']['title']}'") data = { "fan_id": user_id, "search_key": tralbum_data["current"]["title"], @@ -200,18 +197,18 @@ class BCFreeDownloader: ) tralbums = results["tralbums"] redownload_urls = results["redownload_urls"] - wanted_id = f"{tralbum_data["item_type"][0]}:{tralbum_data["id"]}" + wanted_id = f"{tralbum_data['item_type'][0]}:{tralbum_data['id']}" try: tralbum = next( filter( - lambda tralbum: f"{tralbum["tralbum_type"]}:{tralbum["tralbum_id"]}" + lambda tralbum: f"{tralbum['tralbum_type']}:{tralbum['tralbum_id']}" == wanted_id, tralbums, ) ) except StopIteration: raise BCFreeDownloadError("Could not find album in collection") - sale_id = f"{tralbum["sale_item_type"]}{tralbum["sale_item_id"]}" + sale_id = f"{tralbum['sale_item_type']}{tralbum['sale_item_id']}" if sale_id not in redownload_urls: raise BCFreeDownloadError("Could not find album download URL in collection") download_url = redownload_urls[sale_id] @@ -299,7 +296,7 @@ class BCFreeDownloader: info = BCFreeDownloader.get_label_info(soup) for release in info["releases"]: - logger.info(f"Downloading {release["url"]}") + logger.info(f"Downloading {release['url']}") soup = self.get_url_soup(release["url"]) try: