···4949 echo "Error: mpv is not installed. Stream mode requires mpv."
5050 exit 1
5151 fi
5252-5252+5353 # Stream mode: start aria2c in background to download all files
5454 # while playing them sequentially as they become available
5555-5555+5656 # Create a temporary file with URLs for aria2c
5757 TMPFILE=$(mktemp)
5858 trap 'rm -f "$TMPFILE"' EXIT
5959-5959+6060 # Store filenames in an array for playback
6161 declare -a FILES_ARRAY=()
6262 while IFS= read -r file; do
6363 if [[ -n "$file" ]]; then
6464 # Extract just the filename from the path
6565 filename=$(basename "$file")
6666- echo "$FLAX_URL/$file" >> "$TMPFILE"
6666+ if [[ -f "$filename" ]]; then
6767+ echo "File already exists: $filename (skipping download)"
6868+ else
6969+ echo "$FLAX_URL/$file" >> "$TMPFILE"
7070+ fi
6771 FILES_ARRAY+=("$filename")
6872 fi
6973 done <<< "$SELECTED"
7070-7171- echo "Starting background downloads..."
7272- # Start aria2c in background with progress bar
7373- aria2c --http-user="$FLAX_USER" --http-passwd="$FLAX_PASS" -i "$TMPFILE" --console-log-level=warn &
7474- ARIA_PID=$!
7575-7474+7575+ # Only start downloads if there are files to download
7676+ if [[ -s "$TMPFILE" ]]; then
7777+ echo "Starting background downloads..."
7878+ # Start aria2c in background with progress bar
7979+ aria2c --http-user="$FLAX_USER" --http-passwd="$FLAX_PASS" -i "$TMPFILE" --console-log-level=warn &
8080+ ARIA_PID=$!
8181+ else
8282+ echo "All selected files already exist, nothing to download."
8383+ ARIA_PID=""
8484+ fi
8585+7686 # Play files as they download
7787 for file in "${FILES_ARRAY[@]}"; do
7878- echo "Waiting for $file to start downloading..."
7979- # Wait for file to exist and have some content
8080- while [[ ! -f "$file" ]] || [[ ! -s "$file" ]]; do
8181- sleep 0.5
8282- # Check if aria2c is still running
8383- if ! kill -0 $ARIA_PID 2>/dev/null; then
8484- echo "Download process ended unexpectedly"
8585- break 2
8686- fi
8787- done
8888-8989- # Give it a moment to buffer
9090- sleep 1
9191-9292- echo "Playing: $file"
9393- mpv "$file"
8888+ if [[ -f "$file" ]]; then
8989+ echo "Playing existing file: $file"
9090+ mpv "$file"
9191+ else
9292+ echo "Waiting for $file to start downloading..."
9393+ # Wait for file to exist and have some content
9494+ while [[ ! -f "$file" ]] || [[ ! -s "$file" ]]; do
9595+ sleep 0.5
9696+ # Check if aria2c is still running (only if we started it)
9797+ if [[ -n "$ARIA_PID" ]] && ! kill -0 $ARIA_PID 2>/dev/null; then
9898+ echo "Download process ended unexpectedly"
9999+ break 2
100100+ fi
101101+ done
102102+103103+ # Give it a moment to buffer
104104+ sleep 1
105105+106106+ echo "Playing: $file"
107107+ mpv "$file"
108108+ fi
94109 done
9595-9696- # Wait for all downloads to complete
9797- wait $ARIA_PID
110110+111111+ # Wait for all downloads to complete (only if we started downloads)
112112+ if [[ -n "$ARIA_PID" ]]; then
113113+ wait $ARIA_PID
114114+ fi
98115else
99116 # Normal mode: download all files with aria2c
100117 # Create a temporary file with URLs for aria2c
···103120104121 while IFS= read -r file; do
105122 if [[ -n "$file" ]]; then
106106- echo "$FLAX_URL/$file" >> "$TMPFILE"
123123+ # Extract just the filename from the path
124124+ filename=$(basename "$file")
125125+ if [[ -f "$filename" ]]; then
126126+ echo "File already exists: $filename (skipping download)"
127127+ else
128128+ echo "$FLAX_URL/$file" >> "$TMPFILE"
129129+ fi
107130 fi
108131 done <<< "$SELECTED"
109132110110- echo "Downloading selected files..."
111111- aria2c --http-user="$FLAX_USER" --http-passwd="$FLAX_PASS" -i "$TMPFILE"
133133+ # Only download if there are files to download
134134+ if [[ -s "$TMPFILE" ]]; then
135135+ echo "Downloading selected files..."
136136+ aria2c --http-user="$FLAX_USER" --http-passwd="$FLAX_PASS" -i "$TMPFILE"
137137+ else
138138+ echo "All selected files already exist, nothing to download."
139139+ fi
112140fi
113141114142echo "Download complete!"