Skip to content

Instantly share code, notes, and snippets.

@johnpaulada
Last active November 15, 2022 17:01
Show Gist options
  • Save johnpaulada/ebac033298bfb20dc00ebf19cd8a584f to your computer and use it in GitHub Desktop.
Save johnpaulada/ebac033298bfb20dc00ebf19cd8a584f to your computer and use it in GitHub Desktop.
Downloading Embedded Streaming Videos (m3u8)

1. Get link to .m3u8

Go to the Network tab of your browser and find the file that ends in .m3u8, then its URL.

2. Install Prerequisites

You'll need youtube-dl and ffmpeg for this. In macOS, you can just use brew to install them. I will optionally install gum coz I like my scripts fancy hahaha

brew install ffmpeg
brew install youtube-dl
brew install gum        # Optional

3. Download video

Run download.sh.

gum style \
--foreground 212 --border-foreground 212 --border double \
--align center --width 50 --margin "1 2" --padding "2 4" \
'Embedded Video Downloader! (.m3u8)'
function download_video() {
master_file=$1
output_file=$2
best_format=$(youtube-dl --list-formats ${master_file} | grep "(best)" | awk '{print $1}')
gum spin --spinner globe --title "Downloading '${output_file}.mp4'..." -- youtube-dl --format "${best_format}" --output "${output_file}.mp4" ${master_file}
gum spin --spinner globe --title "Downloading '${output_file}.aac'..." -- youtube-dl --format "AAC-Default" --output "${output_file}.aac" ${master_file}
gum spin --spinner minidot --title "Combining video and audio files into '${output_file}.mkv'..." -- ffmpeg -i "${output_file}.mp4" -i "${output_file}.aac" -c copy "${output_file}.mkv"
gum style \
--foreground 212 --border-foreground 212 --border double \
--align center --width 50 --margin "1 2" --padding "2 4" \
"Completed download of '${output_file}.mkv'."
}
batch_or_single=$(gum choose single batch)
if [[ "${batch_or_single}" == "batch" ]]; then
batch_file_url=$(gum file .)
downloadz=( $(cat ${batch_file_url}) )
for download in ${downloadz[@]}
do
values=($(echo "${download}" | tr ',' '\n'))
master_file="${values[0]}"
output_file="${values[1]}"
download_video "${master_file}" "${output_file}"
done
else
master_file=$(gum input --char-limit 0 --placeholder "Link to .m3u8")
output_file=$(gum input --char-limit 0 --placeholder "Output file name")
download_video "${master_file}" "${output_file}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment