nrk-sapmi-podcasts / download_m3u8.sh
versae's picture
Add NRK Sápmi podcasts
6fee629
#!/bin/bash
# Check if required tools are installed
if ! command -v curl &> /dev/null; then
echo "curl is required but not installed. Exiting."
exit 1
fi
if ! command -v jq &> /dev/null; then
echo "jq is required but not installed. Exiting."
exit 1
fi
if ! command -v ffmpeg &> /dev/null; then
echo "ffmpeg is required but not installed. Exiting."
exit 1
fi
if ! command -v youtube-dl &> /dev/null; then
echo "youtube-dl is required but not installed. Exiting."
exit 1
fi
# Check if a file is provided
if [ $# -eq 0 ]; then
echo "Usage: $0 <file_with_urls>"
exit 1
fi
FILE=$1
# Process each URL in the file
while IFS= read -r url; do
echo "Processing URL: $url"
# Fetch the JSON data from the URL
json=$(curl -s "$url")
# Extract the .playable.assets[0].url property
asset_url=$(echo "$json" | jq -r '.playable.assets[0].url')
if [ "$asset_url" != "null" ]; then
echo "Found asset URL: $asset_url"
# Extract the filename from the URL
filename=$(echo "$json" | jq -r '.id')
# Download the m3u8 file using youtube-dl and ffmpeg
# ffmpeg -i "$asset_url" -c copy "$filename".m3u8
# youtube-dl -f 2500 "$asset_url" --id --restrict-filenames --add-header User-Agent:'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:104.0) Gecko/20100101 Firefox/104.0' --add-header Accept:'*/*' --add-header Accept-Language:'en-US,en;q=0.5' --add-header Accept-Encoding:'gzip, deflate, br' --add-header Origin:'https://www.nb.no' --add-header Connection:'keep-alive' --add-header Referer:'https://www.nb.no/' --add-header Sec-Fetch-Dest:'empty' --add-header Sec-Fetch-Mode:'cors' --add-header Sec-Fetch-Site:'same-site' --add-header Pragma:'no-cache' --add-header Cache-Control:'no-cache' --add-header TE:'trailers'
youtube-dl -o "$filename.%(ext)s" "$asset_url"
echo "Downloaded $filename.mp4"
else
echo "No playable asset found for URL: $url"
fi
done < "$FILE"