I am downloading news shows for later viewing at a convenient time in my timezone.
The download is being done on a Linux Ubuntu 24.04 server using ffmpeg as downloader and it needs the m3u8 URL to the m3u8 stream in order to work.
I have a script that extracts the m3u8 URL for use by ffmpeg, but it has stopped working and I am not clever enough to extract it myself.
So can someone please help?
The original extractor code in the script looks like this and has worked OK but no longer:
Here STREAMURL="https://planetnews.com/live/msnbc-news.html"Code:M3U8=$(curl -s "$STREAMURL" | grep m3u8 | sed -n "s/^.*file: \"\([^\"]*\)\".*$/\1/p")
which is the URL to the webpage hosting the video player I want to download from.
When I run the command on the command line it returns an empty string....
If I remove the sed call the output of the command is:
The ffmpeg download command using the m3u8 URL looks like this:Code:$ curl -s https://planetnews.com/live/msnbc-news.html | grep m3u8 const streamURL = "https://cdn.livenewsplayer.com/hls/msnbcalt/msnbcalt/playlist.m3u8?altzstarttime=1749718334&altzendtime=1749725534&altzhash=gGZEq7lIcZrZoIGxsEbQIpzSk8rkonzrAjTGqJl8JFIR6BxuP4hPzKDDyBMORSS-";
Here:Code:CMD="ffmpeg -hide_banner -loglevel warning -referer ${VIDEOURL} -i \"${M3U8URL}\" -r 30 -vf scale=w=-4:h=480 -c:v libx264 -preset fast -crf 26 -x264-params keyint=30:scenecut=0:open-gop=0 -c:a aac -t ${CAPTURETIME} ${TARGETFILE}"
VIDEOURL=URL to the webpage hosting the player
M3U8URL=The m3u8 URL that the stream extraction script fails to get....
CAPTURETIME=number of seconds to download
TARGETFILE=output mp4 file name
With a working m3u8 URL the script works just fine to download video....
Any ideas what to do to extract the m3u8 URL?
+ Reply to Thread
Results 1 to 6 of 6
-
-
Code:
curl -s https://planetnews.com/live/msnbc-news.html | egrep -o '"https.*?m3u8.*?"' | tr -d '"'
-
Thanks,
but I get this when I try:
Code:$ curl -s https://planetnews.com/live/msnbc-news.html | egrep -o '"https.*?m3u8.*?"' | tr -d '"' https://cdn.livenewsplayer.com/hls/msnbcalt/msnbcalt/playlist.m3u8?altzstarttime=1749732696&altzendtime=1749739896&altzhash=DeFuuzc8Dj70GTjSKMWHGzVC_GR5spjCkb6Xu1W5No2Bb_-RWxfxXzHdA9McNhZf
I.e. what in this is the wanted m3u8 URL and how do I extract it?
I am only using bash scripts in simple tools normally and I have no real experience in manipulation of strings. -
It seems that the service needs a User-Agent header when fetching the m3u8 resource.
Fetching works for me with eg:
Code:curl -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36' \ -H "Referer: https://planetnews.com/" \ -s $(curl -s https://planetnews.com/live/msnbc-news.html | egrep -o '"https.*?m3u8.*?"' | tr -d '"')
You can use the "-user_agent" option with ffmpeg to pass the User-Agent field. It must be set before the m3u8 url, like you do with the "-referer" option. -
Code:
$ curl -s https://planetnews.com/live/msnbc-news.html | egrep -o '"https.*?m3u8.*?"' | tr -d '"'
https://cdn.livenewsplayer.com/hls/msnbcalt/msnbcalt/playlist.m3u8?altzstarttime=17497...fxXzHdA9McNhZf
How do I get the actual m3u8 URL out of that response?
I.e. what in this is the wanted m3u8 URL and how do I extract it?
That is the actual m3u8.
Pipe it to vlc and it will play -
Obo & Gromyko, thanks for your input!
Much appreciated!
I have now put the extraction code into my script for m3u8 retrieval, which is used by my downloader script and in fact that very long string is actually the working m3u8 URL!
Works fine now to download the video using this!
Similar Threads
-
Need curl command to extract m3u8 url
By tonygables in forum Video Streaming DownloadingReplies: 2Last Post: 26th Feb 2024, 01:11 -
Automate m3u8 URL extraction from site with video player...
By BosseB in forum Video Streaming DownloadingReplies: 27Last Post: 24th Feb 2024, 05:29 -
How to automatically extract the m3u8 stream URL from this site?
By BosseB in forum Video Streaming DownloadingReplies: 23Last Post: 7th Feb 2023, 20:13 -
How to automatically extract m3u8 URL from this streaming site?
By BosseB in forum Video Streaming DownloadingReplies: 12Last Post: 10th Oct 2022, 07:10 -
How to extract and use an m3u8 URL to download from a 24/7 stream?
By BosseB in forum Video Streaming DownloadingReplies: 28Last Post: 1st Feb 2022, 07:57