refactor(download): remove ProviderCore/download.py, move sanitize_filename to SYS.utils, replace callers to use API.HTTP.HTTPClient
This commit is contained in:
@@ -7,10 +7,7 @@ from typing import Any, Dict, List, Optional
|
||||
from ProviderCore.base import Provider, SearchResult
|
||||
from SYS.logger import log, debug
|
||||
|
||||
try:
|
||||
from playwright.sync_api import sync_playwright
|
||||
except ImportError: # pragma: no cover
|
||||
sync_playwright = None
|
||||
from tool.playwright import PlaywrightTool
|
||||
|
||||
|
||||
class Bandcamp(Provider):
|
||||
@@ -137,8 +134,7 @@ class Bandcamp(Provider):
|
||||
if not stage_is_last:
|
||||
return False
|
||||
|
||||
if sync_playwright is None:
|
||||
return False
|
||||
# Playwright is required; proceed to handle artist selection
|
||||
|
||||
# Only handle artist selections.
|
||||
chosen: List[Dict[str, Any]] = []
|
||||
@@ -219,11 +215,10 @@ class Bandcamp(Provider):
|
||||
artist_url = chosen[0].get("url") or ""
|
||||
|
||||
try:
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(headless=True)
|
||||
page = browser.new_page()
|
||||
tool = PlaywrightTool({})
|
||||
tool.require()
|
||||
with tool.open_page(headless=True) as page:
|
||||
discography = self._scrape_artist_page(page, artist_url, limit=50)
|
||||
browser.close()
|
||||
except Exception as exc:
|
||||
print(f"bandcamp artist lookup failed: {exc}\n")
|
||||
return True
|
||||
@@ -275,18 +270,10 @@ class Bandcamp(Provider):
|
||||
Any]] = None,
|
||||
**kwargs: Any,
|
||||
) -> List[SearchResult]:
|
||||
if sync_playwright is None:
|
||||
log(
|
||||
"[bandcamp] Playwright not available. Install with: pip install playwright",
|
||||
file=sys.stderr,
|
||||
)
|
||||
return []
|
||||
|
||||
try:
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(headless=True)
|
||||
page = browser.new_page()
|
||||
|
||||
tool = PlaywrightTool({})
|
||||
tool.require()
|
||||
with tool.open_page(headless=True) as page:
|
||||
if query.strip().lower().startswith("artist:"):
|
||||
artist_name = query[7:].strip().strip('"')
|
||||
search_url = f"https://bandcamp.com/search?q={artist_name}&item_type=b"
|
||||
@@ -294,8 +281,6 @@ class Bandcamp(Provider):
|
||||
search_url = f"https://bandcamp.com/search?q={query}&item_type=a"
|
||||
|
||||
results = self._scrape_url(page, search_url, limit)
|
||||
|
||||
browser.close()
|
||||
return results
|
||||
|
||||
except Exception as exc:
|
||||
@@ -366,4 +351,5 @@ class Bandcamp(Provider):
|
||||
return results
|
||||
|
||||
def validate(self) -> bool:
|
||||
return sync_playwright is not None
|
||||
# Playwright is required for the provider to function
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user