[FFmpeg-user] Getting m3u8 URL from SVTPlay channels?

Robert Jeffares jeffares.robert at gmail.com
Sun Dec 26 00:11:40 EET 2021


Hi Bo,

The SVT Play site has links to video on demand which are read by the 
embedded player not all available to me because of geoblocking.

This is not live streaming so ffmpeg is not your tool of choice.

The site cleverly creates the play link from data stored in an array of 
filenames which do not indicate the format of the video so searching for 
'mp4' or some other format is not possible.

m3u8 is a streaming flag so it's not going to be found.

Fortunately you have Ubuntu 20.04 so you have plenty of resources.

If you don't have it; install youtube-dl

Here is what I did to download videos from this site.

You can put this all in a bash script.

first get the full listing of the web page

         curl https://www.svtplay.se/ > tahi

then make the video links easy to extract

         sed -i 's/video/\n\/video/g' tahi

then extract the video link data

         cat tahi |grep '/video/' > lua

we only need the first part of each line

         awk -F'"' '{print $1 }' lua > toru

there are some trailing \ which we need to lose

         sed -i 's/\\//g' toru

there may have been some better way but this is quick and dirty

now lets weed out the double ups

          uniq  toru > fa

and insert the upstream path

         sed -i 's/^/https\:\/\/www\.svtplay\.se/g' fa

the file fa now has a series of links to the programs you can download.

If you only want one or a selection you can sort this out

otherwise

         while read line ; do youtube-dl $line; done < fa

grabs the lot.

If you are not geoblocked they will download. The ones that work here 
come as mp4.

The server is not that fast. It may be managing many clients and 
allocate each client enough to stream rather then download.

There are 1001 ways of doing this. It may be ugly; but it works!


Now a mention relating to copyright.

If a video is published on a website for on demand viewing it's ok for 
you to download it and view it on your device(s)

This is the same as downloading a podcast.

You can share with your family.

If you are going to re use the video [website broadcast education public 
screening] you should obtain permission.

This may involve some rights negotiation and a fee.

Most broadcasters make it a bit hard to extract video to protect their 
investment and the rights of producers who make a living from creating 
content.

News; especially publicly funded news; should be unencumbered, but it is 
polite to seek approval.

I looked at the page source and had a scout around for links. It looks 
java based. The video files will be on an internal server.

Not the most difficult to find. The address bar in play has it all 
assembled.

regards

Robert Jeffares

Laingholm

New Zealand










On 25/12/21 10:13 pm, Bo Berglund wrote:
> See earlier thread named "Can ffmpeg record video from this kind of URL?" where
> I discussed extracting m3u8 stream URL from a webpage URL where the video would
> appear in the browser....
>
> This m3u8 URL is then used in an ffmpeg command to download video content.
>
> The findings in that thread has been put to work and functions on several
> different streaming video pages I use.
>
> But yesterday I also wanted to download from the SVT_Play site and here the URL
> extractor does not work...
>
> The current solution is like this in the script running on Ubuntu Server
> 20.04.3:
>
> CMD="curl -s \"${STREAMURL}\" | grep -o -e \"https://.\+m3u8\"  | head -n 1"
> M3U8=$(eval $CMD)
> if [ -z $M3U8 ]; then
>    RESULT=1
>    echo "Error, no response!"
> else
>    RESULT=0
>    eval "echo ${STREAMURL} ${M3U8} > ${URLFILE}"
>    echo "Done, result in  ${URLFILE}:  ${STREAMURL} ${M3U8}"
> fi
> exit ${RESULT}
>
>
> Here STREAMURL is the input, i.e. the URL to the webpage where the video plays.
> And the result is saved to a file from which the download script reads its
> referer and stream url.
>
> But on the following pages it does not work at all:
> https://www.svtplay.se/kanaler/svt1?start=auto
> https://www.svtplay.se/kanaler/svt2?start=auto
> https://www.svtplay.se/kanaler/svt24?start=auto
> https://www.svtplay.se/kanaler/kunskapskanalen?start=auto
>
> These are the public Swedish TV channels.
>
> Is there a programmatic way to extract the m3u8 URL from these sites so it can
> be used with ffmpeg to download the videos?
>
>


More information about the ffmpeg-user mailing list