diff --git a/app/js/animeHandler.js b/app/js/animeHandler.js index 1612e21..1707d20 100644 --- a/app/js/animeHandler.js +++ b/app/js/animeHandler.js @@ -697,11 +697,7 @@ async function releasesCards(items, frag, limit) { results.forEach((mediaInformation, index) => { let o = items[index].querySelector.bind(items[index]) template = cardCreator(mediaInformation) - template.onclick = async () => { - addTorrent(o('link').innerHTML, { media: mediaInformation.media, episode: mediaInformation.episode }) - store[mediaInformation.parseObject.anime_title] = await alRequest({ id: mediaInformation.media.id, method: "SearchIDSingle" }).then(res => res.data.Media) - // force updates entry data on play in case its outdated, needs to be made cleaner and somewhere else... - } + template.onclick = () => addTorrent(o('link').innerHTML, { media: mediaInformation.media, episode: mediaInformation.episode }) frag.appendChild(template) }) }) diff --git a/app/js/idbkv-chunk-store.js b/app/js/idbkv-chunk-store.js deleted file mode 100644 index 7a5808b..0000000 --- a/app/js/idbkv-chunk-store.js +++ /dev/null @@ -1 +0,0 @@ -!function(){for(var t,r,e=(t=function(t,i){(function(t){"use strict";function e(r){if(r>2147483647)throw new RangeError('The value "'+r+'" is invalid for option "size"');var e=new Uint8Array(r);return e.__proto__=t.prototype,e}function t(t,r,e){if("number"==typeof t){if("string"==typeof r)throw new TypeError('The "string" argument must be of type string. Received type number');return u(t)}return o(t,r,e)}function o(r,n,i){if("string"==typeof r)return function(r,n){if("string"==typeof n&&""!==n||(n="utf8"),!t.isEncoding(n))throw new TypeError("Unknown encoding: "+n);var i=0|a(r,n),o=e(i),s=o.write(r,n);return s!==i&&(o=o.slice(0,s)),o}(r,n);if(ArrayBuffer.isView(r))return f(r);if(null==r)throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r);if(N(r,ArrayBuffer)||r&&N(r.buffer,ArrayBuffer))return function(r,e,n){if(e<0||r.byteLength=2147483647)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+2147483647..toString(16)+" bytes");return 0|t}function a(r,e){if(t.isBuffer(r))return r.length;if(ArrayBuffer.isView(r)||N(r,ArrayBuffer))return r.byteLength;if("string"!=typeof r)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof r);var n=r.length,i=arguments.length>2&&!0===arguments[2];if(!i&&0===n)return 0;for(var o=!1;;)switch(e){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":return M(r).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return P(r).length;default:if(o)return i?-1:M(r).length;e=(""+e).toLowerCase(),o=!0}}function c(t,r,e){var n=t[r];t[r]=t[e],t[e]=n}function p(r,e,n,i,o){if(0===r.length)return-1;if("string"==typeof n?(i=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),j(n=+n)&&(n=o?0:r.length-1),n<0&&(n=r.length+n),n>=r.length){if(o)return-1;n=r.length-1}else if(n<0){if(!o)return-1;n=0}if("string"==typeof e&&(e=t.from(e,i)),t.isBuffer(e))return 0===e.length?-1:y(r,e,n,i,o);if("number"==typeof e)return e&=255,"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(r,e,n):Uint8Array.prototype.lastIndexOf.call(r,e,n):y(r,[e],n,i,o);throw new TypeError("val must be string, number or Buffer")}function y(t,r,e,n,i){var o,s=1,u=t.length,f=r.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||r.length<2)return-1;s=2,u/=2,f/=2,e/=2}function h(t,r){return 1===s?t[r]:t.readUInt16BE(r*s)}if(i){var a=-1;for(o=e;ou&&(e=u-f),o=e;o>=0;o--){for(var c=!0,l=0;li&&(n=i):n=i;var o=r.length;n>o/2&&(n=o/2);for(var s=0;s>8,i=e%256,o.push(i),o.push(n);return o}(r,t.length-e),t,e,n)}function E(t,r,e){return 0===r&&e===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(r,e))}function A(t,r,e){e=Math.min(t.length,e);for(var n=[],i=r;i239?4:h>223?3:h>191?2:1;if(i+c<=e)switch(c){case 1:h<128&&(a=h);break;case 2:128==(192&(o=t[i+1]))&&(f=(31&h)<<6|63&o)>127&&(a=f);break;case 3:o=t[i+1],s=t[i+2],128==(192&o)&&128==(192&s)&&(f=(15&h)<<12|(63&o)<<6|63&s)>2047&&(f<55296||f>57343)&&(a=f);break;case 4:o=t[i+1],s=t[i+2],u=t[i+3],128==(192&o)&&128==(192&s)&&128==(192&u)&&(f=(15&h)<<18|(63&o)<<12|(63&s)<<6|63&u)>65535&&f<1114112&&(a=f)}null===a?(a=65533,c=1):a>65535&&(a-=65536,n.push(a>>>10&1023|55296),a=56320|1023&a),n.push(a),i+=c}return function(t){var r=t.length;if(r<=B)return String.fromCharCode.apply(String,t);for(var e="",n=0;nthis.length)return"";if((void 0===e||e>this.length)&&(e=this.length),e<=0)return"";if((e>>>=0)<=(r>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return I(this,r,e);case"utf8":case"utf-8":return A(this,r,e);case"ascii":return _(this,r,e);case"latin1":case"binary":return k(this,r,e);case"base64":return E(this,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return U(this,r,e);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}.apply(this,arguments)},t.prototype.toLocaleString=t.prototype.toString,t.prototype.equals=function(r){if(!t.isBuffer(r))throw new TypeError("Argument must be a Buffer");return this===r||0===t.compare(this,r)},t.prototype.inspect=function(){var t="",r=i.INSPECT_MAX_BYTES;return t=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(t+=" ... "),""},t.prototype.compare=function(r,e,n,i,o){if(N(r,Uint8Array)&&(r=t.from(r,r.offset,r.byteLength)),!t.isBuffer(r))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof r);if(void 0===e&&(e=0),void 0===n&&(n=r?r.length:0),void 0===i&&(i=0),void 0===o&&(o=this.length),e<0||n>r.length||i<0||o>this.length)throw new RangeError("out of range index");if(i>=o&&e>=n)return 0;if(i>=o)return-1;if(e>=n)return 1;if(this===r)return 0;for(var s=(o>>>=0)-(i>>>=0),u=(n>>>=0)-(e>>>=0),f=Math.min(s,u),h=this.slice(i,o),a=r.slice(e,n),c=0;c>>=0,isFinite(e)?(e>>>=0,void 0===n&&(n="utf8")):(n=e,e=void 0)}var i=this.length-r;if((void 0===e||e>i)&&(e=i),t.length>0&&(e<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return g(this,t,r,e);case"utf8":case"utf-8":return d(this,t,r,e);case"ascii":return w(this,t,r,e);case"latin1":case"binary":return v(this,t,r,e);case"base64":return m(this,t,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return b(this,t,r,e);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},t.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var B=4096;function _(t,r,e){var n="";e=Math.min(t.length,e);for(var i=r;ii)&&(e=i);for(var o="",s=r;se)throw new RangeError("Trying to access beyond buffer length")}function C(r,e,n,i,o,s){if(!t.isBuffer(r))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>o||er.length)throw new RangeError("Index out of range")}function T(t,r,e,n,i,o){if(e+n>t.length)throw new RangeError("Index out of range");if(e<0)throw new RangeError("Index out of range")}function L(t,r,e,n,i){return r=+r,e>>>=0,i||T(t,0,e,4),l.write(t,r,e,n,23,4),e+4}function x(t,r,e,n,i){return r=+r,e>>>=0,i||T(t,0,e,8),l.write(t,r,e,n,52,8),e+8}t.prototype.slice=function(r,e){var n=this.length;(r=~~r)<0?(r+=n)<0&&(r=0):r>n&&(r=n),(e=void 0===e?n:~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),e>>=0,r>>>=0,e||S(t,r,this.length);for(var n=this[t],i=1,o=0;++o>>=0,r>>>=0,e||S(t,r,this.length);for(var n=this[t+--r],i=1;r>0&&(i*=256);)n+=this[t+--r]*i;return n},t.prototype.readUInt8=function(t,r){return t>>>=0,r||S(t,1,this.length),this[t]},t.prototype.readUInt16LE=function(t,r){return t>>>=0,r||S(t,2,this.length),this[t]|this[t+1]<<8},t.prototype.readUInt16BE=function(t,r){return t>>>=0,r||S(t,2,this.length),this[t]<<8|this[t+1]},t.prototype.readUInt32LE=function(t,r){return t>>>=0,r||S(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},t.prototype.readUInt32BE=function(t,r){return t>>>=0,r||S(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},t.prototype.readIntLE=function(t,r,e){t>>>=0,r>>>=0,e||S(t,r,this.length);for(var n=this[t],i=1,o=0;++o=(i*=128)&&(n-=Math.pow(2,8*r)),n},t.prototype.readIntBE=function(t,r,e){t>>>=0,r>>>=0,e||S(t,r,this.length);for(var n=r,i=1,o=this[t+--n];n>0&&(i*=256);)o+=this[t+--n]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*r)),o},t.prototype.readInt8=function(t,r){return t>>>=0,r||S(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},t.prototype.readInt16LE=function(t,r){t>>>=0,r||S(t,2,this.length);var e=this[t]|this[t+1]<<8;return 32768&e?4294901760|e:e},t.prototype.readInt16BE=function(t,r){t>>>=0,r||S(t,2,this.length);var e=this[t+1]|this[t]<<8;return 32768&e?4294901760|e:e},t.prototype.readInt32LE=function(t,r){return t>>>=0,r||S(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},t.prototype.readInt32BE=function(t,r){return t>>>=0,r||S(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},t.prototype.readFloatLE=function(t,r){return t>>>=0,r||S(t,4,this.length),l.read(this,t,!0,23,4)},t.prototype.readFloatBE=function(t,r){return t>>>=0,r||S(t,4,this.length),l.read(this,t,!1,23,4)},t.prototype.readDoubleLE=function(t,r){return t>>>=0,r||S(t,8,this.length),l.read(this,t,!0,52,8)},t.prototype.readDoubleBE=function(t,r){return t>>>=0,r||S(t,8,this.length),l.read(this,t,!1,52,8)},t.prototype.writeUIntLE=function(t,r,e,n){t=+t,r>>>=0,e>>>=0,n||C(this,t,r,e,Math.pow(2,8*e)-1,0);var i=1,o=0;for(this[r]=255&t;++o>>=0,e>>>=0,n||C(this,t,r,e,Math.pow(2,8*e)-1,0);var i=e-1,o=1;for(this[r+i]=255&t;--i>=0&&(o*=256);)this[r+i]=t/o&255;return r+e},t.prototype.writeUInt8=function(t,r,e){return t=+t,r>>>=0,e||C(this,t,r,1,255,0),this[r]=255&t,r+1},t.prototype.writeUInt16LE=function(t,r,e){return t=+t,r>>>=0,e||C(this,t,r,2,65535,0),this[r]=255&t,this[r+1]=t>>>8,r+2},t.prototype.writeUInt16BE=function(t,r,e){return t=+t,r>>>=0,e||C(this,t,r,2,65535,0),this[r]=t>>>8,this[r+1]=255&t,r+2},t.prototype.writeUInt32LE=function(t,r,e){return t=+t,r>>>=0,e||C(this,t,r,4,4294967295,0),this[r+3]=t>>>24,this[r+2]=t>>>16,this[r+1]=t>>>8,this[r]=255&t,r+4},t.prototype.writeUInt32BE=function(t,r,e){return t=+t,r>>>=0,e||C(this,t,r,4,4294967295,0),this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t,r+4},t.prototype.writeIntLE=function(t,r,e,n){if(t=+t,r>>>=0,!n){var i=Math.pow(2,8*e-1);C(this,t,r,e,i-1,-i)}var o=0,s=1,u=0;for(this[r]=255&t;++o>0)-u&255;return r+e},t.prototype.writeIntBE=function(t,r,e,n){if(t=+t,r>>>=0,!n){var i=Math.pow(2,8*e-1);C(this,t,r,e,i-1,-i)}var o=e-1,s=1,u=0;for(this[r+o]=255&t;--o>=0&&(s*=256);)t<0&&0===u&&0!==this[r+o+1]&&(u=1),this[r+o]=(t/s>>0)-u&255;return r+e},t.prototype.writeInt8=function(t,r,e){return t=+t,r>>>=0,e||C(this,t,r,1,127,-128),t<0&&(t=255+t+1),this[r]=255&t,r+1},t.prototype.writeInt16LE=function(t,r,e){return t=+t,r>>>=0,e||C(this,t,r,2,32767,-32768),this[r]=255&t,this[r+1]=t>>>8,r+2},t.prototype.writeInt16BE=function(t,r,e){return t=+t,r>>>=0,e||C(this,t,r,2,32767,-32768),this[r]=t>>>8,this[r+1]=255&t,r+2},t.prototype.writeInt32LE=function(t,r,e){return t=+t,r>>>=0,e||C(this,t,r,4,2147483647,-2147483648),this[r]=255&t,this[r+1]=t>>>8,this[r+2]=t>>>16,this[r+3]=t>>>24,r+4},t.prototype.writeInt32BE=function(t,r,e){return t=+t,r>>>=0,e||C(this,t,r,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t,r+4},t.prototype.writeFloatLE=function(t,r,e){return L(this,t,r,!0,e)},t.prototype.writeFloatBE=function(t,r,e){return L(this,t,r,!1,e)},t.prototype.writeDoubleLE=function(t,r,e){return x(this,t,r,!0,e)},t.prototype.writeDoubleBE=function(t,r,e){return x(this,t,r,!1,e)},t.prototype.copy=function(r,e,n,i){if(!t.isBuffer(r))throw new TypeError("argument should be a Buffer");if(n||(n=0),i||0===i||(i=this.length),e>=r.length&&(e=r.length),e||(e=0),i>0&&i=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),r.length-e=0;--s)r[s+e]=this[s+n];else Uint8Array.prototype.set.call(r,this.subarray(n,i),e);return o},t.prototype.fill=function(r,e,n,i){if("string"==typeof r){if("string"==typeof e?(i=e,e=0,n=this.length):"string"==typeof n&&(i=n,n=this.length),void 0!==i&&"string"!=typeof i)throw new TypeError("encoding must be a string");if("string"==typeof i&&!t.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(1===r.length){var o=r.charCodeAt(0);("utf8"===i&&o<128||"latin1"===i)&&(r=o)}}else"number"==typeof r&&(r&=255);if(e<0||this.length>>=0,n=void 0===n?this.length:n>>>0,r||(r=0),"number"==typeof r)for(s=e;s55295&&e<57344){if(!i){if(e>56319){(r-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(r-=3)>-1&&o.push(239,191,189);continue}i=e;continue}if(e<56320){(r-=3)>-1&&o.push(239,191,189),i=e;continue}e=65536+(i-55296<<10|e-56320)}else i&&(r-=3)>-1&&o.push(239,191,189);if(i=null,e<128){if((r-=1)<0)break;o.push(e)}else if(e<2048){if((r-=2)<0)break;o.push(e>>6|192,63&e|128)}else if(e<65536){if((r-=3)<0)break;o.push(e>>12|224,e>>6&63|128,63&e|128)}else{if(!(e<1114112))throw new Error("Invalid code point");if((r-=4)<0)break;o.push(e>>18|240,e>>12&63|128,e>>6&63|128,63&e|128)}}return o}function P(t){return n.toByteArray(function(t){if((t=(t=t.split("=")[0]).trim().replace(R,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function O(t,r,e,n){for(var i=0;i=r.length||i>=t.length);++i)r[i+e]=t[i];return i}function N(t,r){return t instanceof r||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===r.name}function j(t){return t!=t}}).call(this,e({}).Buffer)},function(e){return r||t(r={exports:{},parent:e},r.exports),r.exports}),n={toByteArray:function(t){var r,e,n=a(t),i=n[0],u=n[1],f=new s(function(t,r,e){return 3*(r+e)/4-e}(0,i,u)),h=0,c=u>0?i-4:i;for(e=0;e>16&255,f[h++]=r>>8&255,f[h++]=255&r;return 2===u&&(r=o[t.charCodeAt(e)]<<2|o[t.charCodeAt(e+1)]>>4,f[h++]=255&r),1===u&&(r=o[t.charCodeAt(e)]<<10|o[t.charCodeAt(e+1)]<<4|o[t.charCodeAt(e+2)]>>2,f[h++]=r>>8&255,f[h++]=255&r),f},fromByteArray:function(t){for(var r,e=t.length,n=e%3,o=[],s=0,u=e-n;su?u:s+16383));return 1===n?(r=t[e-1],o.push(i[r>>2]+i[r<<4&63]+"==")):2===n&&(r=(t[e-2]<<8)+t[e-1],o.push(i[r>>10]+i[r>>4&63]+i[r<<2&63]+"=")),o.join("")}},i=[],o=[],s="undefined"!=typeof Uint8Array?Uint8Array:Array,u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",f=0,h=u.length;f0)throw new Error("Invalid string. Length must be a multiple of 4");var e=t.indexOf("=");return-1===e&&(e=r),[e,e===r?0:4-e%4]}function c(t,r,e){for(var n,o,s=[],u=r;u>18&63]+i[o>>12&63]+i[o>>6&63]+i[63&o]);return s.join("")}o["-".charCodeAt(0)]=62,o["_".charCodeAt(0)]=63;var l={read:function(t,r,e,n,i){var o,s,u=8*i-n-1,f=(1<>1,a=-7,c=e?i-1:0,l=e?-1:1,p=t[r+c];for(c+=l,o=p&(1<<-a)-1,p>>=-a,a+=u;a>0;o=256*o+t[r+c],c+=l,a-=8);for(s=o&(1<<-a)-1,o>>=-a,a+=n;a>0;s=256*s+t[r+c],c+=l,a-=8);if(0===o)o=1-h;else{if(o===f)return s?NaN:1/0*(p?-1:1);s+=Math.pow(2,n),o-=h}return(p?-1:1)*s*Math.pow(2,o-n)},write:function(t,r,e,n,i,o){var s,u,f,h=8*o-i-1,a=(1<>1,l=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:o-1,y=n?1:-1,g=r<0||0===r&&1/r<0?1:0;for(r=Math.abs(r),isNaN(r)||r===1/0?(u=isNaN(r)?1:0,s=a):(s=Math.floor(Math.log(r)/Math.LN2),r*(f=Math.pow(2,-s))<1&&(s--,f*=2),(r+=s+c>=1?l/f:l*Math.pow(2,1-c))*f>=2&&(s++,f/=2),s+c>=a?(u=0,s=a):s+c>=1?(u=(r*f-1)*Math.pow(2,i),s+=c):(u=r*Math.pow(2,c-1)*Math.pow(2,i),s=0));i>=8;t[e+p]=255&u,p+=y,u/=256,i-=8);for(s=s<0;t[e+p]=255&s,p+=y,s/=256,h-=8);t[e+p-y]|=128*g}},p={};(function(t){function r(){}p=class{constructor(t,{length:r=1/0,name:e="idbkv-chunk-store",batchInterval:n=10}={}){this._idbkvStore=new class{constructor(t,{batchInterval:r=10}={}){this.storeName="idb-kv",this.batchInterval=r,this.db=new Promise((r,e)=>{const n=indexedDB.open(t,1);n.onsuccess=()=>r(n.result),n.onerror=()=>{e(new Error(`error opening the indexedDB database named ${t}: ${n.error}`))},n.onupgradeneeded=()=>n.result.createObjectStore(this.storeName)}),this._actions=[],this._commitPromise=null}async get(t){const r=new Promise((r,e)=>{this._actions.push({type:"get",key:t,resolve:r,reject:e})});return await Promise.race([r,this._getOrStartCommit()]),r}async set(t,r){return this._actions.push({type:"set",key:t,value:r}),this._getOrStartCommit()}async delete(t){return this._actions.push({type:"delete",key:t}),this._getOrStartCommit()}async destroy(){const t=await this.db;t.close();const r=indexedDB.deleteDatabase(t.name);return this.db=Promise.reject(new Error("This idb-kv instance has been destroyed")),new Promise((t,e)=>{r.onsuccess=()=>t(),r.onerror=()=>e(r.error)})}_getOrStartCommit(){return this._commitPromise||(this._commitPromise=this._commit()),this._commitPromise}async _commit(){await new Promise(t=>setTimeout(t,this.batchInterval));const t=(await this.db).transaction(this.storeName,"readwrite"),r=t.objectStore(this.storeName);for(const e of this._actions)switch(e.type){case"get":{const t=r.get(e.key);t.onsuccess=()=>e.resolve(t.result),t.onerror=()=>e.reject(t.error);break}case"set":r.put(e.value,e.key);break;case"delete":r.delete(e.key)}return this._actions=[],this._commitPromise=null,new Promise((r,e)=>{t.oncomplete=()=>r(),t.onabort=t=>e(t.target.error),t.onerror=()=>{t.error&&e(t.error)}})}}(e,{batchInterval:n}),this.chunkLength=t,r!==1/0&&(this.lastChunkLength=r%this.chunkLength||this.chunkLength,this.lastChunkIndex=Math.ceil(r/this.chunkLength)-1)}put(t,e,n=r){if(t===this.lastChunkIndex){if(e.length!==this.lastChunkLength)return n(new Error("Last chunk's length must be "+this.lastChunkLength))}else if(e.length!==this.chunkLength)return n(new Error("Chunk length must be "+this.chunkLength));this._idbkvStore.set(t,e).then(n).catch(n)}get(r,e,n){if("function"==typeof e)return this.get(r,{},e);this._idbkvStore.get(r).then(r=>{if(void 0===r)return n(new Error("Index does not exist in storage"));const i=t.from(r),o=e&&e.offset||0,s=e&&e.length||i.length-o;n(null,i.slice(o,o+s))}).catch(n)}close(t=r){this._idbkvStore.db.then(r=>{r.close(),t()}).catch(t)}destroy(t=r){this._idbkvStore.destroy().then(t).catch(t)}}}).call(this,e({}).Buffer),function(t){t.window.IdbkvChunkStore=p}.call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})}(); \ No newline at end of file diff --git a/app/js/playerHandler.js b/app/js/playerHandler.js index ae869c2..93b7f6a 100644 --- a/app/js/playerHandler.js +++ b/app/js/playerHandler.js @@ -64,10 +64,54 @@ function cleanupVideo() { // cleans up objects, attemps to clear as much video c document.querySelector(".playlist").innerHTML = ''; bnext.removeAttribute("disabled") navNowPlaying.classList.add("d-none") - if ('mediaSession' in navigator) navigator.mediaSession.metadata = null + if ('mediaSession' in navigator) navigator.mediaSession.metadata = undefined } async function buildVideo(torrent, opts) { // sets video source and creates a bunch of other media stuff + //play wanted episode from opts, or the 1st episode, or 1st file [batches: plays wanted episode, single: plays the only episode, manually added: plays first or only file] + let selectedFile = videoFiles[0] + if (opts.file) { + selectedFile = opts.file + } else if (videoFiles.length > 1) { + //TODO play selected media too! + selectedFile = videoFiles.filter(async file => await anitomyscript(file.name).then(object => Number(object.episode_number) == opts.episode || 1))[0] || videoFiles[0] + } + video.src = `${scope}webtorrent/${torrent.infoHash}/${encodeURI(selectedFile.path)}` + video.load(); + //"predict" video FPS for subtitle renderer + playerData.fps = new Promise(resolve => { + if ('requestVideoFrameCallback' in HTMLVideoElement.prototype) { + let wasSeeked + video.onseeking = () => wasSeeked = true; + video.onplay = () => setTimeout(() => video.requestVideoFrameCallback((now, metadata) => { + let rawFPS = metadata.presentedFrames / metadata.mediaTime + console.log(rawFPS, metadata) + if (!wasSeeked) { + if (rawFPS >= 19 && rawFPS <= 26) { + resolve(23.976) + } else if (rawFPS > 26 && rawFPS <= 35) { + resolve(29.97) + } else if (rawFPS > 50 && rawFPS <= 70) { + resolve(59.94) + } else { + //smth went VERY wrong XD + resolve(23.976) + } + } else { + //video was seeked, cant predict fps + resolve(23.976) + } + video.onseeking = undefined + video.onplay = undefined + }), 3000) + } else { + // can't predict fps, API unsupported, assume 24fps + resolve(23.976) + } + + }) + playVideo(); + if (videoFiles.length > 1) { if (!torrent.store.store._idbkvStore) { torrent.files.forEach(file => file.deselect()); @@ -78,55 +122,12 @@ async function buildVideo(torrent, opts) { // sets video source and creates a bu for (let file of videoFiles) { let mediaInformation = await resolveFileMedia({ fileName: file.name, method: "SearchName" }) template = cardCreator(mediaInformation) - template.onclick = async () => { - addTorrent(torrent, { media: mediaInformation.media, episode: mediaInformation.parseObject.episode, file: file }) - store[mediaInformation.parseObject.anime_title] = await alRequest({ id: mediaInformation.media.id, method: "SearchIDSingle" }).then(res => res.data.Media) - // force updates entry data on play in case its outdated, needs to be made cleaner and somewhere else... - } + template.onclick = () => addTorrent(torrent, { media: mediaInformation.media, episode: mediaInformation.parseObject.episode, file: file }) frag.appendChild(template) } document.querySelector(".playlist").appendChild(frag) } - console.log(opts.file) - //play wanted episode from opts, or the 1st episode, or 1st file [batches: plays wanted episode, single: plays the only episode, manually added: plays first or only file] - let selectedFile = opts.file || videoFiles.filter(async file => await anitomyscript(file.name).then(object => Number(object.episode_number) == opts.episode || 1))[0] || videoFiles[0] - video.src = `${scope}webtorrent/${torrent.infoHash}/${encodeURI(selectedFile.path)}` - video.load(); - //"predict" video FPS for subtitle renderer - playerData.fps = new Promise(resolve => { - if ('requestVideoFrameCallback' in HTMLVideoElement.prototype) { - let wasSeeked - video.onseeking = () => wasSeeked = true; - video.onplay = () => setTimeout(() => { - video.requestVideoFrameCallback((now, metadata) => { - let rawFPS = metadata.presentedFrames / metadata.mediaTime - console.log(rawFPS, metadata) - if (!wasSeeked) { - if (rawFPS >= 19 && rawFPS <= 26) { - resolve(23.976) - } else if (rawFPS > 26 && rawFPS <= 35) { - resolve(29.97) - } else if (rawFPS > 50 && rawFPS <= 70) { - resolve(59.94) - } else { - //smth went VERY wrong XD - resolve(23.976) - } - } else { - //video was seeked, cant predict fps - resolve(23.976) - } - }) - video.onseeking = undefined - video.onplay = undefined - }, 3000) - } else { - // can't predict fps, API unsupported, assume 24fps - resolve(23.976) - } - }) - playVideo(); function processFile() { halfmoon.initStickyAlert({ content: `${selectedFile.name} has finished downloading. Now seeding.`, @@ -160,19 +161,23 @@ async function buildVideo(torrent, opts) { // sets video source and creates a bu } setTimeout(playerData.onProgress, 100) } - console.log(opts) setTimeout(playerData.onProgress, 100) - if (opts.media) { - playerData.nowPlaying = [opts.media, opts.episode] - navNowPlaying.classList.remove("d-none") - } else { // try to resolve name + + + if (opts.media && videoFiles.length == 1) { + // if this is a single file, then the media is most likely accurate, just update it! + playerData.nowPlaying = [await alRequest({ id: opts.media?.id, method: "SearchIDSingle" }).then(res => res.data.Media), opts.episode || 0] + // update store with entry, but dont really do anything with it + resolveFileMedia({ fileName: selectedFile.name, method: "SearchName" }) + } else { + // if this is a batch or single unresolved file, then resolve the single selected file, batches can include specials let mediaInformation = await resolveFileMedia({ fileName: selectedFile.name, method: "SearchName" }) - playerData.nowPlaying = [mediaInformation.media, mediaInformation.episode] - if (mediaInformation.media) navNowPlaying.classList.remove("d-none") + playerData.nowPlaying = [mediaInformation.media, mediaInformation.episode || 0] } let mediaMetadata // only set mediasession and other shit if the playerdata is parsed correctly - if (playerData.nowPlaying && playerData.nowPlaying[0] && playerData.nowPlaying[1]) { + if (playerData.nowPlaying[0]) { + navNowPlaying.classList.remove("d-none") mediaMetadata = new MediaMetadata({ title: playerData.nowPlaying[0].title.userPreferred, artist: `Episode ${Number(playerData.nowPlaying[1])}`, @@ -183,21 +188,23 @@ async function buildVideo(torrent, opts) { // sets video source and creates a bu type: 'image/jpg' }] }); - nowPlayingDisplay.innerHTML = `EP ${Number(playerData.nowPlaying[1])}` if (parseInt(playerData.nowPlaying[1]) >= playerData.nowPlaying[0].episodes) bnext.setAttribute("disabled", "") if (playerData.nowPlaying[0].streamingEpisodes.length >= Number(playerData.nowPlaying[1])) { let streamingEpisode = playerData.nowPlaying[0].streamingEpisodes.filter(episode => episodeRx.exec(episode.title) && episodeRx.exec(episode.title)[1] == Number(playerData.nowPlaying[1]))[0] - video.poster = streamingEpisode.thumbnail - document.title = `${playerData.nowPlaying[0].title.userPreferred} - EP ${Number(playerData.nowPlaying[1])} - ${episodeRx.exec(streamingEpisode.title)[2]} - Miru` - mediaMetadata.artist = `Episode ${Number(playerData.nowPlaying[1])} - ${episodeRx.exec(streamingEpisode.title)[2]}` - mediaMetadata.artwork = [{ - src: streamingEpisode.thumbnail, - sizes: '256x256', - type: 'image/jpg' - }] - nowPlayingDisplay.innerHTML = `EP ${Number(playerData.nowPlaying[1])} - ${episodeRx.exec(streamingEpisode.title)[2]}` - } else { - document.title = `${playerData.nowPlaying[0].title.userPreferred} - EP ${Number(playerData.nowPlaying[1])} - Miru` + if (streamingEpisode) { + video.poster = streamingEpisode.thumbnail + document.title = `${playerData.nowPlaying[0].title.userPreferred} - EP ${Number(playerData.nowPlaying[1])} - ${episodeRx.exec(streamingEpisode.title)[2]} - Miru` + mediaMetadata.artist = `Episode ${Number(playerData.nowPlaying[1])} - ${episodeRx.exec(streamingEpisode.title)[2]}` + mediaMetadata.artwork = [{ + src: streamingEpisode.thumbnail, + sizes: '256x256', + type: 'image/jpg' + }] + nowPlayingDisplay.innerHTML = `EP ${Number(playerData.nowPlaying[1])} - ${episodeRx.exec(streamingEpisode.title)[2]}` + } else { + document.title = `${playerData.nowPlaying[0].title.userPreferred} - EP ${Number(playerData.nowPlaying[1])} - Miru` + nowPlayingDisplay.innerHTML = `EP ${Number(playerData.nowPlaying[1])}` + } } } if ('mediaSession' in navigator && mediaMetadata) navigator.mediaSession.metadata = mediaMetadata diff --git a/app/js/torrentHandler.js b/app/js/torrentHandler.js index f06575f..210a8a2 100644 --- a/app/js/torrentHandler.js +++ b/app/js/torrentHandler.js @@ -73,11 +73,7 @@ function offlineDownload(torrentID, skipVerify) { } let mediaInformation = await resolveFileMedia({ fileName: torrent.name, method: "SearchName" }) template = cardCreator(mediaInformation) - template.onclick = async () => { - addTorrent(torrent, { media: mediaInformation.media, episode: mediaInformation.parseObject.episode }) - store[mediaInformation.parseObject.anime_title] = await alRequest({ id: mediaInformation.media?.id, method: "SearchIDSingle" }).then(res => res.data.Media) - // force updates entry data on play in case its outdated, needs to be made cleaner and somewhere else... - } + template.onclick = () => addTorrent(torrent, { media: mediaInformation.media, episode: mediaInformation.parseObject.episode }) document.querySelector(".downloads").appendChild(template) }) }