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\"
@osvivant
Copy link

Hi uahim, thanks for your reply and I am trying to find a way to download ARTE video with different language subtitles. Do you know how to do it?

@uahim
Copy link
Author

uahim commented Aug 22, 2022

there is currently no option to download the subtitles in the browser with my userjs script, BUT you should be able to get them using your browser's "Developer Tools" via the "network" tab. this is a quick solution: open and play the video and select your desired subtitle language, then for example in Firefox hit SHIFT + CTRL + I keyboard shortcut, then "filter urls" for vtt and you should see the url of the vtt file.

in this example, I selected the subtitle "German for the hearing impaired":
Clipboard0434734347347

you can also try programs such as JDownloader or mediathekview or, at worst, yt-dlp (this one definitely offers subtitle downloads).

all available audio, subtitle and video links are stored in the file https://api.arte.tv/api/opa/v3/videoStreams?programId=<FILMCODE>
there is an option to download subtitles for French or German using the script this page, but unfortunately no option to go through all the available ones.
the codes that correspond with the different subtitle files (FRA = French, ALL = German etc) are described in https://fta-media.konsole-labs.com/pdf_files/allgemeine-technische-richtlinien-arte-geie-v1-07-1.pdf

@osvivant
Copy link

thank you very much, it's working!!!!!!!!!!

@n40l-remimu
Copy link

n40l-remimu commented Aug 31, 2022

Hello @uahim @osvivant

I manage to download the .vtt files of subtitles.

However, I can't recognize the FILMCODE to have "all available audio, subtitle and video links"
How to find the FILMCODE?

edit: I found from the code.

Thanks a lot!
It's a good job

@n40l-remimu
Copy link

Hello @uahim

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

This may not be one of the objectives.

Thanks

@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