VideoHelp Forum
+ Reply to Thread
Results 1 to 6 of 6
Thread
  1. Hi
    I need help in extracting live streaming links from https://www.twitch.tv/yementv and forward them to tivimate app.
    The streaming link contains a token so every time I need a new one
    Quote Quote  
  2. Member aqzs's Avatar
    Join Date
    Mar 2024
    Location
    Paris
    Search Comp PM
    You have to make a script that fetch a fresh url and forward when requested. You have to self host that.
    Quote Quote  
  3. Originally Posted by aqzs View Post
    You have to make a script that fetch a fresh url and forward when requested. You have to self host that.
    Yes that's exactly what I want, I have a script running on flask that does this on several other platforms.

    But I didn't succeed on twitch,

    Look what I came up with

    Code:
    import requests
    
    headers = {
        'Accept': 'application/x-mpegURL, application/vnd.apple.mpegurl, application/json, text/plain',
        'DNT': '1',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36',
    }
    
    params = (
        ('sig', '8ef3cd57c77d9c6c9c72ee943f65ac654ec11f5a'),
        ('token', '{"adblock":false,"authorization":{"forbidden":false,"reason":""},"blackout_enabled":false,"channel":"yementv","channel_id":492835585,"chansub":{"restricted_bitrates":[],"view_until":1924905600},"ci_gb":false,"geoblock_reason":"","device_id":"78b902e307bf5b","expires":1726180696,"extended_history_allowed":false,"game":"","hide_ads":false,"https_required":true,"mature":false,"partner":false,"platform":"web","player_type":"site","private":{"allowed_to_view":true},"privileged":false,"role":"","server_ads":true,"show_ads":true,"subscriber":false,"turbo":false,"user_id":null,"version":2}'),
    )
    
    response = requests.get('https://usher.ttvnw.net/api/channel/hls/yementv.m3u8', headers=headers, params=params)
    The token is somehow connected to the sig, maybe some encryption
    Quote Quote  
  4. I just looked at this and I noticed as well that the dynamic m3u8 url needs just those two parameters (sig and token). Token is relatively simple as it's just a url-encoded JSON with mostly predictable (or even static) values. But yes, the signature is calculated from that token using a key known only to Twitch. As soon as you change just one thing in the token value, the signature becomes invalid and the url will return an error message to say as much.

    It also looks like these m3u8 url's aren't simply fetched from some API that you could call yourself, but are produced by as piece of WASM code that gets loaded from Amazon (amazon-ivs-wasmworker). I don't think there's much you can do here except going the Selenium/Puppeteer route but even then, a captcha could stop you in your tracks.
    Quote Quote  
  5. I wrote the code a while ago, but I'm not sure if I should share it here publicly, because it will be patched by a developer lurking here. If you want it DM me and I'll share it with you
    Quote Quote  
  6. Code:
    pip install streamlink
    Code:
    pip install --upgrade streamlink
    Make sure streamlink is installed and working on your system for this to function correctly. You can test it directly by running
    "streamlink https://www.twitch.tv/yementv best" in your terminal to check the available stream.

    Code:
    import subprocess
    
    def get_m3u8_playlist(twitch_url):
        try:
            # Use streamlink to fetch the best stream quality URL
            result = subprocess.run(
                ['streamlink', '--stream-url', twitch_url, 'best'],
                capture_output=True,
                text=True
            )
            
            # Check if the command was successful
            if result.returncode == 0:
                m3u8_url = result.stdout.strip()
                print(f"M3U8 playlist URL: {m3u8_url}")
                return m3u8_url
            else:
                print(f"Error fetching M3U8 playlist: {result.stderr}")
                return None
        except Exception as e:
            print(f"An error occurred: {str(e)}")
            return None
    
    if __name__ == "__main__":
        twitch_url = "https://www.twitch.tv/yementv"
        get_m3u8_playlist(twitch_url)
    Quote Quote  



Similar Threads

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