Add YAPF style + ignore, and format tracked Python files
This commit is contained in:
@@ -35,7 +35,9 @@ def _pick_provider_config(config: Any) -> Dict[str, Any]:
|
||||
|
||||
def _looks_fielded_query(q: str) -> bool:
|
||||
low = (q or "").lower()
|
||||
return (":" in low) or (" and " in low) or (" or " in low) or (" not " in low) or ("(" in low)
|
||||
return (":" in low) or (" and " in low) or (" or "
|
||||
in low) or (" not "
|
||||
in low) or ("(" in low)
|
||||
|
||||
|
||||
def _extract_identifier_from_any(value: str) -> str:
|
||||
@@ -111,9 +113,7 @@ def is_download_file_url(url: str) -> bool:
|
||||
return False
|
||||
# /download/<identifier>/<filename>
|
||||
return (
|
||||
len(parts) >= 3
|
||||
and parts[0].lower() == "download"
|
||||
and bool(parts[1].strip())
|
||||
len(parts) >= 3 and parts[0].lower() == "download" and bool(parts[1].strip())
|
||||
and bool(parts[2].strip())
|
||||
)
|
||||
|
||||
@@ -158,9 +158,15 @@ def list_download_files(identifier: str) -> List[Dict[str, Any]]:
|
||||
files.append(
|
||||
{
|
||||
"name": str(name),
|
||||
"size": getattr(f, "size", None),
|
||||
"format": getattr(f, "format", None),
|
||||
"source": getattr(f, "source", None),
|
||||
"size": getattr(f,
|
||||
"size",
|
||||
None),
|
||||
"format": getattr(f,
|
||||
"format",
|
||||
None),
|
||||
"source": getattr(f,
|
||||
"source",
|
||||
None),
|
||||
}
|
||||
)
|
||||
except Exception:
|
||||
@@ -179,13 +185,16 @@ def list_download_files(identifier: str) -> List[Dict[str, Any]]:
|
||||
|
||||
if source == "metadata":
|
||||
return True
|
||||
if fmt in {"metadata", "archive bittorrent"}:
|
||||
if fmt in {"metadata",
|
||||
"archive bittorrent"}:
|
||||
return True
|
||||
if fmt.startswith("thumbnail"):
|
||||
return True
|
||||
return False
|
||||
|
||||
candidates = [f for f in files if isinstance(f, dict) and not _is_ia_metadata_file(f)]
|
||||
candidates = [
|
||||
f for f in files if isinstance(f, dict) and not _is_ia_metadata_file(f)
|
||||
]
|
||||
if not candidates:
|
||||
candidates = [f for f in files if isinstance(f, dict)]
|
||||
|
||||
@@ -266,7 +275,8 @@ def _best_file_candidate(files: List[Dict[str, Any]]) -> Optional[Dict[str, Any]
|
||||
fmt = str(f.get("format") or "").strip().lower()
|
||||
if source == "metadata":
|
||||
return True
|
||||
if fmt in {"metadata", "archive bittorrent"}:
|
||||
if fmt in {"metadata",
|
||||
"archive bittorrent"}:
|
||||
return True
|
||||
if fmt.startswith("thumbnail"):
|
||||
return True
|
||||
@@ -283,7 +293,10 @@ def _best_file_candidate(files: List[Dict[str, Any]]) -> Optional[Dict[str, Any]
|
||||
candidates = list(files)
|
||||
|
||||
# Prefer originals.
|
||||
originals = [f for f in candidates if str(f.get("source") or "").strip().lower() == "original"]
|
||||
originals = [
|
||||
f for f in candidates
|
||||
if str(f.get("source") or "").strip().lower() == "original"
|
||||
]
|
||||
pool = originals if originals else candidates
|
||||
|
||||
pool = [f for f in pool if str(f.get("name") or "").strip()]
|
||||
@@ -330,7 +343,8 @@ class InternetArchive(Provider):
|
||||
mt = str(mediatype or "").strip().lower()
|
||||
if mt in {"texts"}:
|
||||
return "book"
|
||||
if mt in {"audio", "etree"}:
|
||||
if mt in {"audio",
|
||||
"etree"}:
|
||||
return "audio"
|
||||
if mt in {"movies"}:
|
||||
return "video"
|
||||
@@ -342,7 +356,8 @@ class InternetArchive(Provider):
|
||||
self,
|
||||
query: str,
|
||||
limit: int = 50,
|
||||
filters: Optional[Dict[str, Any]] = None,
|
||||
filters: Optional[Dict[str,
|
||||
Any]] = None,
|
||||
**_kwargs: Any,
|
||||
) -> List[SearchResult]:
|
||||
ia = _ia()
|
||||
@@ -355,7 +370,8 @@ class InternetArchive(Provider):
|
||||
return []
|
||||
|
||||
# If the user supplied a plain string, default to title search.
|
||||
if not _looks_fielded_query(q) and q not in {"*", "*.*"}:
|
||||
if not _looks_fielded_query(q) and q not in {"*",
|
||||
"*.*"}:
|
||||
q = f'title:("{q}")'
|
||||
|
||||
fields = [
|
||||
@@ -419,10 +435,14 @@ class InternetArchive(Provider):
|
||||
size_bytes=None,
|
||||
tag=set(),
|
||||
columns=[
|
||||
("title", title),
|
||||
("mediatype", mediatype),
|
||||
("date", date),
|
||||
("creator", creator),
|
||||
("title",
|
||||
title),
|
||||
("mediatype",
|
||||
mediatype),
|
||||
("date",
|
||||
date),
|
||||
("creator",
|
||||
creator),
|
||||
],
|
||||
full_metadata=dict(row),
|
||||
)
|
||||
@@ -437,7 +457,12 @@ class InternetArchive(Provider):
|
||||
- https://archive.org/details/<identifier>
|
||||
- https://archive.org/download/<identifier>/<filename>
|
||||
"""
|
||||
sr = SearchResult(table="internetarchive", title=str(url), path=str(url), full_metadata={})
|
||||
sr = SearchResult(
|
||||
table="internetarchive",
|
||||
title=str(url),
|
||||
path=str(url),
|
||||
full_metadata={}
|
||||
)
|
||||
return self.download(sr, output_dir)
|
||||
|
||||
def download(self, result: SearchResult, output_dir: Path) -> Optional[Path]:
|
||||
@@ -449,7 +474,11 @@ class InternetArchive(Provider):
|
||||
if not callable(download_fn):
|
||||
raise Exception("internetarchive.download is not available")
|
||||
|
||||
identifier = _extract_identifier_from_any(str(getattr(result, "path", "") or ""))
|
||||
identifier = _extract_identifier_from_any(
|
||||
str(getattr(result,
|
||||
"path",
|
||||
"") or "")
|
||||
)
|
||||
if not identifier:
|
||||
return None
|
||||
|
||||
@@ -490,9 +519,15 @@ class InternetArchive(Provider):
|
||||
files.append(
|
||||
{
|
||||
"name": str(name),
|
||||
"size": getattr(f, "size", None),
|
||||
"format": getattr(f, "format", None),
|
||||
"source": getattr(f, "source", None),
|
||||
"size": getattr(f,
|
||||
"size",
|
||||
None),
|
||||
"format": getattr(f,
|
||||
"format",
|
||||
None),
|
||||
"source": getattr(f,
|
||||
"source",
|
||||
None),
|
||||
}
|
||||
)
|
||||
except Exception:
|
||||
@@ -616,7 +651,8 @@ class InternetArchive(Provider):
|
||||
if not identifier:
|
||||
raise Exception("Could not determine Internet Archive identifier")
|
||||
|
||||
meta: Dict[str, Any] = {}
|
||||
meta: Dict[str,
|
||||
Any] = {}
|
||||
if title:
|
||||
meta["title"] = title
|
||||
else:
|
||||
@@ -628,7 +664,10 @@ class InternetArchive(Provider):
|
||||
meta["mediatype"] = self._mediatype.strip()
|
||||
|
||||
# Build upload options; credentials are optional if the user has internetarchive configured globally.
|
||||
upload_kwargs: Dict[str, Any] = {"metadata": meta}
|
||||
upload_kwargs: Dict[str,
|
||||
Any] = {
|
||||
"metadata": meta
|
||||
}
|
||||
ak = os.getenv("IA_ACCESS_KEY") or self._access_key
|
||||
sk = os.getenv("IA_SECRET_KEY") or self._secret_key
|
||||
if isinstance(ak, str) and ak.strip():
|
||||
@@ -638,7 +677,9 @@ class InternetArchive(Provider):
|
||||
|
||||
# Use a friendly uploaded filename.
|
||||
upload_name = sanitize_filename(p.name)
|
||||
files = {upload_name: str(p)}
|
||||
files = {
|
||||
upload_name: str(p)
|
||||
}
|
||||
|
||||
try:
|
||||
resp: Any = upload_fn(identifier, files=files, **upload_kwargs)
|
||||
@@ -664,9 +705,11 @@ class InternetArchive(Provider):
|
||||
if pipe_obj is not None:
|
||||
from Store import Store
|
||||
|
||||
Store(self.config, suppress_debug=True).try_add_url_for_pipe_object(
|
||||
pipe_obj, item_url
|
||||
)
|
||||
Store(
|
||||
self.config,
|
||||
suppress_debug=True
|
||||
).try_add_url_for_pipe_object(pipe_obj,
|
||||
item_url)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user