Bilibili-Evolved/registry/dist/components/utils/download-emoticons.js
github-actions[bot] c0d915e3da
Some checks failed
Build / build (push) Has been cancelled
CI build
2025-09-11 01:38:19 +00:00

1 line
6.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["utils/download-emoticons"]=t():e["utils/download-emoticons"]=t()}(globalThis,(()=>(()=>{var e,t,o={669:(e,t,o)=>{"use strict";o.r(t),o.d(t,{default:()=>m});var n=function(){var e=this,t=e._self._c;e._self._setupProxy;return t("DefaultWidget",{attrs:{disabled:e.downloading,name:"下载up主表情包",icon:"mdi-emoticon-outline"},on:{click:function(t){return e.download()}}})};n._withStripped=!0;const r=coreApis.ui,i=coreApis.utils.log,s=coreApis.ajax;function a(e,t,o){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var o=e[Symbol.toPrimitive];if(void 0!==o){var n=o.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}const c=(0,i.useScopedConsole)("表情包下载");const l=coreApis.download,d=coreApis.toast,u=new class{constructor(){a(this,"apiRequest",(e=>{const t={url:e,method:"GET",responseType:"json"};return(0,s.monkey)(t)})),a(this,"getImageBlob",(async e=>{const t={url:e,method:"GET",responseType:"blob"};return(0,s.monkey)(t)}))}async getEmoticonsByRoomId(e){return await this.apiRequest(`https://api.live.bilibili.com/xlive/web-ucenter/v2/emoticon/GetEmoticons?platform=pc&room_id=${e}`)}async downloadEmoticons(e){return e.map((e=>({emoticons:e.emoticons.map((e=>{try{const t=this.getImageBlob(e.url);return{emoji:e.emoji,blob:t}}catch(t){return c.error(`下载表情 ${e.emoji} 失败:`,t),null}})),pkg_name:e.pkg_name})))}async getEmoticonsArray(e){try{let t=await this.getEmoticonsByRoomId(e);if(0===t.data.data.length){c.log("获取表情包失败尝试获取真实roomId");const o=await this.getRealRoomId(e);t=await this.getEmoticonsByRoomId(o)}return t.data.data.slice(2)}catch(e){throw new Error("获取表情包失败")}}async batchDownload(e){const t=[];for(const o of e){const e=(async()=>{const e=[],t=o.emoticons.map((e=>e.blob));for(const o of t){const t=await o;e.push(t)}return{pkg_name:o.pkg_name,emoticons:o.emoticons.map(((t,o)=>({emoji:t.emoji,blob:e[o]})))}})();t.push(e)}return Promise.all(t)}async getRealRoomId(e){try{const t=await this.apiRequest(`https://api.live.bilibili.com/room/v1/Room/get_info?room_id=${e}`);if(0===Object.keys(t.data).length)throw new Error("获取直播间id失败");return t.data.room_id}catch(e){throw new Error("获取直播间id失败")}}};var p=function(e,t,o,n,r,i,s,a){var c,l="function"==typeof e?e.options:e;if(t&&(l.render=t,l.staticRenderFns=o,l._compiled=!0),n&&(l.functional=!0),i&&(l._scopeId="data-v-"+i),s?(c=function(e){(e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),r&&r.call(this,e),e&&e._registeredComponents&&e._registeredComponents.add(s)},l._ssrRegister=c):r&&(c=a?function(){r.call(this,(l.functional?this.parent:this).$root.$options.shadowRoot)}:r),c)if(l.functional){l._injectStyles=c;var d=l.render;l.render=function(e,t){return c.call(t),d(e,t)}}else{var u=l.beforeCreate;l.beforeCreate=u?[].concat(u,c):[c]}return{exports:e,options:l}}(Vue.extend({components:{DefaultWidget:r.DefaultWidget},data:()=>({downloading:!1,roomIdRegex:/^https:\/\/live\.bilibili\.com\/(?:blanc\/)?(\d+)(?:\?\.*?)?$/}),methods:{async download(){this.downloading=!0;try{const e=window.location.href;if(e.startsWith("https://live.bilibili.com/")){const t=this.roomIdRegex.exec(e)[1],o=await u.getEmoticonsArray(t);if(0===o.length)return void d.Toast.info("该up主没有专属表情包","表情包下载");const n=await u.downloadEmoticons(o),r=await u.batchDownload(n),i=new l.DownloadPackage;i.noEscape=!0;for(const e of r)if(null!==e)for(const t of e.emoticons)i.add(`${e.pkg_name}/${t.emoji}.png`,t.blob);await i.emit(`emoticons-${t}.zip`)}}catch(e){d.Toast.error("下载失败详情查看控制台","表情包下载"),(0,i.logError)(e)}finally{this.downloading=!1}}}}),n,[],!1,null,null,null);const m=p.exports},726:e=>{function t(e){var t=new Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}t.keys=()=>[],t.resolve=t,t.id=726,e.exports=t},701:e=>{"use strict";e.exports="## 下载up主专属表情包\n\n支持下载up主专属表情包处于任意直播间页面时下载按钮会在`功能`面板显示,以压缩包形式保存。"}},n={};function r(e){var t=n[e];if(void 0!==t)return t.exports;var i=n[e]={exports:{}};return o[e](i,i.exports,r),i.exports}t=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,r.t=function(o,n){if(1&n&&(o=this(o)),8&n)return o;if("object"==typeof o&&o){if(4&n&&o.__esModule)return o;if(16&n&&"function"==typeof o.then)return o}var i=Object.create(null);r.r(i);var s={};e=e||[null,t({}),t([]),t(t)];for(var a=2&n&&o;"object"==typeof a&&!~e.indexOf(a);a=t(a))Object.getOwnPropertyNames(a).forEach((e=>s[e]=()=>o[e]));return s.default=()=>o,r.d(i,s),i},r.d=(e,t)=>{for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return(()=>{"use strict";r.d(i,{component:()=>o});const e=coreApis.componentApis.define,t=coreApis.utils.urls,o=(0,e.defineComponentMetadata)({name:"downloadEmoticons",displayName:"下载表情",tags:[componentsTags.utils,componentsTags.live],entry:none,author:{name:"Pencilqaq",link:"https://github.com/pencilqaq"},widget:{component:()=>Promise.resolve().then(r.bind(r,669)).then((e=>e.default))},urlInclude:t.liveUrls,commitHash:"f8d9b5665fc198fe5b2eb39c57dab6d686e5ed74",coreVersion:"2.10.4",description:(()=>{const e=r(726);return{...Object.fromEntries(e.keys().map((t=>[t.match(/index\.(.+)\.md$/)[1],e(t)]))),"zh-CN":()=>Promise.resolve().then(r.t.bind(r,701,17)).then((e=>e.default))}})()})})(),i=i.component})()));