style: apply pre-commit auto-fixes (isort, whitespace, eof)

This commit is contained in:
imSp4rky
2026-06-25 11:06:55 -06:00
parent 06e0593da3
commit 5d4a27b8ca
3 changed files with 23 additions and 46 deletions
+3 -11
View File
@@ -6,17 +6,9 @@ from typing import Any, Optional
import pytest import pytest
from unshackle.core.music.extract import ( from unshackle.core.music.extract import (build_music_from_songs, classify_release_kind, dedupe_track_options,
build_music_from_songs, duration_seconds, first_number, first_text, format_duration, format_names,
classify_release_kind, year_from_value)
dedupe_track_options,
duration_seconds,
first_number,
first_text,
format_duration,
format_names,
year_from_value,
)
from unshackle.core.music.models import MusicTrackOption from unshackle.core.music.models import MusicTrackOption
from unshackle.core.titles.music import Music, Song from unshackle.core.titles.music import Music, Song
+2 -17
View File
@@ -15,23 +15,8 @@ except ImportError: # pragma: no cover - optional artwork enhancement
try: try:
from mutagen.flac import FLAC, Picture from mutagen.flac import FLAC, Picture
from mutagen.id3 import ( from mutagen.id3 import (APIC, COMM, TALB, TCOM, TCON, TCOP, TDRC, TIT2, TPE1, TPE2, TPOS, TRCK, TSRC, TXXX,
APIC, ID3NoHeaderError)
COMM,
ID3NoHeaderError,
TALB,
TCOM,
TCON,
TCOP,
TDRC,
TIT2,
TPE1,
TPE2,
TPOS,
TRCK,
TSRC,
TXXX,
)
from mutagen.mp3 import MP3 from mutagen.mp3 import MP3
from mutagen.mp4 import MP4, MP4Cover from mutagen.mp4 import MP4, MP4Cover
except ImportError: # pragma: no cover - optional tagging dependency except ImportError: # pragma: no cover - optional tagging dependency
@@ -3,14 +3,14 @@ Firefox Cookie and LocalStorage Extractor Utility for unshackle.
Provides a secure, read-only mechanism to extract authentication tokens from Firefox. Provides a secure, read-only mechanism to extract authentication tokens from Firefox.
""" """
import sqlite3
import platform
import os import os
import platform
import shutil import shutil
import sqlite3
import tempfile import tempfile
from http.cookiejar import Cookie, CookieJar
from pathlib import Path from pathlib import Path
from http.cookiejar import CookieJar, Cookie from typing import Dict, List, Optional
from typing import Dict, Optional, List
def get_firefox_root() -> Path: def get_firefox_root() -> Path:
@@ -41,7 +41,7 @@ def get_latest_profile_path(ff_root: Path) -> Path:
for base in search_dirs: for base in search_dirs:
if base.exists(): if base.exists():
valid_profiles.extend([p for p in base.iterdir() if p.is_dir() and (p / 'cookies.sqlite').exists()]) valid_profiles.extend([p for p in base.iterdir() if p.is_dir() and (p / 'cookies.sqlite').exists()])
if not valid_profiles: if not valid_profiles:
raise FileNotFoundError("No active Firefox profiles detected.") raise FileNotFoundError("No active Firefox profiles detected.")
@@ -56,29 +56,29 @@ def get_local_storage_data(profile_path: Path, hosts: List[str], tmp_dir_path: P
ls_db = profile_path / 'webappsstore.sqlite' ls_db = profile_path / 'webappsstore.sqlite'
if not ls_db.exists(): if not ls_db.exists():
return {} return {}
temp_ls = tmp_dir_path / "webappsstore.sqlite" temp_ls = tmp_dir_path / "webappsstore.sqlite"
extracted_storage = {} extracted_storage = {}
try: try:
shutil.copy2(ls_db, temp_ls) shutil.copy2(ls_db, temp_ls)
conn = sqlite3.connect(temp_ls) conn = sqlite3.connect(temp_ls)
cursor = conn.cursor() cursor = conn.cursor()
for host in hosts: for host in hosts:
# Firefox stores LocalStorage as reversed host (e.g., moc.viki.:https:443) # Firefox stores LocalStorage as reversed host (e.g., moc.viki.:https:443)
# Use strict prefix matching to prevent over-broad harvesting # Use strict prefix matching to prevent over-broad harvesting
reversed_host = host[::-1] reversed_host = host[::-1]
query = "SELECT key, value FROM webappsstore2 WHERE originKey LIKE ?" query = "SELECT key, value FROM webappsstore2 WHERE originKey LIKE ?"
cursor.execute(query, (f"{reversed_host}.%",)) cursor.execute(query, (f"{reversed_host}.%",))
for key, value in cursor.fetchall(): for key, value in cursor.fetchall():
extracted_storage[key] = value extracted_storage[key] = value
conn.close() conn.close()
except Exception: except Exception:
pass pass
return extracted_storage return extracted_storage
@@ -99,14 +99,14 @@ def get_firefox_cookies(service_settings: dict) -> Optional[CookieJar]:
profile_path = get_latest_profile_path(get_firefox_root()) profile_path = get_latest_profile_path(get_firefox_root())
except Exception: except Exception:
return None return None
cookie_jar = CookieJar() cookie_jar = CookieJar()
# Use a secure temporary directory with restricted permissions (Finding #5) # Use a secure temporary directory with restricted permissions (Finding #5)
with tempfile.TemporaryDirectory(prefix="unshackle_ff_") as tmp_dir: with tempfile.TemporaryDirectory(prefix="unshackle_ff_") as tmp_dir:
tmp_dir_path = Path(tmp_dir) tmp_dir_path = Path(tmp_dir)
os.chmod(tmp_dir, 0o700) os.chmod(tmp_dir, 0o700)
temp_db = tmp_dir_path / "cookies.sqlite" temp_db = tmp_dir_path / "cookies.sqlite"
temp_wal = tmp_dir_path / "cookies.sqlite-wal" temp_wal = tmp_dir_path / "cookies.sqlite-wal"
@@ -123,8 +123,8 @@ def get_firefox_cookies(service_settings: dict) -> Optional[CookieJar]:
for host in priority_hosts: for host in priority_hosts:
# Precise matching: exact host or dot-prefixed domain suffix (Finding #2) # Precise matching: exact host or dot-prefixed domain suffix (Finding #2)
query = """ query = """
SELECT host, name, value, path, expiry, isSecure, isHttpOnly SELECT host, name, value, path, expiry, isSecure, isHttpOnly
FROM moz_cookies FROM moz_cookies
WHERE host = ? OR host LIKE ? WHERE host = ? OR host LIKE ?
""" """
cursor.execute(query, (host, f"%.{host}")) cursor.execute(query, (host, f"%.{host}"))
@@ -137,7 +137,7 @@ def get_firefox_cookies(service_settings: dict) -> Optional[CookieJar]:
version=0, name=n, value=v, port=None, port_specified=False, version=0, name=n, value=v, port=None, port_specified=False,
domain=h, domain_specified=True, domain_initial_dot=h.startswith('.'), domain=h, domain_specified=True, domain_initial_dot=h.startswith('.'),
path=p, path_specified=True, secure=bool(secure), expires=e, path=p, path_specified=True, secure=bool(secure), expires=e,
discard=False, comment=None, comment_url=None, discard=False, comment=None, comment_url=None,
rest={'HttpOnly': str(bool(httponly))}, rfc2109=False rest={'HttpOnly': str(bool(httponly))}, rfc2109=False
) )
cookie_jar.set_cookie(c) cookie_jar.set_cookie(c)
@@ -158,4 +158,4 @@ def get_firefox_cookies(service_settings: dict) -> Optional[CookieJar]:
except Exception: except Exception:
return None return None
return cookie_jar if len(list(cookie_jar)) > 0 else None return cookie_jar if len(list(cookie_jar)) > 0 else None