This repository has no description
0

Configure Feed

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

tools.flaxget: only download if not already downloaded

+60 -32
+60 -32
tools/flaxget/flaxget.sh
··· 49 49 echo "Error: mpv is not installed. Stream mode requires mpv." 50 50 exit 1 51 51 fi 52 - 52 + 53 53 # Stream mode: start aria2c in background to download all files 54 54 # while playing them sequentially as they become available 55 - 55 + 56 56 # Create a temporary file with URLs for aria2c 57 57 TMPFILE=$(mktemp) 58 58 trap 'rm -f "$TMPFILE"' EXIT 59 - 59 + 60 60 # Store filenames in an array for playback 61 61 declare -a FILES_ARRAY=() 62 62 while IFS= read -r file; do 63 63 if [[ -n "$file" ]]; then 64 64 # Extract just the filename from the path 65 65 filename=$(basename "$file") 66 - echo "$FLAX_URL/$file" >> "$TMPFILE" 66 + if [[ -f "$filename" ]]; then 67 + echo "File already exists: $filename (skipping download)" 68 + else 69 + echo "$FLAX_URL/$file" >> "$TMPFILE" 70 + fi 67 71 FILES_ARRAY+=("$filename") 68 72 fi 69 73 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 - 74 + 75 + # Only start downloads if there are files to download 76 + if [[ -s "$TMPFILE" ]]; then 77 + echo "Starting background downloads..." 78 + # Start aria2c in background with progress bar 79 + aria2c --http-user="$FLAX_USER" --http-passwd="$FLAX_PASS" -i "$TMPFILE" --console-log-level=warn & 80 + ARIA_PID=$! 81 + else 82 + echo "All selected files already exist, nothing to download." 83 + ARIA_PID="" 84 + fi 85 + 76 86 # Play files as they download 77 87 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" 88 + if [[ -f "$file" ]]; then 89 + echo "Playing existing file: $file" 90 + mpv "$file" 91 + else 92 + echo "Waiting for $file to start downloading..." 93 + # Wait for file to exist and have some content 94 + while [[ ! -f "$file" ]] || [[ ! -s "$file" ]]; do 95 + sleep 0.5 96 + # Check if aria2c is still running (only if we started it) 97 + if [[ -n "$ARIA_PID" ]] && ! kill -0 $ARIA_PID 2>/dev/null; then 98 + echo "Download process ended unexpectedly" 99 + break 2 100 + fi 101 + done 102 + 103 + # Give it a moment to buffer 104 + sleep 1 105 + 106 + echo "Playing: $file" 107 + mpv "$file" 108 + fi 94 109 done 95 - 96 - # Wait for all downloads to complete 97 - wait $ARIA_PID 110 + 111 + # Wait for all downloads to complete (only if we started downloads) 112 + if [[ -n "$ARIA_PID" ]]; then 113 + wait $ARIA_PID 114 + fi 98 115 else 99 116 # Normal mode: download all files with aria2c 100 117 # Create a temporary file with URLs for aria2c ··· 103 120 104 121 while IFS= read -r file; do 105 122 if [[ -n "$file" ]]; then 106 - echo "$FLAX_URL/$file" >> "$TMPFILE" 123 + # Extract just the filename from the path 124 + filename=$(basename "$file") 125 + if [[ -f "$filename" ]]; then 126 + echo "File already exists: $filename (skipping download)" 127 + else 128 + echo "$FLAX_URL/$file" >> "$TMPFILE" 129 + fi 107 130 fi 108 131 done <<< "$SELECTED" 109 132 110 - echo "Downloading selected files..." 111 - aria2c --http-user="$FLAX_USER" --http-passwd="$FLAX_PASS" -i "$TMPFILE" 133 + # Only download if there are files to download 134 + if [[ -s "$TMPFILE" ]]; then 135 + echo "Downloading selected files..." 136 + aria2c --http-user="$FLAX_USER" --http-passwd="$FLAX_PASS" -i "$TMPFILE" 137 + else 138 + echo "All selected files already exist, nothing to download." 139 + fi 112 140 fi 113 141 114 142 echo "Download complete!"