caprica / vlcj

Java framework for the vlc media player
http://www.capricasoftware.co.uk/projects/vlcj
1.1k stars 260 forks source link

Adding options has no effect when playing streaming video #1209

Closed byxiaobai closed 5 months ago

byxiaobai commented 5 months ago

I am trying to play steaming video. When I use vcl for windows , it works well.

The url is

https://cn-hbwh-cm-01-14.bilivideo.com/upgcxcode/12/39/1405483912/1405483912-1-192.mp4?e=ig8euxZM2rNcNbNz7zdVhwdlhbhahwdVhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1705220768&gen=playurlv2&os=bcache&oi=1863275617&trid=0000c6e60b288f8e472a9450940035bf3514u&mid=0&platform=pc&upsig=ef3f89c2ee1140cc90d63d7537c56ed7&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform&cdnid=10210&bvc=vod&nettype=0&orderid=0,3&buvid=&build=0&f=u_0_0&agrr=1&bw=238744&logo=80000000

The options are

:http-referrer=https://www.bilibili.com :http-user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36

But when I use vlcj, there will be a 403 error message (the referer option does not work)

public void playBilibiliVideo(String bvid){
        System.out.println("playBilibiliVideo:"+bvid);
        BilibiliVideoInfo videoInfo= BilibiliDecoder.INSTANCE.getVideoInfo(bvid);
        String downloadUrl=videoInfo.getVideoDownloadUrl();
        String option=":http-referrer=https://www.bilibili.com :http-user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36";
        getAPI().media().prepare(new String(downloadUrl.getBytes(), StandardCharsets.UTF_8),":http-referrer","https://www.bilibili.com",":http-user-agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36");

        getAPI().audio().setVolume(200);
        getAPI().controls().play();
    }
http debug: stream 1 13 headers:
http debug:  :status: "403"
http debug:  server: "openresty"
http debug:  date: "Sun, 14 Jan 2024 07:16:00 GMT"
http debug:  content-type: "text/html"
http debug:  content-length: "150"
http debug:  x-upsig-version: "20220801"
http debug:  access-control-allow-headers: "Origin, Referer, Range, Pragma"
http debug:  access-control-expose-headers: "X-Service-Module, Origin, Referer, Range, Pragma"
http debug:  access-control-allow-methods: "GET, HEAD, OPTIONS"
http debug:  access-control-allow-credentials: "true"
http debug:  access-control-allow-origin: "*"
http debug:  access-control-max-age: "21600"
http debug:  x-service-module: "bvc-h2-server"
http debug: in DATA (0x00) frame of 150 bytes, flags 0x01, stream 1
http debug: out (priority) WINDOW_UPDATE (0x08) frame of 4 bytes, flags 0x00, global
http debug: stream 1 closed by peer
http error: HTTP 403 error
byxiaobai commented 5 months ago

My options are in wrong format. The correct format should be like ":http-referrer=https://whatever.com/" The correct code is

public void playBilibiliVideo(String bvid){
        System.out.println("playBilibiliVideo:"+bvid);
        BilibiliVideoInfo videoInfo= BilibiliDecoder.INSTANCE.getVideoInfo(bvid);
        String downloadUrl=videoInfo.getVideoDownloadUrl();
        String option=":http-referrer=https://www.bilibili.com :http-user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36";
        getAPI().media().prepare(new String(downloadUrl.getBytes(), StandardCharsets.UTF_8),"http-referrer=https://www.bilibili.com",":http-user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36");

        getAPI().audio().setVolume(200);
        getAPI().controls().play();
    }

thanks a lot for @caprica