VideoHelp Forum


Try StreamFab Downloader and download from Netflix, Amazon, Youtube! Or Try DVDFab and copy Blu-rays! or rip iTunes movies!


Try StreamFab Downloader and download streaming video from Youtube, Netflix, Amazon! Download free trial.


+ Reply to Thread
Results 1 to 7 of 7
Thread
  1. Hi,
    I'm on Windows, using Edge browser.
    When playing the video I see that the M3U8 URLs, in Developer Tools-> Network, are changing from time to time with different tokens, the beginning of the URL remains the same though.
    Here is an example of one URL:
    https://tv.ipslow.com/tv192_www.elahmad.com_mbc_max/tracks-v1a1/mono.m3u8?token=5fb33c...490-1680878690

    I want to write a script to retrieve the current URL automatically, without manually opening the browser and get inside the Development Tools. I know that it may be possible using Powershell (Invoke-WebRequest ), but I have zero experience with this. There's a lot of info on the web, but everything deals with a singular URL

    Also, do I need to play the video in order to get the M3U8 URLs? Can I automate that too?

    Thanks
    Quote Quote  
  2. Hi ,

    First of all , the link you provided is from a site called "https://www.elahmad.com/tv/" , which uses various types of links .

    Some of these links are static m3u8 links from different IPTV providers , some are dynamic using tokens like the link in your case and other links uses DRM and obtained from some subscription services like shahid and even from sling ,but they are DRM protected with widevine which is not your case .

    My Advice is that this site keep making changes every while so you may consider looking for other public source for you links .

    Back to your problem , Some dynamic links are easy to obtain ,but others are hard because they are encrypted using AES!

    Let's take as an example the channel in your link "MBC Max HD" , this channel have 3 sources that can be watched from using this link:
    http://www.elahmad.com/tv/mbc-live.php

    Note: I'm not a good programmer either , but i hope this will be a start point for you to obtain the links you desire from this site .

    Now for this channel some of the sources are easy to get links from like this one :
    http://www.elahmad.com/tv/radiant.php?id=mbcmax_tv_1

    With simple headers and static data payload you can get the link and you only need b64decode it using this python script :
    Code:
    import requests
    import base64
    
    headers = {
        'Accept': 'application/json, text/javascript, */*; q=0.01',
        'Accept-Language': 'en-US,en;q=0.9',
        'Connection': 'keep-alive',
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
        'Origin': 'http://www.elahmad.com',
        'Referer': 'http://www.elahmad.com/tv/radiant.php?id=mbcmax_tv_1',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36',
        'X-Requested-With': 'XMLHttpRequest',
    }
    
    data = {
        'id': 'mbcmax_tv_1',
    }
    
    result = requests.post(
        'http://www.elahmad.com/tv/result/embed_result_64.php',
        headers=headers,
        data=data,
        verify=False,
    )
    result_array= result.text.split('"')
    mbc_max_link=base64.b64decode(result_array[3])
    print("MBC Max HD Link:\n"+mbc_max_link.decode('utf-8'))
    Other sources are harder to get links from like this one:
    http://www.elahmad.com/tv/watchtv.php?id=mbc_max

    Because you need to obtain data payload first then make another request to get AES key ,iv and encrypted link (all of these change with every new request), and here is another python script to automate this for you :
    Code:
    import requests
    import re
    import json
    from Crypto.Cipher import AES
    from Crypto.Util.Padding import pad, unpad
    import base64
    
    #Get the data Payload 
    headers = {
        'Accept': 'application/json, text/javascript, */*; q=0.01',
        'Accept-Language': 'en-US,en;q=0.9',
        'Connection': 'keep-alive',
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
        'Origin': 'http://www.elahmad.com',
        'Referer': 'http://www.elahmad.com/tv/watchtv.php?id=mbc_max',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36',
        'X-Requested-With': 'XMLHttpRequest',
    }
    
    params = {
        'id': 'mbc_max',
    }
    
    response = requests.get(
        'http://www.elahmad.com/tv/watchtv.php',
        params=params,
        headers=headers,
        verify=False,
    )
    
    
    items=re.findall("var da_ta =.*$",response.text,re.MULTILINE)
    array= re.split('\'', items[0])
    data_payload=array[1]
    
    #Format the payload 
    data_payload={f'{data_payload}':"mbc_max"}
    
    #Get the encrypted link , key and IV 
    response2 = requests.post('http://www.elahmad.com/tv/watchtv.php',headers=headers, data = data_payload, verify=False)
    a=response2.text.split("\"")
    aes_encrypted=a[3].encode("utf-8")
    items=re.findall("my_crypt.*$",response.text,re.MULTILINE)
    items=re.split('"', items[0])
    key=items[1].encode("utf-8")
    iv="www.elahmad.com/".encode('utf-8')[:16]
    
    #Decrypt the link 
    aes_encrypted = base64.b64decode(aes_encrypted)
    cipher = AES.new(key, AES.MODE_CBC, iv)
    link = cipher.decrypt(aes_encrypted)
    link = unpad(link, 16)
    
    print("MBC Max HD Link:\n"+link.decode('utf-8'))
    And of course you need python installed with all required modules to run these two scripts , Now to the testing phase of those two scripts :

    Image
    [Attachment 70305 - Click to enlarge]


    as you can see links obtained in both .

    Finally running the links using VLC:
    Image
    [Attachment 70306 - Click to enlarge]



    These scripts for this channel will work as long as no server side changes are made .


    I hope this will help you in your quest .


    Regards
    Quote Quote  
  3. Originally Posted by thej911 View Post
    Hi ,

    First of all , the link you provided is from a site called "https://www.elahmad.com/tv/" , which uses various types of links .

    Some of these links are static m3u8 links from different IPTV providers , some are dynamic using tokens like the link in your case and other links uses DRM and obtained from some subscription services like shahid and even from sling ,but they are DRM protected with widevine which is not your case .

    My Advice is that this site keep making changes every while so you may consider looking for other public source for you links .

    Back to your problem , Some dynamic links are easy to obtain ,but others are hard because they are encrypted using AES!

    Let's take as an example the channel in your link "MBC Max HD" , this channel have 3 sources that can be watched from using this link:
    http://www.elahmad.com/tv/mbc-live.php

    Note: I'm not a good programmer either , but i hope this will be a start point for you to obtain the links you desire from this site .

    Now for this channel some of the sources are easy to get links from like this one :
    http://www.elahmad.com/tv/radiant.php?id=mbcmax_tv_1

    With simple headers and static data payload you can get the link and you only need b64decode it using this python script :
    Code:
    import requests
    import base64
    
    headers = {
        'Accept': 'application/json, text/javascript, */*; q=0.01',
        'Accept-Language': 'en-US,en;q=0.9',
        'Connection': 'keep-alive',
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
        'Origin': 'http://www.elahmad.com',
        'Referer': 'http://www.elahmad.com/tv/radiant.php?id=mbcmax_tv_1',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36',
        'X-Requested-With': 'XMLHttpRequest',
    }
    
    data = {
        'id': 'mbcmax_tv_1',
    }
    
    result = requests.post(
        'http://www.elahmad.com/tv/result/embed_result_64.php',
        headers=headers,
        data=data,
        verify=False,
    )
    result_array= result.text.split('"')
    mbc_max_link=base64.b64decode(result_array[3])
    print("MBC Max HD Link:\n"+mbc_max_link.decode('utf-8'))
    Other sources are harder to get links from like this one:
    http://www.elahmad.com/tv/watchtv.php?id=mbc_max

    Because you need to obtain data payload first then make another request to get AES key ,iv and encrypted link (all of these change with every new request), and here is another python script to automate this for you :
    Code:
    import requests
    import re
    import json
    from Crypto.Cipher import AES
    from Crypto.Util.Padding import pad, unpad
    import base64
    
    #Get the data Payload 
    headers = {
        'Accept': 'application/json, text/javascript, */*; q=0.01',
        'Accept-Language': 'en-US,en;q=0.9',
        'Connection': 'keep-alive',
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
        'Origin': 'http://www.elahmad.com',
        'Referer': 'http://www.elahmad.com/tv/watchtv.php?id=mbc_max',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36',
        'X-Requested-With': 'XMLHttpRequest',
    }
    
    params = {
        'id': 'mbc_max',
    }
    
    response = requests.get(
        'http://www.elahmad.com/tv/watchtv.php',
        params=params,
        headers=headers,
        verify=False,
    )
    
    
    items=re.findall("var da_ta =.*$",response.text,re.MULTILINE)
    array= re.split('\'', items[0])
    data_payload=array[1]
    
    #Format the payload 
    data_payload={f'{data_payload}':"mbc_max"}
    
    #Get the encrypted link , key and IV 
    response2 = requests.post('http://www.elahmad.com/tv/watchtv.php',headers=headers, data = data_payload, verify=False)
    a=response2.text.split("\"")
    aes_encrypted=a[3].encode("utf-8")
    items=re.findall("my_crypt.*$",response.text,re.MULTILINE)
    items=re.split('"', items[0])
    key=items[1].encode("utf-8")
    iv="www.elahmad.com/".encode('utf-8')[:16]
    
    #Decrypt the link 
    aes_encrypted = base64.b64decode(aes_encrypted)
    cipher = AES.new(key, AES.MODE_CBC, iv)
    link = cipher.decrypt(aes_encrypted)
    link = unpad(link, 16)
    
    print("MBC Max HD Link:\n"+link.decode('utf-8'))
    And of course you need python installed with all required modules to run these two scripts , Now to the testing phase of those two scripts :

    Image
    [Attachment 70305 - Click to enlarge]


    as you can see links obtained in both .

    Finally running the links using VLC:
    Image
    [Attachment 70306 - Click to enlarge]



    These scripts for this channel will work as long as no server side changes are made .


    I hope this will help you in your quest .


    Regards
    Thanks a lot for this extensive explanation.
    I have some knowledge in programming, but unfortunately not in Python 😥. I was hoping to use something in Java in Selinium or Powershell...
    What do you mean by "static data payload"? So your code will work only with this "static data payload"?
    Quote Quote  
  4. Originally Posted by PODL View Post

    Thanks a lot for this extensive explanation.
    I have some knowledge in programming, but unfortunately not in Python 😥. I was hoping to use something in Java in Selinium or Powershell...
    What do you mean by "static data payload"? So your code will work only with this "static data payload"?
    By "static data payload" i was referring to the data section which is static (fixed/unchanged....till now) for the request in the first script :

    Code:
    data = {
        'id': 'mbcmax_tv_1',
    }

    Again I'm not a good programmer ,But I think converting the first script to Powershell should look like this :
    Code:
    $headers=@{}
    $headers.Add("Accept", "application/json, text/javascript, */*; q=0.01")
    $headers.Add("Accept-Language", "en-US,en;q=0.9")
    $headers.Add("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
    $headers.Add("Origin", "http://www.elahmad.com")
    $headers.Add("Referer", "http://www.elahmad.com/tv/radiant.php?id=mbcmax_tv_1")
    $headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36")
    $headers.Add("X-Requested-With", "XMLHttpRequest")
    $response = Invoke-RestMethod -Uri 'http://www.elahmad.com/tv/result/embed_result_64.php' -Method POST -Headers $headers -ContentType 'application/x-www-form-urlencoded; charset=UTF-8' -Body 'id=mbcmax_tv_1'
    $b64 = $response -Split(";")
    $b64 = $b64[0] -split("@{link=")
    $link = [Text.Encoding]::Utf8.GetString([Convert]::FromBase64String($b64))
    "MBC Max HD Link:"
    $link
    Read-Host -Prompt "Press Enter to exit"
    Image
    [Attachment 70330 - Click to enlarge]


    Regards
    Quote Quote  
  5. Originally Posted by thej911 View Post
    Originally Posted by PODL View Post

    Thanks a lot for this extensive explanation.
    I have some knowledge in programming, but unfortunately not in Python 😥. I was hoping to use something in Java in Selinium or Powershell...
    What do you mean by "static data payload"? So your code will work only with this "static data payload"?
    By "static data payload" i was referring to the data section which is static (fixed/unchanged....till now) for the request in the first script :

    Code:
    data = {
        'id': 'mbcmax_tv_1',
    }

    Again I'm not a good programmer ,But I think converting the first script to Powershell should look like this :
    Code:
    $headers=@{}
    $headers.Add("Accept", "application/json, text/javascript, */*; q=0.01")
    $headers.Add("Accept-Language", "en-US,en;q=0.9")
    $headers.Add("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
    $headers.Add("Origin", "http://www.elahmad.com")
    $headers.Add("Referer", "http://www.elahmad.com/tv/radiant.php?id=mbcmax_tv_1")
    $headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36")
    $headers.Add("X-Requested-With", "XMLHttpRequest")
    $response = Invoke-RestMethod -Uri 'http://www.elahmad.com/tv/result/embed_result_64.php' -Method POST -Headers $headers -ContentType 'application/x-www-form-urlencoded; charset=UTF-8' -Body 'id=mbcmax_tv_1'
    $b64 = $response -Split(";")
    $b64 = $b64[0] -split("@{link=")
    $link = [Text.Encoding]::Utf8.GetString([Convert]::FromBase64String($b64))
    "MBC Max HD Link:"
    $link
    Read-Host -Prompt "Press Enter to exit"
    Image
    [Attachment 70330 - Click to enlarge]


    Regards
    I was able to harness your extraordinary code to capture another channel, but it seems they change the logic by which they now encrypt the links.
    So, the updated PS script is as follows:

    Code:
     $headers=@{}
      $headers.Add("Accept", "application/json, text/javascript, */*; q=0.01")
      $headers.Add("Accept-Language", "en-US,en;q=0.9")
      $headers.Add("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
      $headers.Add("Origin", "http://www.elahmad.com")
      $headers.Add("Referer", "http://www.elahmad.com/tv/watchtv.php?id=mbc2tv")
      $headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36")
      $headers.Add("X-Requested-With", "XMLHttpRequest")
      $response = Invoke-RestMethod -Uri 'http://www.elahmad.com/tv/watchtv.php' -Method POST -Headers $headers -ContentType 'application/x-www-form-urlencoded; 
        charset=UTF-8' -Body '2901079d62bebe07b26762cbff970bdc=mbc2tv'

    But $response is no longer a proper base64 string.
    In the .php webpage I found this function my_crypt which I'm unable to trace:

    Code:
    success: function(response) {
                            stream_Url = my_crypt(response.link_url_4, "254047c19db2f15f5918772b6b1b345e", "www.elahmad.com/");
                            setHttps(stream_Url);
                        },
    Do you know how can I Invoke this function externally in order to get stream_Url?
    Quote Quote  
  6. Originally Posted by PODL View Post

    I was able to harness your extraordinary code to capture another channel, but it seems they change the logic by which they now encrypt the links.
    So, the updated PS script is as follows:

    Code:
     $headers=@{}
      $headers.Add("Accept", "application/json, text/javascript, */*; q=0.01")
      $headers.Add("Accept-Language", "en-US,en;q=0.9")
      $headers.Add("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
      $headers.Add("Origin", "http://www.elahmad.com")
      $headers.Add("Referer", "http://www.elahmad.com/tv/watchtv.php?id=mbc2tv")
      $headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36")
      $headers.Add("X-Requested-With", "XMLHttpRequest")
      $response = Invoke-RestMethod -Uri 'http://www.elahmad.com/tv/watchtv.php' -Method POST -Headers $headers -ContentType 'application/x-www-form-urlencoded; 
        charset=UTF-8' -Body '2901079d62bebe07b26762cbff970bdc=mbc2tv'
    Hi ,
    Are you sure that the Payload and Key are static/Fixed ? I'm sure you get a message like "Oops!" From the site because they are dynamic and change every while so these have to be fetched with every new request mate .

    response is no longer a proper base64 string.
    True , it has "\" , you need to repair that .

    In the .php webpage I found this function my_crypt which I'm unable to trace
    You can trace it from the source tab:
    Code:
    function my_crypt(a, d, e) {
        d = CryptoJS.enc.Utf8.parse(d);
        e = CryptoJS.enc.Utf8.parse(e);
        a = CryptoJS.AES.decrypt(a, d, {
            iv: e
        });
        return CryptoJS.enc.Utf8.stringify(a)
    }
    Do you know how can I Invoke this function externally in order to get stream_Url?
    I don't know mate as I'm not a good programmer , but why not try to implement it ?

    For the overall process:
    1- Get the Payload
    2- Get the Encrypted link + Key
    3- Decrypting the link

    Something like this:

    Code:
    #Get the payload 
    $headers=@{}
    $headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7")
    $headers.Add("Accept-Language", "en-US,en;q=0.9")
    $headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36")
    $response = Invoke-RestMethod -Uri 'http://www.elahmad.com/tv/watchtv.php?id=mbc2tv' -Method GET -Headers $headers
    $payload = $response.Split("`n") | Select-String -Pattern "var ada_taa =.*$" 
    $payload = $payload -replace "var ada_taa = {'" -replace "'};" -replace '\s','' -replace "':'","="
    
    #Get the Enc Link and Key
    $headers2=@{}
    $headers2.Add("Referer", "http://www.elahmad.com/tv/watchtv.php?id=mbc2tv")
    $response2 = Invoke-WebRequest -Uri 'http://www.elahmad.com/tv/watchtv.php' -Method POST -Headers $headers2  -Body $payload
    $aes_enc = $response2.Content -replace '{"link_url_4":"' -replace '"}' 
    $aes_enc = $aes_enc.replace('\','')
    $key = $response.Split("`n") | Select-String -Pattern "stream_Url = my_crypt.*$" 
    $key = $key.Line.Split(",")[1] -replace '\s','' -replace '"'
    
    #Decrypting the link
    $data = [Convert]::FromBase64String($aes_enc)
    $iv   = "www.elahmad.com/"
    $aes = [System.Security.Cryptography.Aes]::Create()
    $utf8 = [System.Text.Encoding]::Utf8
    $aes.Key = $utf8.GetBytes($key)
    $aes.IV  = $utf8.GetBytes($iv)
    $dec = $aes.CreateDecryptor()
    $result = $dec.TransformFinalBlock($data, 0, $data.Length)
    $resultStr = $utf8.GetString($result)
    "MBC 2 HD Link:"
    Write-Output $resultStr
    $dec.Dispose()
    Read-Host -Prompt "Press Enter to exit"
    - Testing:
    Image
    [Attachment 71297 - Click to enlarge]


    Image
    [Attachment 71298 - Click to enlarge]


    Good Luck !
    Quote Quote  
  7. You can trace it from the source tab
    Right, I'm beginning to master the search function

    I don't know mate as I'm not a good programmer
    If that's not good programming, I don't know what is. Appreciate your help.
    Quote Quote  



Similar Threads

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