yumata/lampa-source

IPTV plugin update: follow redirects

Opened this issue · 0 comments

I have a playlist that requires generating special token, once a day.
So I created a script, that generate this token and replace it in the playlist, then redirect you to newly created playlist.

But IPTV plugin seems doesn't understand this redirect, and don't read it.

Could you update it please.

Here is my script that generates m3u playlist with token

<!DOCTYPE html>
<html lang="en">
    <head>
        <script>
            function generateToken() {
                fetch('https://token.example.com/gettoken.json')
                    .then(response => response.json())
                    .then(data => {
                        const tokenRegex = /token=([^&]*)/;
                        const match = data.variants[0].url.match(tokenRegex);
                        let token = ''
                        if (match && match[1]) {
                            token = match[1];
                        }
                        return token;
                    })
                    .catch(error => console.error('Error:', error));
                return 1;
            }

            function generateM3UContent(token) {
                const m3uContent = `#EXTM3U
#EXTINF:-1 catchup="append" catchup-days="7" catchup-type="flussonic",ch1
http://example.com/ch1/video.m3u8?token=${token}
#EXTINF:-1 catchup="append" catchup-days="7" catchup-type="flussonic",ch2
http://example.com/ch2/video.m3u8?token=${token}
`;

                return m3uContent;
            }

            function useRedirectMethod(content){
                const dataUri = 'data:application/x-mpegURL;charset=utf-8,' + encodeURIComponent(content);

                // Redirect the user to the data URI
                window.location.href = dataUri;
            }
        </script>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Get M3U File</title>
    </head>
    <body>
    <script>
        const new_token = generateToken()
        const new_m3uContent = generateM3UContent(new_token);
        useRedirectMethod(new_m3uContent);
    </script>
    </body>
</html>