Skip to content

Instantly share code, notes, and snippets.

@uahim
Last active May 19, 2024 14:41
Show Gist options
  • Save uahim/9b755b3a728bf790f67488f84f26a3ba to your computer and use it in GitHub Desktop.
Save uahim/9b755b3a728bf790f67488f84f26a3ba to your computer and use it in GitHub Desktop.
May 2024: this will no longer work as arte stopped serving http mp4 hosting; script stays up for reference
#!/bin/bash
# usage
# arte_v2.sh <url>
# now also displays the link to high quality direct download of the mp4 and supports arte concert
# important:
# requires jq, which is "like sed for JSON data" ( https://stedolan.github.io/jq/ )
# replace with your preferred user agent
ua="Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0"
IN=$(echo "$1")
arrIN=(${IN//\// })
language=${arrIN[2]}
filmcode=${arrIN[4]}
if [ "$language" == "de" ]; then
langshort="A"
langsub="ALL"
audiocode="VA-STA" # via https://fta-media.konsole-labs.com/pdf_files/allgemeine-technische-richtlinien-arte-geie-v1-07-1.pdf
elif [ "$language" == "fr" ]; then
langshort="F"
langsub="FRA"
audiocode="VOF-STF"
fi
api="https://api.arte.tv/api/player/v2/config/$language/$filmcode"
apikey="Nzc1Yjc1ZjJkYjk1NWFhN2I2MWEwMmRlMzAzNjI5NmU3NWU3ODg4ODJjOWMxNTMxYzEzZGRjYjg2ZGE4MmIwOA" # thanks to https://github.com/yt-dlp/yt-dlp/pull/3302#issuecomment-1153001508
streams="https://api.arte.tv/api/opa/v3/videoStreams?programId=$filmcode"
readarray -t a < <(curl -s -k -X GET "$api" -H "User-Agent: $ua" -H "Referer: $1" | jq -r ".data.attributes.streams[0].url,.data.attributes.metadata.title,.data.attributes.rights.begin,.data.attributes.rights.end")
curl -s -k -X GET $streams -H "User-Agent: $UA" -H "Accept: */*" -H "Accept-Language: en-US,en;q=0.5" -H "Referer: $1" -H "Authorization: Bearer $apikey" > ~/artestreams.json
readarray -t pt < <(cat ~/artestreams.json | jq -r '.videoStreams[] | .profileAmm')
progtype=${pt[0]}
progtype="${progtype//$'\r'/}"
if [[ $progtype == *"CONCERT"* ]]; then
download=$(jq -r '[.videoStreams[] | select(.protocol == "HTTPS" and .bitrate == 2200 and .platform == "ARTE_NEXT") | .url][0]' < ~/artestreams.json)
else
download=$(jq -r '.videoStreams[] | select(.protocol == "HTTPS" and .bitrate == 2200 and .platform == "ARTE_NEXT" and .audioLabel == "'$audiocode'") | .url' < ~/artestreams.json)
fi
download="${download//$'\r'/}"
url=${a[0]}
title=${a[1]}
start=${a[2]}
end=${a[3]}
url="${url//$'\r'/}"
subs=$url
re='(.*)'$filmcode'_(.*)'
while [[ $subs =~ $re ]]; do
subs=${BASH_REMATCH[1]}
done
re='(.*)T(.*)'
while [[ $start =~ $re ]]; do
start=${BASH_REMATCH[1]}
done
while [[ $end =~ $re ]]; do
end=${BASH_REMATCH[1]}
done
filename="${title//$'\r'/}"
filename=${filename//[^a-zA-Z0-9_]/_}
filename=${filename//___/_}
filename=${filename//__/_}
filename=$(echo "${filename}")
printf "\n"
echo $title
printf "\n"
echo $start -
echo $end
printf "\n"
# printf "\n"
echo $url
printf "\n"
echo "download:"
echo "$download"
printf "\n"
echo ffmpeg -referer \"$1\" -user_agent \"$ua\" -i \"$url\" -c copy -bsf:a aac_adtstoasc \"$filename.mp4\"
printf "\n"
echo subtitles:
echo curl $subs"medias/"$filmcode"_st_V"$langshort"-"$langsub".vtt" \> \"$filename.vtt\"
@uahim
Copy link
Author

uahim commented Aug 31, 2022

n40l-remimu filmcode is part of the address, e.g. 071467-000-A in
https://www.arte.tv/de/videos/071467-000-A/audrey-hepburn-koenigin-der-eleganz/

Is it possible to have the audio dubbing without downloading all the dubbed videos? It would be to remux a multilingual version.

sure, I suggest using yt-dlp as you should be able to do this automatically

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment