dank074 / Discord-video-stream

Experiment for making video streaming work for discord selfbots.
185 stars 35 forks source link

User-agent Headers #118

Closed zarar2312 closed 1 day ago

zarar2312 commented 2 days ago

Benzer yayın url siteleri doğrulama istiyor. Güncel playVideo Fonksiyonun güncellenmesi gerekiyor.

    const headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36",
        "Referer": "https://example.site/", // Option.
        "Cookie": "auth_token=abc123;",  // Option.
    };

Yukarıda ki kod tarzı bot olmadığını, self hesabın çalıştığı makinenin bilgilerine yakın yada aynısını içerecek bir headers gerekiyor. .m3u8 tarzı yayın urlerini kullanırken bazı siteler doğrulama istiyor. Yani bu sorunu kökünden çözecek bir method yapılması gerekiyor.

Örnek;

import axios from "axios";
import ffmpeg from "fluent-ffmpeg";
import { MediaUdp } from "@dank074/discord-video-stream";

async function playVideo(videoUrl: string, udpConn: MediaUdp) {
    // Özel başlıklar
    const headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36",
        "Referer": "https://örnek.site/", // Gerekliyse
        "Cookie": "auth_token=abc123;",  // Gerekliyse
    };

    // HLS doğrulaması için ilk isteği yap
    try {
        const response = await axios.get(videoUrl, { headers });
        if (response.status !== 200) {
            console.log(`HLS isteği başarısız: ${response.status}`);
            return;
        }
    } catch (e) {
        console.log(`HLS doğrulama hatası: ${e}`);
        return;
    }

    console.log("Video başlatılıyor...");

    // ffmpeg ayarlarıyla akışı başlat
    const ffmpegProcess = ffmpeg(videoUrl)
        .inputOptions([
            "-headers", `User-Agent: ${headers["User-Agent"]}`,
        ])
        .outputOptions([
            "-c:v", "libx264",
            "-preset", "ultrafast",
            "-pix_fmt", "yuv420p",
            "-f", "mpegts",
        ])
        .on("start", () => {
            console.log("FFmpeg işlemi başladı.");
        })
        .on("error", (err) => {
            console.error(`FFmpeg hatası: ${err.message}`);
        })
        .on("end", () => {
            console.log("FFmpeg işlemi tamamlandı.");
        });

    // Akışı Discord UDP bağlantısına bağla
    ffmpegProcess.pipe(udpConn.mediaConnection.stream, { end: false });

    udpConn.mediaConnection.setSpeaking(true);
    udpConn.mediaConnection.setVideoStatus(true);

    console.log("Akış başlatıldı.");
}
longnguyen2004 commented 2 days ago

Please use English

zarar2312 commented 2 days ago

The code above should not rely on a bot setup; instead, it should use headers that closely mimic or match the machine's information where the self-account is running. Some sites require validation when using .m3u8 stream URLs. A method needs to be created that fundamentally resolves this issue by handling such validations seamlessly.

longnguyen2004 commented 2 days ago

That is out of scope for this library. All this library does is take an AV stream and push it to Discord, fetching the stream itself is entirely up to you. We can't know what validation methods and anti-bot measures are being used by a website, so it's impossible to have a method that will work for all websites.

zarar2312 commented 2 days ago

At least he'll stay on the sidelines

dank074 commented 2 days ago

The code above should not rely on a bot setup; instead, it should use headers that closely mimic or match the machine's information where the self-account is running. Some sites require validation when using .m3u8 stream URLs. A method needs to be created that fundamentally resolves this issue by handling such validations seamlessly.

You can override the headers by passing your own to the method.

https://github.com/dank074/Discord-video-stream/blob/d11bc5cc4bb21db5ef287f5a9e443814607c662a/src/media/streamLivestreamVideo.ts#L14