docs: strip non-essential comments, fold key facts into docstrings

This commit is contained in:
imSp4rky
2026-08-16 23:32:02 -06:00
parent 66bcbe9377
commit 511f96d8db
81 changed files with 204 additions and 1017 deletions
-2
View File
@@ -139,11 +139,9 @@ def apply_real_bitrates(
for group in groups.values():
group.sort(key=lambda t: getattr(t, "bitrate", None) or 0, reverse=True)
# Initial pass: top per_group of every group, all probed concurrently.
initial = [track for group in groups.values() for track in group[:per_group]]
probe_batch(initial, session, log=log, workers=workers)
# Extend each group downward until unprobed tracks can't outrank probed ones.
for group in groups.values():
probed = min(per_group, len(group))
while probed < len(group):
-18
View File
@@ -20,7 +20,6 @@ class VideoCodecChoice(click.Choice):
def __init__(self, codec_enum):
self.codec_enum = codec_enum
# Build choices from both enum names and values
choices = []
for codec in codec_enum:
choices.append(codec.name.lower()) # e.g., "avc", "hevc"
@@ -31,17 +30,14 @@ class VideoCodecChoice(click.Choice):
if not value:
return None
# First try to convert using the parent class
converted_value = super().convert(value, param, ctx)
# Now map the converted value back to the enum
for codec in self.codec_enum:
if converted_value.lower() == codec.name.lower():
return codec
if converted_value == codec.value:
return codec
# This shouldn't happen if the parent conversion worked
self.fail(f"'{value}' is not a valid video codec", param, ctx)
@@ -84,17 +80,14 @@ class SubtitleCodecChoice(click.Choice):
def __init__(self, codec_enum):
self.codec_enum = codec_enum
# Build choices from enum names, values, and common aliases
choices = []
aliases = {}
for codec in codec_enum:
choices.append(codec.name.lower()) # e.g., "subrip", "webvtt"
# Only add the value if it's different from common aliases
value_lower = codec.value.lower()
# Add common aliases and track them
if codec.name == "SubRip":
if "srt" not in choices:
choices.append("srt")
@@ -103,32 +96,27 @@ class SubtitleCodecChoice(click.Choice):
if "vtt" not in choices:
choices.append("vtt")
aliases["vtt"] = codec
# Also add the enum value if different
if value_lower != "vtt" and value_lower not in choices:
choices.append(value_lower)
elif codec.name == "SubStationAlpha":
if "ssa" not in choices:
choices.append("ssa")
aliases["ssa"] = codec
# Also add the enum value if different
if value_lower != "ssa" and value_lower not in choices:
choices.append(value_lower)
elif codec.name == "SubStationAlphav4":
if "ass" not in choices:
choices.append("ass")
aliases["ass"] = codec
# Also add the enum value if different
if value_lower != "ass" and value_lower not in choices:
choices.append(value_lower)
elif codec.name == "TimedTextMarkupLang":
if "ttml" not in choices:
choices.append("ttml")
aliases["ttml"] = codec
# Also add the enum value if different
if value_lower != "ttml" and value_lower not in choices:
choices.append(value_lower)
else:
# For other codecs, just add the enum value
if value_lower not in choices:
choices.append(value_lower)
@@ -144,21 +132,17 @@ class SubtitleCodecChoice(click.Choice):
if str(value).lower() == "original":
return "original"
# First try to convert using the parent class
converted_value = super().convert(value, param, ctx)
# Check aliases first
if converted_value.lower() in self.aliases:
return self.aliases[converted_value.lower()]
# Now map the converted value back to the enum
for codec in self.codec_enum:
if converted_value.lower() == codec.name.lower():
return codec
if converted_value.lower() == codec.value.lower():
return codec
# This shouldn't happen if the parent conversion worked
self.fail(f"'{value}' is not a valid subtitle codec", param, ctx)
@@ -460,5 +444,3 @@ LANGUAGE_RANGE = LanguageRange()
QUALITY_LIST = QualityList()
AUDIO_CODEC_LIST = AudioCodecList(Audio.Codec)
SLOW_DELAY_RANGE = SlowDelayRange()
# VIDEO_CODEC_CHOICE will be created dynamically when imported
-1
View File
@@ -57,7 +57,6 @@ def merge_dict(source: dict, destination: dict) -> None:
return
for key, value in source.items():
if isinstance(value, dict):
# get node or create one
node = destination.setdefault(key, {})
merge_dict(value, node)
else:
@@ -102,7 +102,6 @@ def get_firefox_cookies(service_settings: dict) -> Optional[CookieJar]:
cookie_jar = CookieJar()
# Use a secure temporary directory with restricted permissions (Finding #5)
with tempfile.TemporaryDirectory(prefix="unshackle_ff_") as tmp_dir:
tmp_dir_path = Path(tmp_dir)
os.chmod(tmp_dir, 0o700)
@@ -131,7 +130,6 @@ def get_firefox_cookies(service_settings: dict) -> Optional[CookieJar]:
rows = cursor.fetchall()
for h, n, v, p, e, secure, httponly in rows:
# Final validation to ensure proper domain suffix
if h == host or h.endswith(f".{host}"):
c = Cookie(
version=0,
@@ -155,7 +153,6 @@ def get_firefox_cookies(service_settings: dict) -> Optional[CookieJar]:
cookie_jar.set_cookie(c)
conn.close()
# Optional LocalStorage harvesting (Finding #4)
if use_local_storage:
storage_data = get_local_storage_data(profile_path, priority_hosts, tmp_dir_path)
for key, val in storage_data.items():
-3
View File
@@ -6,7 +6,6 @@ def get_os_arch(name: str) -> str:
os_name = platform.system().lower()
os_arch = platform.machine().lower()
# Map platform.system() output to desired OS name
if os_name == "windows":
os_name = "win"
elif os_name == "darwin":
@@ -14,11 +13,9 @@ def get_os_arch(name: str) -> str:
else:
os_name = "linux"
# Map platform.machine() output to desired architecture
if os_arch in ["x86_64", "amd64"]:
os_arch = "x64"
elif os_arch == "arm64":
os_arch = "arm64"
# Construct the dependency name in the desired format using the input name
return f"{name}-{os_name}-{os_arch}"
+4 -16
View File
@@ -49,7 +49,6 @@ class Selector:
self.minimal_count = minimal_count
self.dependencies = dependencies or {}
# Parent-Child mapping for quick lookup
self.child_to_parent = {}
for parent, children in self.dependencies.items():
for child in children:
@@ -59,10 +58,8 @@ class Selector:
self.selected_indices = set()
self.scroll_offset = 0
# Tree view state
self.expanded_headers = set()
if not collapse_on_start:
# Expand all by default
self.expanded_headers.update(self.dependencies.keys())
def get_visible_indices(self) -> list[int]:
@@ -72,13 +69,11 @@ class Selector:
"""
visible = []
for idx in range(len(self.options)):
# If it's a child, check if parent is expanded
if idx in self.child_to_parent:
parent = self.child_to_parent[idx]
if parent in self.expanded_headers:
visible.append(idx)
else:
# It's a header or independent item, always visible
visible.append(idx)
return visible
@@ -88,7 +83,6 @@ class Selector:
"""
visible_indices = self.get_visible_indices()
# Adjust scroll offset to ensure cursor is visible
if self.cursor_index not in visible_indices:
# Fallback if cursor got hidden (should be handled in move, but safety check)
self.cursor_index = visible_indices[0] if visible_indices else 0
@@ -99,17 +93,14 @@ class Selector:
cursor_visual_pos = 0
self.cursor_index = visible_indices[0]
# Calculate logical page start/end based on VISIBLE items
start_idx = self.scroll_offset
end_idx = start_idx + self.page_size
# Dynamic scroll adjustment
if cursor_visual_pos < start_idx:
self.scroll_offset = cursor_visual_pos
elif cursor_visual_pos >= end_idx:
self.scroll_offset = cursor_visual_pos - self.page_size + 1
# Re-calc render range
render_indices = visible_indices[self.scroll_offset : self.scroll_offset + self.page_size]
table = Table(show_header=False, show_edge=False, box=None, pad_edge=False, padding=(0, 1, 0, 0))
@@ -130,7 +121,6 @@ class Selector:
table.add_row(indicator_text, content_text)
# Fill empty rows to maintain height
rows_rendered = len(render_indices)
for _ in range(self.page_size - rows_rendered):
table.add_row(Text(" "), Text(" "))
@@ -310,17 +300,15 @@ class Selector:
if char == "\x03":
return "CANCEL"
# ANSI Escape Sequences for Arrow Keys
mapping = {
"\x1b[A": "UP", # Escape + [ + A
"\x1b[B": "DOWN", # Escape + [ + B
"\x1b[C": "RIGHT", # Escape + [ + C
"\x1b[D": "LEFT", # Escape + [ + D
"\x1b[A": "UP",
"\x1b[B": "DOWN",
"\x1b[C": "RIGHT",
"\x1b[D": "LEFT",
}
if char in mapping:
return mapping[char]
# Handling manual Escape sequences
if char == "\x1b": # ESC
try:
next1 = click.getchar()
+6 -7
View File
@@ -107,15 +107,14 @@ class TemplateFormatter:
safe_value = str(value).strip()
result = result.replace(placeholder, safe_value)
# Clean up multiple consecutive dots/separators and other artifacts
result = re.sub(r"\.{2,}", ".", result) # Multiple dots -> single dot
result = re.sub(r"\.{2,}", ".", result)
result = re.sub(r"\.-", "-", result) # Remove dots before dashes (for dot-based templates)
result = re.sub(r"[\.\s]+([)\]])", r"\1", result) # Remove dots/spaces before closing bracket
result = re.sub(r"\(\s*\)|\[\s*\]", "", result) # Remove empty brackets (empty conditional)
result = re.sub(r"[\.\s]+([)\]])", r"\1", result)
result = re.sub(r"\(\s*\)|\[\s*\]", "", result)
# bracket removal is what creates neighbouring separators, so collapse after it
result = re.sub(r"\s{2,}", " ", result) # Multiple spaces -> single space
result = re.sub(r"(?:-\s*)+-", "-", result) # Multiple dashes (with optional spaces) -> single dash
result = re.sub(r"^[\.\s\-]+|[\.\s\-]+$", "", result) # Remove leading/trailing dots, spaces, dashes
result = re.sub(r"\s{2,}", " ", result)
result = re.sub(r"(?:-\s*)+-", "-", result)
result = re.sub(r"^[\.\s\-]+|[\.\s\-]+$", "", result)
result = sanitize_filename(result, spacer=self.spacer)