I need to automate the extraction of a working m3u8 URL from a streaming site where the URL is only valid for 4 hours.
For a long time the URL lifetime was more than a week so I could get the m3u8 manually and then let it be used by my ffmpeg based download script during scheduled automatic video downloads.
But then they shorted the lifetime to only 240 minutes, which forces an extraction just before use and this is not possible at the requested times.
The m3u8 URL is needed for downloading the video on a Linux Ubuntu server, but if I extract the URL manually it only works for 240 minutes.
So I really need to automate the extraction in a Linux bash script such that it can be done just before the URL is needed.
Manual extraction is possible using the FireFox add-on "Video Controller", but then I have to start the video and then click the add-on icon and select the m3u8 playlist item and save it as a file. Not really workable.
The following manual sequence can be used in FireFox to get to the m3u8 URL:
The data following 'hls_src=' is the wanted m3u8 URL.Code:Steps to reproduce: ------------------- 1) Open video player website "http://www.freeintertv.com/view/id-2565" in Firefox 2) Right click player shown on screen 3) Select: This Frame -> Open Frame in New tab (This page opens: https://ustvgo.tv/player.php?stream=MSNBC) 4) Right-click background -> View Page Source (the source of the player is shown) 5) Search for 'playlist.m3u8' and find this line: var hls_src='https://h3.ustvgo.la/MSNBC/myStream/playlist.m3u8?wmsAuthSign=c2VydmVyX3RpbWU9MS8xNC8yMDIzIDI6Mzk6NDAgUE0maGFzaF92YWx1ZT1OYzZGdGJkaUJBWlYyZWpPcEJET2J3PT0mdmFsaWRtaW51dGVzPTI0MA==';
Can someone here help to create a bash script, which can repeat the above steps and save the final m3u8 URL to a file or display on the terminal screen? I have searched in vain for such a method...
Notice:
The needed script must execute as a bash script on an Ubuntu 20.04.5 LTS server (no GUI).
EDIT:
I found that there is a simpler way than the above steps (removes one step):
The Base64 encoded string wmsAuthSign decodes into this:Code:Steps to reproduce: ------------------- 1) Open video player website "http://www.freeintertv.com/view/id-2565" in Firefox 2) Right click player shown on screen 3) Select: This Frame -> View frame source 4) Search for 'playlist.m3u8' and find this line: var hls_src='https://h3.ustvgo.la/MSNBC/myStream/playlist.m3u8?wmsAuthSign=c2VydmVyX3RpbWU9MS8xNC8yMDIzIDI6Mzk6NDAgUE0maGFzaF92YWx1ZT1OYzZGdGJkaUJBWlYyZWpPcEJET2J3PT0mdmFsaWRtaW51dGVzPTI0MA==';
Code:server_time=1/14/2023 2:39:40 PM&hash_value=Nc6FtbdiBAZV2ejOpBDObw==&validminutes=240
Support our site by donate $5 directly to us Thanks!!!
Try StreamFab Downloader and download streaming video from Netflix, Amazon!
Try StreamFab Downloader and download streaming video from Netflix, Amazon!
+ Reply to Thread
Results 1 to 30 of 30
-
Last edited by BosseB; 14th Jan 2023 at 09:50.
-
I managed to do that with extenstion written on my own.
If you know how to write javascript you can try it yourself. -
I do not know where to start, but did you do a browser extension?
If so is there any way I can get a look at the source?
Just the part that extracts the m3u8 URL...
If the code uses the browser API to do stuff then I'm afraid it will not fly since there is no desktop on the Ubuntu server computer and therefore no browser...
And it needs to be a script that can run in the Linux console (as an at scheduled task or in crontab) to extract the m3u8 URL and stuff it into a file.
Of course if it is in python it could also work, but I have never programmed python myself and have only very little exposure to java. None for javascript... -
I found that there is a simpler way than the above steps (removes one step):
Code:Steps to reproduce: ------------------- 1) Open video player website "http://www.freeintertv.com/view/id-2565" in Firefox 2) Right click player shown on screen 3) Select: This Frame -> View frame source 4) Search for 'playlist.m3u8' and find this line: var hls_src='https://h3.ustvgo.la/MSNBC/myStream/playlist.m3u8?wmsAuthSign=c2VydmVyX3RpbWU9MS8xNC8yMDIzIDI6Mzk6NDAgUE0maGFzaF92YWx1ZT1OYzZGdGJkaUJBWlYyZWpPcEJET2J3PT0mdmFsaWRtaW51dGVzPTI0MA==';
Seems like Firefox is caching the page sources such that even though they change it shows an older version of the frame source when one tries to get at the new token after several hours have passed...
Chrome seems not to do this, instead it shows a new token every time one opens the frame source.
But anyway in Firefox the "Video Controller" add-on picks up the new token when used to save the m3u8 URL but it has to be the "playlist" version and not the "chunks" version in order to work with ffmpeg.
So what could be done in order to read the frame source and extract the m3u8 URL from it using a combination of for example curl or wget and sed or the like so it can be scripted? -
The task comes down to the source of this token
wmsAuthSign=c2VydmVyX3RpbWU..............PTI0MA==
I have searched but was unable to determine how or where this token is generated.
(It's origin is supposedly https://ustvgo.tv as per the curl call)
Find the source and the challenge is over.
Decoded token :
[server_time=1/15/2023 8:19:43 PM&hash_value=g01sjhsL5d8jViKDEsHV1Q==&validminute s=240]
[This is a variable hash value (typical g01sjhsL5d8jViKDEsHV1Q== (b64) 834d6c8e1b0be5df2356228312c1d5d5 (hex) ) ]
It appears that there is an algorithm that takes the server current time plus 240 minutes. The hash of the computed result comprises part of the token. Therefore the number of valid minutes cannot be changed unless the hash value is also changed.
Anyone? -
I have used wget to download the sources for analysis but I apparently did no know how to run wget properly so I got way too many of them. In fact I got 2752 directories, one for each of the sources they serve out...
Now I have to delete all except the id-2565, which is the one I am interested in... -
this is the request url that returns the tokenised playlist m3u8 - it needs the referer header to work.
Code:curl "https://ustvgo.tv/player.php?stream=MSNBC" -H "Referer: https://ustvgo.tv/msnbc/"
Code:var hls_src='https://k2.ustvgo.la/MSNBC/myStream/playlist.m3u8?wmsAuthSign=c2VydmVyX3RpbWU9MS8xNS8yMDIzIDExOjU2OjIyIFBNJmhhc2hfdmFsdWU9VTZPZXM4dWVPK1hKK2E0QnlQWldtUT09JnZhbGlkbWludXRlcz0yNDA=';
-
curl "https://ustvgo.tv/player.php?stream=MSNBC" -H "Referer: https://ustvgo.tv/msnbc/"
A big thank you to @ElCap. I really appreciate your kindly assistance. You are amazing. -
@BosseB
use this code to automate the capture of the playlist.m3u8
This command is for windows but you can easily adapt it to work on linux
Code:curl -ks "https://ustvgo.tv/player.php?stream=MSNBC" -H "Referer: https://ustvgo.tv/msnbc/" | awk "BEGIN{FS=OFS=\"\047\"} /hls_src=/{print \"\042\"$2\"\042\"}"
and the sample response is ...
"https://h4.ustvgo.la/MSNBC/myStream/playlist.m3u8?wmsAuthSign=c2VydmVyX3RpbWU9MS8xNi8y MDIzIDE6NDk6NDYgQU0maGFzaF92YWx1ZT1PZlk2ZmxnZWdtM2 ZZOU1TQWJySmtnPT0mdmFsaWRtaW51dGVzPTI0MA=="
This would not be possible, by me, without the kind help of ElCap -
THANKS A MILLION!
So I created this test script:
Code:#!/bin/bash curl "https://ustvgo.tv/player.php?stream=MSNBC" -H "Referer: https://ustvgo.tv/msnbc/" --output 2565.txt echo CMD="grep \"hls_src=\" 2565.txt | sed -e 's/.*src=\(.*\);.*/\1/'" eval "$CMD" echo echo "Done"
Code:% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 5202 0 5202 0 0 6098 0 --:--:-- --:--:-- --:--:-- 6091 'https://h5.ustvgo.la/MSNBC/myStream/playlist.m3u8?wmsAuthSign=c2VydmVyX3RpbWU9MS8xNi8yMDIzIDEyOjIwOjUyIFBNJmhhc2hfdmFsdWU9bjYwcjA3WXROMWVNcGxDRi9lYTdIQT09JnZhbGlkbWludXRlcz0yNDA=' Done
-
Well I solved it this way in my script:
Code:#!/bin/bash # This solution to finding the m3u8 of a site that puts a lifetime on the URL is based on a discussion # on the web here: # https://forum.videohelp.com/threads/408224-Automate-these-steps-for-m3u8-URL-extraction-from-streaming-site-how OUTPUTFILE="$HOME/www/MSNBC/url_m3u8-7.txt" TMPFILE="2565.tmp" CMD="curl \"https://ustvgo.tv/player.php?stream=MSNBC\" -H \"Referer: https://ustvgo.tv/msnbc/\" --output $TMPFILE" eval "$CMD" #Get m3u8 into temp file echo #Since curl leaves output without a final linefeed #Get m3u8 url line from source temp file: CMD="grep \"hls_src=\" $TMPFILE | sed -e 's/.*src=\(.*\);.*/\1/'" M3U8=$(eval "$CMD") eval "rm $TMPFILE" #No need for this anymore #Remove first and last char from URL: M3U8=${M3U8#"'"} M3U8=${M3U8%"'"} #Save to m3u8 url-file used by download script eval "echo $M3U8 > $OUTPUTFILE" echo "Done"
But I guess piping will not work since curl spews out a lot of user feedback when running... -
Code:
command: curl -s "https://ustvgo.tv/player.php?stream=MSNBC" -H "Referer: https://ustvgo.tv/msnbc/" | grep "hls_src=" $TMPFILE | awk -F\' '{ print $2 } output: https://h4.ustvgo.la/MSNBC/myStream/playlist.m3u8?wmsAuthSign=c2VydmVyX3RpbWU9MS8xNy8yMDIzIDQ6NTU6NDAgQU0maGFzaF92YWx1ZT1lWE95eVQ5V0NIeUNjWVVkWkpsWW5RPT0mdmFsaWRtaW51dGVzPTI0MA==
-
I must have missed something...
When I run the command as copied from your post and pasted into a command window on Linux:
Code:$ curl -s "https://ustvgo.tv/player.php?stream=MSNBC" -H "Referer: https://ustvgo.tv/msnbc/" | grep "hls_src=" $TMPFILE | awk -F\' '{ print $2 } > ^C
So as a last resort I created a new script file and put this into it:
Code:#!/bin/bash TEMPFILE="tempfile.txt" curl -s "https://ustvgo.tv/player.php?stream=MSNBC" -H "Referer: https://ustvgo.tv/msnbc/" | grep "hls_src=" $TMPFILE | awk -F\' '{ print $2 }
Code:$ ./test ./test: line 3: unexpected EOF while looking for matching `'' ./test: line 5: syntax error: unexpected end of file
Code:$ curl -s "https://ustvgo.tv/player.php?stream=MSNBC" -H "Referer: https://ustvgo.tv/msnbc/" | grep "hls_src=" var hls_src='https://h4.ustvgo.la/MSNBC/myStream/playlist.m3u8?wmsAuthSign=c2VydmVyX3RpbWU9MS8xNy8yMDIzIDc6MjU6MzEgQU0maGFzaF92YWx1ZT1YaTZwWktYRXJ6NnYwRUhVTXNzbUF3PT0mdmFsaWRtaW51dGVzPTI0MA==';
-
oops, there shouldnt be "$TMPFILE" and i missed the last single quote
try this
Code:curl -s "https://ustvgo.tv/player.php?stream=MSNBC" -H "Referer: https://ustvgo.tv/msnbc/" | grep "hls_src=" | awk -F\' '{ print $2 }'
-
OK, thanks.
After googling a bit I tested the following awk statement and it also works:
Code:curl -s "https://ustvgo.tv/player.php?stream=MSNBC" -H "Referer: https://ustvgo.tv/msnbc/" | grep "hls_src=" | awk -F[\'] '{ print $2 }'
-
-
Thanks, now simplified the retrieval script, which is run from cron once per hour:
Code:#!/bin/bash # This solution is based on a discussion on the web here: # https://forum.videohelp.com/threads/408224-Automate-these-steps-for-m3u8-URL-extraction-from-streaming-site-how M3U8SRC7="$HOME/www/MSNBC/url_m3u8-7.txt" M3U8=$(curl -s "https://ustvgo.tv/player.php?stream=MSNBC" -H "Referer: https://ustvgo.tv/msnbc/" | grep "hls_src=" | awk -F\' '{ print $2 }') #Save to m3u8 url-files used by download script eval "echo $M3U8 > $M3U8SRC7" echo "Done"
Last edited by BosseB; 17th Jan 2023 at 04:38.
-
-
Code:
#!/bin/bash # This solution is based on a discussion on the web here: # https://forum.videohelp.com/threads/408224-Automate-these-steps-for-m3u8-URL-extraction-from-streaming-site-how M3U8SRC7="$HOME/www/MSNBC/url_m3u8-7.txt" M3U8=$(curl -s "https://ustvgo.tv/player.php?stream=MSNBC" -H "Referer: https://ustvgo.tv/msnbc/" | grep "hls_src=" | awk -F\' '{ print $2 }') #Save to m3u8 url-files used by download script eval "echo $M3U8 > $M3U8SRC7" echo "Done"
this is mean create folder before on /home/www/MSNBC/ before running that from cron ? or can make to other destination folder ?
And notice that the path specifier is $HOME, not /home!
In my case $HOME == /home/bosse but on some other machines I may use different logon names so I use $HOME to get to the right place always.Last edited by BosseB; 17th Jan 2023 at 13:14.
-
--- ALERT! ---
A few days ago they changed the website such that the command shown above no longer works to extract the m3u8 URL!
curl returns a "404 Not Found" error!
My FireFox add-on manages to extract a m3u8 URL from this but it is not useful since it leads to a completely different newscast (CBS instead of MSNBC).
I guess nothing can be done about this except give up.... -
-
hello friends,
i trying to automatically extract m3u8 url from this site
This is free to use with a user and pass
Code:https://www.sunnxt.com/live/64067/sun-news
Code:https://suntvlive.akamaized.net/hls/live/2093435/SunNews/master.m3u8?hdnea=st=1674575040~exp=1674575340~acl=!*/2093435/SunNews/*~hmac=72e401491370d92e6f38dae4d190b4a0ae99eb062c74f3c6501c2d48ca57b890&PlayBackId=2456682745&cid=38926&country=IN&userid=2886272&nid=0&q=&bw=&dw=0&op=SUNNXT&did=0
this part not necessary
Code:&PlayBackId=2456682745&cid=38926&country=IN&userid=2886272&nid=0&q=&bw=&dw=0&op=SUNNXT&did=0
i read this forum but i am not well known about curl commands ,aslo the mega link posted by LZAA aslo not working
Code:https://forum.videohelp.com/threads/405402-Need-to-script-extraction-of-m3u8-URL-on-a-live-video-for-use-with-ffmpeg
can u guys help me to get m3u8 with a small code -
Site is www.sunnxt.com ... unable to connect.
If this site requires log in credentials then I'm afraid that you are out of luck. -
unable to connect.
by using chrome and type the sunnxt then it loads
[Attachment 68837 - Click to enlarge]
by clicking the url(www.sunnxt.com) in videoforum not working
[Attachment 68838 - Click to enlarge]Last edited by Sandy sai; 25th Jan 2023 at 03:54.
-
works with Indian vpn
previously forum members helped me how to download using hlsdl
(https://forum.videohelp.com/threads/406832-how-to-download-this-stream#post2666166)
now i need to automate this because it expires in 5mins
kindly help me friendsLast edited by Sandy sai; 25th Jan 2023 at 11:36.
Similar Threads
-
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 -
Need to script extraction of m3u8 URL on a live video for use with ffmpeg
By BosseB in forum Video Streaming DownloadingReplies: 13Last Post: 20th Apr 2022, 13:30 -
Any way to get a streaming site's manifest URL via command line?
By syrist in forum Video Streaming DownloadingReplies: 17Last Post: 26th Oct 2019, 19:22 -
encrypted m3u8 url
By agu295 in forum Video Streaming DownloadingReplies: 0Last Post: 7th Aug 2018, 21:38