Nove TV MP4 Link Extractor

Extract MP4 links from HLS streams on Nove TV

当前为 2024-09-14 提交的版本,查看 最新版本

// ==UserScript==
// @name            Nove TV MP4 Link Extractor
// @namespace       NoveTV
// @version         1.2
// @description     Extract MP4 links from HLS streams on Nove TV
// @author          YourName
// @match           https://nove.tv/programmi-nove/fratelli-di-crozza-dove-vederlo-tv-streaming
// @require         https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js
// @grant           GM_xmlhttpRequest
// @grant           GM.xmlHttpRequest
// @connect         nove.tv
// @license         GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
// ==/UserScript==

(function() {
    'use strict';

    if (typeof GM !== "undefined" && !!GM.xmlHttpRequest) {
        GM_xmlhttpRequest = GM.xmlHttpRequest;
    }

    function fetch(params) {
        return new Promise(function(resolve, reject) {
            params.onload = resolve;
            params.onerror = reject;
            GM_xmlhttpRequest(params);
        });
    }

    function showModal(title, content) {
        if ($("#video-download-modal").length) {
            $("#video-download-modal").remove();
        }
        var modal = $(`
            <div id="video-download-modal" style="position: fixed; top: 10%; left: 50%; transform: translate(-50%, 0); padding: 20px; background: #fff; border: 1px solid #ccc; z-index: 1000;">
                <h2>${title}</h2>
                <div>${content}</div>
                <button id="modal-close" style="margin-top: 10px;">Close</button>
            </div>
        `);
        $("body").append(modal);
        $("#modal-close").click(() => modal.remove());
    }

    function parseM3U8(m3u8Content) {
        // Extract MP4 URLs from the M3U8 content
        const urls = [];
        const lines = m3u8Content.split('\n');
        lines.forEach(line => {
            if (line.endsWith('.mp4')) {
                urls.push(line.trim());
            }
        });
        return urls;
    }

    function getMP4FromHLS(url) {
        showModal('Processing', '<p>Fetching HLS stream...</p>');

        fetch({
            method: 'GET',
            url: url,
            headers: {
                'User-Agent': 'noveweb',
            },
        }).then(response => {
            const m3u8Content = response.responseText;
            const mp4Links = parseM3U8(m3u8Content);

            if (mp4Links.length > 0) {
                const linksHtml = mp4Links.map(url => `<a href="${url}" target="_blank">${url}</a>`).join("<br>");
                showModal('MP4 Links Found', `<p>Click the links below to view the video:</p><p>${linksHtml}</p>`);
            } else {
                showModal('No MP4 Links Found', '<p>No MP4 links found in the HLS stream.</p>');
            }
        }).catch(() => {
            showModal('Error', '<p>Failed to fetch the HLS stream.</p>');
        });
    }

    function extractHLSLinks() {
        showModal('Processing', '<p>Searching for HLS links...</p>');

        // Find all potential HLS URLs (usually containing .m3u8)
        const hlsLinks = [];

        $("script").each(function() {
            const scriptContent = $(this).html();
            const matches = scriptContent.match(/https:\/\/.*\.m3u8/g);
            if (matches) {
                hlsLinks.push(...matches);
            }
        });

        // Find HLS URLs in <a> tags as well
        $("a").each(function() {
            const href = $(this).attr("href");
            if (href && href.endsWith('.m3u8')) {
                hlsLinks.push(href);
            }
        });

        if (hlsLinks.length === 0) {
            showModal('No HLS Links Found', '<p>No HLS links were found on this page.</p>');
            return;
        }

        hlsLinks.forEach(link => getMP4FromHLS(link));
    }

    $(document).ready(() => {
        // Add a button to trigger HLS link extraction
        $("body").append(`
            <button id="get-hls-links" style="position: fixed; bottom: 10px; right: 10px; padding: 10px; background: #007bff; color: #fff; border: none; border-radius: 5px;">Get HLS Links</button>
        `);
        $("#get-hls-links").click(extractHLSLinks);
    });
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址