海角社区解析

🚀目前最稳定的海角免费解析🚀

// ==UserScript==
// @name          海角社区解析
// @namespace      https://github.com/J-thinker/ai-movie
// @version        v1.0.7
// @author         ak-sky
// @description    🚀目前最稳定的海角免费解析🚀
// @homepage       https://github.com/J-thinker/ai-movie
// @supportURL     https://github.com/J-thinker/ai-movie
// @run-at         document-idle
// @match          https://www.hjcx.org/*
// @match          https://hjcx.org/*
// @match          https://www.hjcx.cc/*
// @match          https://hjcx.cc/*
// @match          https://www.haijiao.com/*
// @license        MIT
// ==/UserScript==

// 环境竞争真恶劣啊,不断被友商举报。


// The competitive environment is really fierce, and we are constantly reported by our competitors.


"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (g && (g = 0, op[0] && (_ = 0)), _) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
            ar[i] = from[i];
        }
    }
    return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getImageBase64Src = exports.downloadFile = exports.getVideoListByType = exports.getVideoTypeMenu = exports.getAllLabels = exports.getVideoSearchResult = exports.loadVideo = exports.getAESConfig = exports.parseHlsURL = exports.getHlsText = exports.getVideoInfo = void 0;
/// <reference path="mogu.d.ts" />
var crypto_js_1 = require("crypto-js");
var hls_js_1 = require("hls.js");
var baseUrl = 'https://api.koudailc.net';
/** 获取视频信息 */
var getVideoInfo = function (videoId) { return __awaiter(void 0, void 0, void 0, function () {
    var params, data;
    return __generator(this, function (_a) {
        switch (_a.label) {
            case 0:
                params = new URLSearchParams([['id', videoId.toString()]]).toString();
                console.log(baseUrl + '/api/vod/info?' + params);
                return [4 /*yield*/, fetch(baseUrl + '/api/vod/info?' + params).then(function (res) { return res.json(); })];
            case 1:
                data = _a.sent();
                return [2 /*return*/, data.data];
        }
    });
}); };
exports.getVideoInfo = getVideoInfo;
/** 获取视频 M3U8 字符串 */
var getHlsText = function (videoUrl, videoId) { return __awaiter(void 0, void 0, void 0, function () {
    var data, encrypted, aesConfig, decrypted;
    return __generator(this, function (_a) {
        switch (_a.label) {
            case 0: return [4 /*yield*/, fetch(videoUrl).then(function (res) { return res.arrayBuffer(); })];
            case 1:
                data = _a.sent();
                encrypted = crypto_js_1.lib.WordArray.create(data);
                aesConfig = (0, exports.getAESConfig)(videoId);
                decrypted = crypto_js_1.AES.decrypt({ ciphertext: encrypted }, aesConfig.key, {
                    iv: aesConfig.iv,
                    padding: crypto_js_1.pad.Pkcs7,
                    mode: crypto_js_1.mode.CBC
                });
                return [2 /*return*/, decrypted.toString(crypto_js_1.enc.Utf8)];
        }
    });
}); };
exports.getHlsText = getHlsText;
/** 解密视频地址并返回可播放的 Hls URL */
var parseHlsURL = function (videoUrl, videoId) { return __awaiter(void 0, void 0, void 0, function () {
    var hlsText, blob;
    return __generator(this, function (_a) {
        switch (_a.label) {
            case 0: return [4 /*yield*/, (0, exports.getHlsText)(videoUrl, videoId)];
            case 1:
                hlsText = _a.sent();
                blob = new Blob([hlsText], { type: 'text/plain' });
                return [2 /*return*/, URL.createObjectURL(blob)];
        }
    });
}); };
exports.parseHlsURL = parseHlsURL;
/** 获取 AES 配置信息 */
var getAESConfig = function (videoId) {
    var hash = (0, crypto_js_1.MD5)((0, crypto_js_1.SHA1)(videoId.toString()).toString(crypto_js_1.enc.Hex));
    return { key: hash, iv: hash };
};
exports.getAESConfig = getAESConfig;
/** 将视频载入到视频元素 */
var loadVideo = function (videoId, element) { return __awaiter(void 0, void 0, void 0, function () {
    var hls, videoInfo, hlsUrl;
    return __generator(this, function (_a) {
        switch (_a.label) {
            case 0:
                hls = new hls_js_1.default();
                return [4 /*yield*/, (0, exports.getVideoInfo)(videoId)];
            case 1:
                videoInfo = _a.sent();
                return [4 /*yield*/, (0, exports.parseHlsURL)(videoInfo.play_url, videoInfo.id)];
            case 2:
                hlsUrl = _a.sent();
                hls.loadSource(hlsUrl);
                hls.attachMedia(element);
                return [2 /*return*/];
        }
    });
}); };
exports.loadVideo = loadVideo;
/**
 * 获取视频搜索结果
 * @param keyword 搜索关键词
 * @param page 页码,起始值为 1
 * @param pageSize 返回记录条数,最大值为 20
 * @returns 搜索结果
 */
var getVideoSearchResult = function (keyword_1) {
    var args_1 = [];
    for (var _i = 1; _i < arguments.length; _i++) {
        args_1[_i - 1] = arguments[_i];
    }
    return __awaiter(void 0, __spreadArray([keyword_1], args_1, true), void 0, function (keyword, page, pageSize) {
        var params, data;
        if (page === void 0) { page = 1; }
        if (pageSize === void 0) { pageSize = 20; }
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    params = new URLSearchParams([['limit', pageSize.toString()], ['page', page.toString()], ['wd', keyword]]).toString();
                    return [4 /*yield*/, fetch(baseUrl + '/api/vod/clever?' + params).then(function (res) { return res.json(); })];
                case 1:
                    data = _a.sent();
                    return [2 /*return*/, data.data.list];
            }
        });
    });
};
exports.getVideoSearchResult = getVideoSearchResult;
/** 获取所有的标签 */
var getAllLabels = function () { return __awaiter(void 0, void 0, void 0, function () {
    var data;
    return __generator(this, function (_a) {
        switch (_a.label) {
            case 0: return [4 /*yield*/, fetch(baseUrl + '/api/vodlabel/all').then(function (res) { return res.json(); })];
            case 1:
                data = _a.sent();
                return [2 /*return*/, data.data.list];
        }
    });
}); };
exports.getAllLabels = getAllLabels;
/** 获取视频分类菜单 */
var getVideoTypeMenu = function () { return __awaiter(void 0, void 0, void 0, function () {
    var data;
    return __generator(this, function (_a) {
        switch (_a.label) {
            case 0: return [4 /*yield*/, fetch(baseUrl + '/api/vod/type').then(function (res) { return res.json(); })];
            case 1:
                data = _a.sent();
                return [2 /*return*/, data.data.list];
        }
    });
}); };
exports.getVideoTypeMenu = getVideoTypeMenu;
/**
 * 获取分类视频列表
 * @param typeIds 分类 ID 列表
 * @param options 配置项
 * @returns 视频列表
 */
var getVideoListByType = function (typeIds_1) {
    var args_1 = [];
    for (var _i = 1; _i < arguments.length; _i++) {
        args_1[_i - 1] = arguments[_i];
    }
    return __awaiter(void 0, __spreadArray([typeIds_1], args_1, true), void 0, function (typeIds, options) {
        var params, data;
        var _a;
        if (options === void 0) { options = {}; }
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    params = new URLSearchParams([
                        ['types', typeIds.join(',')],
                        ['limit', ((_a = options.pageSize) !== null && _a !== void 0 ? _a : 20).toString()],
                        ['page', (options.page || 1).toString()],
                        ['order', '-' + (options.order || 'id')],
                    ]).toString();
                    return [4 /*yield*/, fetch(baseUrl + '/api/vod/list?' + params).then(function (res) { return res.json(); })];
                case 1:
                    data = _b.sent();
                    return [2 /*return*/, data.data.list];
            }
        });
    });
};
exports.getVideoListByType = getVideoListByType;
/** 下载文件 */
var downloadFile = function (objectURL, filename) {
    var link = document.createElement('a');
    link.href = objectURL;
    link.download = filename;
    link.click();
    link.remove();
};
exports.downloadFile = downloadFile;
/** 获取图片的 Base64 格式 src  */
var getImageBase64Src = function (imageUrl) { return __awaiter(void 0, void 0, void 0, function () {
    var data, encrypted, imageId, key, iv, decrypted;
    return __generator(this, function (_a) {
        switch (_a.label) {
            case 0: return [4 /*yield*/, fetch(imageUrl).then(function (res) { return res.arrayBuffer(); })];
            case 1:
                data = _a.sent();
                encrypted = crypto_js_1.lib.WordArray.create(data);
                imageId = imageUrl.match(/([^/]+)\.[^/]+$/)[1];
                console.log(imageId);
                key = (0, crypto_js_1.MD5)(imageId);
                iv = key;
                decrypted = crypto_js_1.AES.decrypt({ ciphertext: encrypted }, key, {
                    iv: iv,
                    padding: crypto_js_1.pad.Pkcs7,
                    mode: crypto_js_1.mode.CBC
                });
                return [2 /*return*/, 'data:image/jpeg;base64,' + decrypted.toString(crypto_js_1.enc.Base64)];
        }
    });
}); };
exports.getImageBase64Src = getImageBase64Src;