Greasy Fork

Greasy Fork is available in English.

xigua视频下载

下载xigua视频

目前为 2022-06-14 提交的版本,查看 最新版本

// ==UserScript==
// @name         xigua视频下载
// @namespace    http://tampermonkey.net/
// @version      0.0.10
// @description  下载xigua视频
// @author       kemalo1101
// @license      MIT License
// @run-at       document-start
// @grant        GM_download
// @include      *://*ixigua.com/*
// @require      http://greasyfork.icu/scripts/440006-mono/code/mono.js?version=1042513
// ==/UserScript==

(function () {
  var mono = window['mono-descargar'];
  var $ = mono.jQuery;
  var md5 = mono.md5;
  var filename = mono.filename;
  var onRequest = mono.onRequest;
  var errCode = mono.FAIL_TO_DEFAULT;
  var idKey = 'mono-dsg-id';
  var dash = null;


  var metaCache = {}

  onRequest(({url, resp, _body, method}) => {
    if (!resp || (url.indexOf('v9-xg-web-s.ixigua.com') === -1 || url.indexOf('.mpd') === -1)) return;
    var urlObj = new URL('https:' + url)
    var paths = urlObj.pathname.split('/');
    paths.pop();
    console.log('resp', resp)
    metaCache.data = {
      mpd:resp,

      url:urlObj.origin + (paths.join('/')) + '/'
    };
    metaCache.dataType = 'mpd';
    console.log('metaCache', metaCache)
  });

  var getItemByMeta = (meta, selector='', selClass='') => {
    var id = `aqy-${md5(meta.data)}`
    if ($(`[${idKey}=${id}]`).length > 0) return null;
    var $el = null;
    if (selector) $el = $(selector)
    if ($el.length > 0 && selClass) {
      var ps = $el.parentsUntil(selClass);
      if (ps.length > 0) $el = $(ps[ps.length - 1])
    }
    if ($el.length <= 0) return null;
    var container = $el[0];

    if (!dash?.config?.DASHPlugin?.dashOpts?.drm?.clearKeys) {
      const keys = Object.keys(window)
      for (let key of keys) {
        if (key.startsWith('dash_')) {
          dash = window[key]
        }
      }
    }

    if (!dash.config?.DASHPlugin?.dashOpts?.drm?.clearKeys) return null
    meta.data.key = dash.config?.DASHPlugin?.dashOpts?.drm?.clearKeys
    console.log('meta', meta)
    return { id, url: meta.data.url, container, meta: meta }
  }

  var cc = () => {
    var items = [];
    var selector = `.teleplayPage__playerSection__left`;
    var item = getItemByMeta(metaCache, selector, '.teleplayPage__playerSection')
    if (!item) return items
    if (item) items.push(item);
    return items
  }

  var parser = async function () {
    var url = window.location.href;
    if (url.indexOf('.ixigua.com') !== -1 && url.indexOf('id=') !== -1 && Object.keys(metaCache).length > 0) {
      return cc();
    } else {
      return [];
    }
  }

  if (mono?.init) mono.init({ parser });
})()