Last active
January 30, 2024 15:06
-
-
Save reznor244/d56d87776f349cc06a64777713e34e65 to your computer and use it in GitHub Desktop.
playlist-stitch: Downloads all files in an m3u playlist and stitches them together into a single .mpg file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
declare -a req=("wget" "basename" "rm" "cat" "echo") | |
for cmd in "${req[@]}" | |
do | |
command -v $cmd >/dev/null 2>&1 || { echo "Required command not found: $cmd"; exit 1; } | |
done | |
[ $1 ] || { echo "Usage: $0 file1 [file2] [file3...]"; } | |
for file in "$@" | |
do | |
if [ -f "$file" ]; then | |
# Filename of current input file. | |
infile=$(basename "$file") | |
# Filename of current input file without extension. | |
name="${infile%.*}" | |
# Output filename. | |
outfile="${name}.mpg" | |
echo -e "Input: ${infile} Output: ${outfile}" | |
echo -e "===================================" | |
# Generate filename for temporary files. | |
urls="urls_$name" | |
# Store the urls of each file. | |
grep -v '#' < "$file" > "$urls" | |
# Counters | |
i=1 | |
lc=$((wc -l < "$urls") | sed 's/^ *//') | |
while read line | |
do | |
tmpfile=$(basename "$line") | |
echo -e "" | |
echo -e "Downloading [$i of $lc] ${tmpfile}" | |
wget -q --show-progress "$line" | |
echo -e "Appending to output [$i of $lc]" | |
cat $tmpfile >> "$outfile" | |
i=$((i+1)) | |
rm $tmpfile | |
done < "$urls" | |
rm "$urls" | |
else | |
(>%2 echo "File '$file' not found.") | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works really great thank you so much for taking the time to post it!
Only thing for anyone else who finds this is just be sure your m3u is in LF not CRLF 😉