星期五, 十二月 29, 2023

176 CCTV 央视视频 获取 m3u8

 JavaScript: jQuery.getJSON("https://vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid=" + guid,

function(result) {

    var content = result.hls_url.link(result.hls_url);

    var match = content.match(/<a href="(.*?)">.*?<\/a>/);

    if (match && match.length === 2) {

        var fullUrl = match[1];

        var modifiedUrl = fullUrl.replace(/maxbr=\d+/, 'maxbr=2000');

        var textarea = document.createElement("textarea");

        textarea.value = modifiedUrl;

        document.body.appendChild(textarea);

        textarea.select();

        var successful = document.execCommand("copy");

        document.body.removeChild(textarea);

        if (successful) {

            console.log("文本已成功复制到剪贴板")

        } else {

            console.error("无法复制文本到剪贴板")

        }

        console.log(modifiedUrl)

    } else {

        console.log('error')

    }

});


在 console 里粘贴此代码回车. m3u8 地址会自动粘贴至剪贴板, 感谢 google bard 的帮助. 
根据 网上的方法 修改而来

星期二, 十二月 05, 2023

175 使用 php 提取 clash 订阅中的 proxies (代理节点)

使用时, 传入base64加密的订阅即可, 如

订阅地址: https://123.xyz/api/v1/client/subscribe?token=ffffffffffffffffffffffffff&flag=clash

则获取链接为: 

https://example.com/this.php?url=aHR0cHM6Ly8xMjMueHl6L2FwaS92MS9jbGllbnQvc3Vic2NyaWJlP3Rva2VuPWZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmJmZsYWc9Y2xhc2g= 

*注意 php 要 php-yaml 模块

 

<?php

$url = base64_decode($_GET['url']);


$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_HEADER, true);

curl_setopt($ch, CURLOPT_USERAGENT, 'clash.meta');

$response = curl_exec($ch);

$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);

$header = substr($response, 0, $header_size);

$body = substr($response, $header_size);

curl_close($ch);


if (preg_match('/^subscription-userinfo: (.*)$/mi', $header, $matches)) {

    $user_info = trim($matches[1]);

    header("Subscription-Userinfo: $user_info");

    //header("Content-Type: text/html; charset=UTF-8");  //如果显示有乱码就把这行打开

}


$yaml = yaml_parse($body);

$proxies = $yaml['proxies'];

echo yaml_emit(['proxies' => $proxies]);

?>  

中间那段 subscription-userinfo 的作用是, 如果订阅中 (v2board) 有这个请求头, 会一并获取回来, 可以获取剩余流量信息, 最终效果是能在客户端中展示, 如我用 metacubexd 面板, 就会展示在其中. 

使用脚本获取订阅的原因是, 有些机场写了大量规则, 好几兆, 自己有写rules所以根本用不到, 所以用php做一个过滤, 感谢老友帮忙写php