This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

tools/flaxget: add streaming mode with -s/--stream flag

Downloads all files in parallel with aria2c while playing them sequentially with mpv.
Waits for each file to have content before starting playback.
Extracts basename from URLs since aria2c saves without directory structure.

+131
+17
tools/flaxget/flake-module.nix
··· 1 + { ... }: 2 + { 3 + perSystem = 4 + { pkgs, ... }: 5 + { 6 + packages.flaxget = pkgs.writeShellApplication { 7 + name = "flaxget"; 8 + runtimeInputs = [ 9 + pkgs.curl 10 + pkgs.fzf 11 + pkgs.coreutils 12 + pkgs.aria2 13 + ]; 14 + text = builtins.readFile ./flaxget.sh; 15 + }; 16 + }; 17 + }
+114
tools/flaxget/flaxget.sh
··· 1 + #!/usr/bin/env bash 2 + set -euo pipefail 3 + 4 + FLAX_URL="https://flax.lassul.us" 5 + FLAX_USER="krebs" 6 + STREAM_MODE=false 7 + 8 + # Parse arguments 9 + while [[ $# -gt 0 ]]; do 10 + case "$1" in 11 + -s|--stream) 12 + STREAM_MODE=true 13 + shift 14 + ;; 15 + *) 16 + echo "Usage: $0 [-s|--stream]" 17 + echo " -s, --stream Stream files to mpv while downloading" 18 + exit 1 19 + ;; 20 + esac 21 + done 22 + 23 + # Try to get password from pass first 24 + if command -v pass >/dev/null 2>&1 && pass git ls-files | grep -qE "^www/flax\.lassul\.us/pass\.(gpg|age)$"; then 25 + FLAX_PASS=$(pass show www/flax.lassul.us/pass) 26 + else 27 + read -rsp "Password for $FLAX_USER@flax.lassul.us: " FLAX_PASS 28 + echo 29 + fi 30 + 31 + echo "Fetching file list..." 32 + FILES=$(curl -s -u "$FLAX_USER:$FLAX_PASS" "$FLAX_URL/index") 33 + 34 + if [[ -z "$FILES" ]]; then 35 + echo "Error: Failed to fetch file list or no files available" 36 + exit 1 37 + fi 38 + 39 + SELECTED=$(echo "$FILES" | fzf --multi --header="Select files to download (TAB to select multiple, ENTER to confirm)") 40 + 41 + if [[ -z "$SELECTED" ]]; then 42 + echo "No files selected" 43 + exit 0 44 + fi 45 + 46 + if [[ "$STREAM_MODE" == "true" ]]; then 47 + # Check if mpv is available 48 + if ! command -v mpv >/dev/null 2>&1; then 49 + echo "Error: mpv is not installed. Stream mode requires mpv." 50 + exit 1 51 + fi 52 + 53 + # Stream mode: start aria2c in background to download all files 54 + # while playing them sequentially as they become available 55 + 56 + # Create a temporary file with URLs for aria2c 57 + TMPFILE=$(mktemp) 58 + trap 'rm -f "$TMPFILE"' EXIT 59 + 60 + # Store filenames in an array for playback 61 + declare -a FILES_ARRAY=() 62 + while IFS= read -r file; do 63 + if [[ -n "$file" ]]; then 64 + # Extract just the filename from the path 65 + filename=$(basename "$file") 66 + echo "$FLAX_URL/$file" >> "$TMPFILE" 67 + FILES_ARRAY+=("$filename") 68 + fi 69 + done <<< "$SELECTED" 70 + 71 + echo "Starting background downloads..." 72 + # Start aria2c in background with progress bar 73 + aria2c --http-user="$FLAX_USER" --http-passwd="$FLAX_PASS" -i "$TMPFILE" --console-log-level=warn & 74 + ARIA_PID=$! 75 + 76 + # Play files as they download 77 + for file in "${FILES_ARRAY[@]}"; do 78 + echo "Waiting for $file to start downloading..." 79 + # Wait for file to exist and have some content 80 + while [[ ! -f "$file" ]] || [[ ! -s "$file" ]]; do 81 + sleep 0.5 82 + # Check if aria2c is still running 83 + if ! kill -0 $ARIA_PID 2>/dev/null; then 84 + echo "Download process ended unexpectedly" 85 + break 2 86 + fi 87 + done 88 + 89 + # Give it a moment to buffer 90 + sleep 1 91 + 92 + echo "Playing: $file" 93 + mpv "$file" 94 + done 95 + 96 + # Wait for all downloads to complete 97 + wait $ARIA_PID 98 + else 99 + # Normal mode: download all files with aria2c 100 + # Create a temporary file with URLs for aria2c 101 + TMPFILE=$(mktemp) 102 + trap 'rm -f "$TMPFILE"' EXIT 103 + 104 + while IFS= read -r file; do 105 + if [[ -n "$file" ]]; then 106 + echo "$FLAX_URL/$file" >> "$TMPFILE" 107 + fi 108 + done <<< "$SELECTED" 109 + 110 + echo "Downloading selected files..." 111 + aria2c --http-user="$FLAX_USER" --http-passwd="$FLAX_PASS" -i "$TMPFILE" 112 + fi 113 + 114 + echo "Download complete!"