### Install Dependencies and Tools Source: https://context7.com/crystalformations/az-supreme-court-audio-scraper/llms.txt Installs necessary Python packages, Playwright browsers, and the yt-dlp tool for audio extraction. yt-dlp can be installed via Homebrew or pip. ```bash pip install -r requirements.txt playwright install chromium brew install yt-dlp # or pip install yt-dlp ``` -------------------------------- ### Download and Convert Audio Stream to MP3 using Python Source: https://context7.com/crystalformations/az-supreme-court-audio-scraper/llms.txt Downloads a video stream from a `.m3u8` URL and converts it to an MP3 audio file using `yt-dlp`. It also sanitizes the provided case name to create a valid filename and ensures the output directory exists before downloading. ```python from SCAZ_download_oralargs_audio import download_audio, sanitize_filename m3u8_url = "https://archive-media.granicus.com/azcourts/azcourts_abc123def.m3u8" case_name = "STATE OF ARIZONA v KEVIN DUNBAR" download_dir = "/Users/username/Downloads/SCAZ/2023" # Sanitize the filename to remove special characters clean_name = sanitize_filename(case_name) # Result: "STATE_OF_ARIZONA_v_KEVIN_DUNBAR" # Download and convert to MP3 download_audio(m3u8_url, clean_name, download_dir) # Creates file: /Users/username/Downloads/SCAZ/2023/STATE_OF_ARIZONA_v_KEVIN_DUNBAR.mp3 ``` -------------------------------- ### Create Retry-Enabled HTTP Session (Python) Source: https://context7.com/crystalformations/az-supreme-court-audio-scraper/llms.txt Creates a `requests.Session` object with automatic retry capabilities for handling transient HTTP errors. This is crucial for robust network operations, especially when dealing with potentially unstable APIs or network conditions. ```python from SCAZ_download_oralargs_audio import get_retry_session # Create session with default retry settings (3 retries, 0.3s backoff) session = get_retry_session() # Or customize retry behavior session = get_retry_session( retries=5, backoff_factor=0.5, status_forcelist=(500, 502, 503, 504) ) # Use session for requests response = session.get("https://example.com/api", headers={"User-Agent": "Mozilla/5.0"}, timeout=10) ``` -------------------------------- ### Download Oral Arguments for a Specific Year using Python Source: https://context7.com/crystalformations/az-supreme-court-audio-scraper/llms.txt Executes the main Python script to download oral arguments for a given year. It accepts a required --year argument and an optional --output-dir for specifying the save location. The output shows the processing progress and completion status for each case. ```bash python3 SCAZ_download_oralargs_audio.py --year 2023 python3 SCAZ_download_oralargs_audio.py --year 2023 --output-dir ~/Desktop/SCAZ_Audio ``` -------------------------------- ### Extract Case Links from HTML using Python Source: https://context7.com/crystalformations/az-supreme-court-audio-scraper/llms.txt Parses HTML content to extract case names and their corresponding video player URLs. This function processes the output from `fetch_cases_for_year_html` and returns a list of tuples, where each tuple contains the case name and its video URL. ```python from SCAZ_download_oralargs_audio import fetch_cases_for_year_html, extract_case_links_from_html html_content = fetch_cases_for_year_html("2023") cases = extract_case_links_from_html(html_content) # Returns list of tuples: [(case_name, video_url), ...] # Example output: # [ # ('STATE OF ARIZONA v KEVIN DUNBAR', 'https://archive-media.granicus.com/MediaPlayer.php?...'), # ('Avitia v Crisis Preparation', 'https://archive-media.granicus.com/MediaPlayer.php?...'), # ... # ] for case_name, video_url in cases: print(f"Case: {case_name}") print(f"URL: {video_url}\n") ``` -------------------------------- ### Fetch HTML Content for Oral Arguments by Year using Python Source: https://context7.com/crystalformations/az-supreme-court-audio-scraper/llms.txt Fetches the HTML content of the archived video page for a specific year. It uses Playwright to navigate the site, interact with iframes, and select the correct year tab. The function returns the HTML string containing case listings. ```python from SCAZ_download_oralargs_audio import fetch_cases_for_year_html # Fetch HTML content for 2023 oral arguments html_content = fetch_cases_for_year_html("2023") # Returns HTML string containing table rows with case information: # # STATE OF ARIZONA v KEVIN DUNBAR # ... # Video # ``` -------------------------------- ### Extract .m3u8 Stream URL from Media Player Page using Python Source: https://context7.com/crystalformations/az-supreme-court-audio-scraper/llms.txt Extracts the `.m3u8` stream URL from a given video player page URL. It fetches the page content and uses regex to find the stream URL. The function includes retry logic with exponential backoff for network request resilience. ```python from SCAZ_download_oralargs_audio import extract_m3u8_from_media_player video_page_url = "https://archive-media.granicus.com/MediaPlayer.php?view_id=11&clip_id=12345" m3u8_url = extract_m3u8_from_media_player(video_page_url) # Returns the direct stream URL: # "https://archive-media.granicus.com/azcourts/azcourts_abc123def.m3u8" if m3u8_url: print(f"Stream URL: {m3u8_url}") else: print("Could not find .m3u8 stream URL") ``` -------------------------------- ### Sanitize Filename for Case Names (Python) Source: https://context7.com/crystalformations/az-supreme-court-audio-scraper/llms.txt Converts a case name string into a safe filename by replacing special characters with underscores and collapsing multiple consecutive underscores. This function is useful for ensuring compatibility with various file systems. ```python from SCAZ_download_oralargs_audio import sanitize_filename # Original case name with special characters case_name = "STATE OF ARIZONA v. JOSÉ ADRIAN AGUNDEZ-MARTINEZ (et al.)" clean_name = sanitize_filename(case_name) # Result: "STATE_OF_ARIZONA_v_JOS_ADRIAN_AGUNDEZ_MARTINEZ_et_al" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.