There is really cool service with Bollywood and Hollywood movies named PRMOVIES. You can watch movies online or download them for free. But the process of downloading movies is full of ads.
So I've decided to implement additional service for my Universal Movies downloader.
This time it was not easy. The player from iframe and other services are looking for referer in the headers of request. For this solution curl was used instead of wget.
I use the default header for which was copied from the browser in each request to the server.
To create correct header variable the array should be created first and then concat all values into variable

headers_source=(
 "Accept: */*"
 "Accept-Language: en-US,en;q=0.9"
 "Cache-Control: no-cache"
 "Connection: keep-alive"
 "Origin: https://somedomain.com"
 "Pragma: no-cache"
 "Referer: https://somedomain.com/"
 "Sec-Fetch-Dest: empty"
 "Sec-Fetch-Mode: cors"
 "Sec-Fetch-Site: cross-site"
 "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36"
 "sec-ch-ua: \"Not A(Brand\";v=\"8\", \"Chromium\";v=\"132\""
 "sec-ch-ua-mobile: ?0"
 "sec-ch-ua-platform: \"Linux\""
)
CURL_HEADERS=""
for header in "${headers_source[@]}"; do
   CURL_HEADERS+=" -H '$header;'"
done

And small helpful function to make requests to curl

# 1 - url
# 2 - headers string
curl_request() {
 local url="$1"
 local header_args="$2"
 local cmd="curl -L -s ${header_args} '${url}'"
 eval "$cmd"
}

Default FFMPEG playlist download will not work with this website because additional headers should be added to each request. I didn't check if it's possible via ffmpeg.

Another problem I've faced that ffmpeg show an error at the end of the process when it tried to concat the files.

[concat @ 0x55f521281340] Impossible to open '/home/user/Videos/movies/segments/hanuman-2005-Watch-online-full-movie/seg-1-v1-a1.ts'                                                                                                        
[in#0 @ 0x55f521281240] Error opening input: Invalid data found when processing input  

The videos in the playlist are encrypted. We can see it in m3u8 file

#EXT-X-KEY:METHOD=AES-128,URI="https://someserver.com/enc_key?t=HASH1&s=HASH2&e=123456&f=12345&i=0.0&sp=0"

In an HLS playlist file, the EXT-X-KEY tag specifies the method to be used for decrypting media segments. It tells the video player how to retrieve the necessary decryption key to unlock the encrypted media segments and play them back.

So we need to save key first and then decode every video.
According to the documentation, we also should have IV attribute. It's optional param and if it's not available player will use media sequence as IV. For decoding I've used first 16 bytes of each media file. It's working fine.

Get the key from the previously saved file

KEY_HEX=$(od -tx1 -An -N 16 "$FILE_KEY" | tr -d ' ')

get the IV from the downloaded file and decode it:

local KEY_IV=$(od -tx1 -An -N 16 "${DESTINATION_FOLDER}/${DOWNLOADED_FILE}" | tr -d ' ')
openssl enc -d -aes-128-cbc -K ${KEY_HEX} -iv ${KEY_IV} -in "${DESTINATION_FOLDER}/${DOWNLOADED_FILE}" -out "${DESTINATION_FOLDER}/${DOWNLOADED_FILE}e"

Example of running this script:

./movie.sh https://prmovies.host/hanuman-2005-Watch-online-full-movie/

Finally the mp4 file was created and it's working.
The only issue is that there is no quality selection for this moment. The lowest quality will be downloaded.
 

Link to the source code on github https://github.com/onesixromcom/movies-downloader