VideoHelp Forum




+ Reply to Thread
Results 1 to 6 of 6
  1. Member
    Join Date
    Feb 2021
    Location
    Sweden
    Search Comp PM
    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:
    Code:
    M3U8=$(curl -s "$STREAMURL" | grep m3u8 | sed -n "s/^.*file: \"\([^\"]*\)\".*$/\1/p")
    Here STREAMURL="https://planetnews.com/live/msnbc-news.html"
    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:
    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-";
    The ffmpeg download command using the m3u8 URL looks like this:
    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}"
    Here:
    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?
    Quote Quote  
  2. Code:
    curl -s https://planetnews.com/live/msnbc-news.html | egrep -o '"https.*?m3u8.*?"' | tr -d '"'
    Quote Quote  
  3. Member
    Join Date
    Feb 2021
    Location
    Sweden
    Search Comp PM
    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
    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?
    I am only using bash scripts in simple tools normally and I have no real experience in manipulation of strings.
    Quote Quote  
  4. 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 '"')
    The referrer is probably not even needed (but passing it doesn't hurt either).

    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.
    Quote Quote  
  5. 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?
    https://cdn.livenewsplayer.com/hls/msnbcalt/msnbcalt/playlist.m3u8?altzstarttime=1749732696&altzendtime=1749739896&a ltzhash=DeFuuzc8Dj70GTjSKMWHGzVC_GR5spjCkb6Xu1W5No 2Bb_-RWxfxXzHdA9McNhZf

    That is the actual m3u8.
    Pipe it to vlc and it will play
    Quote Quote  
  6. Member
    Join Date
    Feb 2021
    Location
    Sweden
    Search Comp PM
    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!
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!