@sebbo2002/node-pyatv 9.0.3-develop.11 → 9.0.3-develop.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/check.cjs +2 -2
- package/dist/bin/check.cjs.map +1 -1
- package/dist/bin/check.js +1 -1
- package/dist/{chunk-P7VXRVDB.js → chunk-LK2FTHZN.js} +4 -4
- package/dist/chunk-LK2FTHZN.js.map +1 -0
- package/dist/lib/index.cjs +4 -4
- package/dist/lib/index.cjs.map +1 -1
- package/dist/lib/index.d.cts +2 -2
- package/dist/lib/index.d.ts +2 -2
- package/dist/lib/index.js +1 -1
- package/package.json +6 -6
- package/dist/chunk-P7VXRVDB.js.map +0 -1
package/dist/bin/check.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";var B=Object.create;var L=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var Y=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty;var Q=(s,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of H(e))!z.call(s,n)&&n!==t&&L(s,n,{get:()=>e[n],enumerable:!(i=q(e,n))||i.enumerable});return s};var X=(s,e,t)=>(t=s!=null?B(Y(s)):{},Q(e||!s||!s.__esModule?L(t,"default",{value:s,enumerable:!0}):t,s));var Z=()=>typeof document>"u"?new URL(`file:${__filename}`).href:document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"?document.currentScript.src:new URL("main.js",document.baseURI).href,y=Z();var J=require("fs"),I=require("path"),C=X(require("semver"),1),M=require("url");var T=class{get device(){return this.values.device}get key(){return this.values.key}get newValue(){return this.values.new}get oldValue(){return this.values.old}get value(){return this.values.new}values;constructor(e){this.values=Object.assign({},e,{key:e.key})}};var W=require("events");var U=require("child_process");var O=(o=>(o.idle="idle",o.loading="loading",o.paused="paused",o.playing="playing",o.seeking="seeking",o.stopped="stopped",o))(O||{});var R=(i=>(i.focued="focused",i.focused="focused",i.unfocused="unfocused",i))(R||{}),j=(l=>(l.down="down",l.home="home",l.homeHold="home_hold",l.left="left",l.menu="menu",l.next="next",l.pause="pause",l.play="play",l.playPause="play_pause",l.previous="previous",l.right="right",l.select="select",l.skipBackward="skip_backward",l.skipForward="skip_forward",l.stop="stop",l.suspend="suspend",l.topMenu="top_menu",l.turnOff="turn_off",l.turnOn="turn_on",l.up="up",l.volumeDown="volume_down",l.volumeUp="volume_up",l.wakeup="wakeup",l))(j||{});var
|
|
1
|
+
"use strict";var B=Object.create;var L=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var Y=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty;var Q=(s,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of H(e))!z.call(s,n)&&n!==t&&L(s,n,{get:()=>e[n],enumerable:!(i=q(e,n))||i.enumerable});return s};var X=(s,e,t)=>(t=s!=null?B(Y(s)):{},Q(e||!s||!s.__esModule?L(t,"default",{value:s,enumerable:!0}):t,s));var Z=()=>typeof document>"u"?new URL(`file:${__filename}`).href:document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"?document.currentScript.src:new URL("main.js",document.baseURI).href,y=Z();var J=require("fs"),I=require("path"),C=X(require("semver"),1),M=require("url");var T=class{get device(){return this.values.device}get key(){return this.values.key}get newValue(){return this.values.new}get oldValue(){return this.values.old}get value(){return this.values.new}values;constructor(e){this.values=Object.assign({},e,{key:e.key})}};var W=require("events");var U=require("child_process");var O=(o=>(o.idle="idle",o.loading="loading",o.paused="paused",o.playing="playing",o.seeking="seeking",o.stopped="stopped",o))(O||{});var R=(i=>(i.focued="focused",i.focused="focused",i.unfocused="unfocused",i))(R||{}),j=(l=>(l.down="down",l.home="home",l.homeHold="home_hold",l.left="left",l.menu="menu",l.next="next",l.pause="pause",l.play="play",l.playPause="play_pause",l.previous="previous",l.right="right",l.select="select",l.skipBackward="skip_backward",l.skipForward="skip_forward",l.stop="stop",l.suspend="suspend",l.topMenu="top_menu",l.turnOff="turn_off",l.turnOn="turn_on",l.up="up",l.volumeDown="volume_down",l.volumeUp="volume_up",l.wakeup="wakeup",l))(j||{});var E=(n=>(n.music="music",n.tv="tv",n.unknown="unknown",n.video="video",n))(E||{}),_=(t=>(t.off="off",t.on="on",t))(_||{});var k=(i=>(i.all="all",i.off="off",i.track="track",i))(k||{}),x=(i=>(i.albums="albums",i.off="off",i.songs="songs",i))(x||{});var D=[];function m(){let s="?";for(let e=0;e<1e3;e+=1)if(s=Math.round(Math.random()*(e+6)*36).toString(36).toUpperCase(),!D.includes(s)){D.push(s);break}return s}function G(s,e){return!!(Array.isArray(s)&&Array.isArray(e)&&JSON.stringify(s.sort((t,i)=>t.identifier<i.identifier?-1:1))===JSON.stringify(e.sort((t,i)=>t.identifier<i.identifier?-1:1)))}function p(s,e,t){if(t.debug){let i=typeof t.debug=="function"?t.debug:console.log,n=!process.env.NO_COLOR&&!t.noColors,r=[n?"\x1B[0m":"",n?"\x1B[90m":"","[node-pyatv][",n?"\x1B[37m":"",s,n?"\x1B[90m":"","] ",n?"\x1B[0m":"",e];i.apply(null,[r.join("")])}}function F(s,e,t,i){let n=K(e,i),r=typeof i.spawn=="function"?i.spawn:U.spawn;p(s,`${n} ${t.join(" ")}`,i);let o=r(n,t,{env:process.env}),a=h=>p(s,`stdout: ${String(h).trim()}`,i),d=h=>p(s,`stderr: ${String(h).trim()}`,i),u=h=>p(s,`error: ${String(h).trim()}`,i),b=h=>{p(s,`${n} exited with code: ${h}`,i),o.stdout&&o.stdout.off("data",a),o.stderr&&o.stderr.off("data",d),o.off("error",u),o.off("close",b)};return o.stdout&&o.stdout.on("data",a),o.stderr&&o.stderr.on("data",d),o.on("error",u),o.on("close",b),o}function K(s,e){return s==="atvremote"&&typeof e.atvremotePath=="string"?e.atvremotePath:s==="atvscript"&&typeof e.atvscriptPath=="string"?e.atvscriptPath:s}function g(s={}){let e=[];return s.hosts?e.push("-s",s.hosts.join(",")):s.host&&e.push("-s",s.host),s.id&&e.push("-i",s.id),s.protocol&&e.push("--protocol",s.protocol),s.dmapCredentials&&e.push("--dmap-credentials",s.dmapCredentials),s.mrpCredentials&&e.push("--mrp-credentials",s.mrpCredentials),s.airplayCredentials&&e.push("--airplay-credentials",s.airplayCredentials),s.companionCredentials&&e.push("--companion-credentials",s.companionCredentials),s.raopCredentials&&e.push("--raop-credentials",s.raopCredentials),e}function A(s,e,t){let i=r=>p(e,r,t),n={album:null,app:null,appId:null,artist:null,contentIdentifier:null,dateTime:null,deviceState:null,episodeNumber:null,focusState:null,genre:null,hash:null,iTunesStoreIdentifier:null,mediaType:null,outputDevices:null,position:null,powerState:null,repeat:null,seasonNumber:null,seriesName:null,shuffle:null,title:null,totalTime:null,volume:null};if(!s||typeof s!="object")return n;if(s.exception){let r="Got pyatv Error: "+s.exception;throw s.stacktrace&&(r+=`
|
|
2
2
|
|
|
3
3
|
pyatv Stacktrace:
|
|
4
|
-
`+s.stacktrace),new Error(r)}if(typeof s.datetime=="string"){let r=new Date(s.datetime);isNaN(r.getTime())?i(`Invalid datetime value ${s.datetime}, ignore attribute`):n.dateTime=r}else i(`No datetime value found in input (${JSON.stringify(s)})`);return f(s,n,"hash","hash",i),typeof s.media_type=="string"?Object.keys(
|
|
4
|
+
`+s.stacktrace),new Error(r)}if(typeof s.datetime=="string"){let r=new Date(s.datetime);isNaN(r.getTime())?i(`Invalid datetime value ${s.datetime}, ignore attribute`):n.dateTime=r}else i(`No datetime value found in input (${JSON.stringify(s)})`);return f(s,n,"hash","hash",i),typeof s.media_type=="string"?Object.keys(E).map(o=>String(o)).includes(s.media_type)?n.mediaType=E[s.media_type]:i(`Unsupported mediaType value ${s.media_type}, ignore attribute`):i(`No mediaType value found in input (${JSON.stringify(s)})`),typeof s.device_state=="string"?Object.keys(O).map(o=>String(o)).includes(s.device_state)?n.deviceState=O[s.device_state]:i(`Unsupported deviceState value ${s.device_state}, ignore attribute`):i(`No deviceState value found in input (${JSON.stringify(s)})`),f(s,n,"title","title",i),f(s,n,"artist","artist",i),f(s,n,"album","album",i),f(s,n,"genre","genre",i),N(s,n,"total_time","totalTime",i),N(s,n,"position","position",i),typeof s.shuffle=="string"?Object.keys(x).map(o=>String(o)).includes(s.shuffle)?n.shuffle=x[s.shuffle]:i(`Unsupported shuffle value ${s.shuffle}, ignore attribute`):i(`No shuffle value found in input (${JSON.stringify(s)})`),typeof s.repeat=="string"?Object.keys(k).map(o=>String(o)).includes(s.repeat)?n.repeat=k[s.repeat]:i(`Unsupported repeat value ${s.repeat}, ignore attribute`):i(`No repeat value found in input (${JSON.stringify(s)})`),f(s,n,"app","app",i),f(s,n,"app_id","appId",i),typeof s.power_state=="string"?Object.keys(_).map(o=>String(o)).includes(s.power_state)?n.powerState=_[s.power_state]:i(`Unsupported powerState value ${s.power_state}, ignore attribute`):i(`No powerState value found in input (${JSON.stringify(s)})`),N(s,n,"volume","volume",i),typeof s.focus_state=="string"?Object.keys(R).map(o=>String(o)).includes(s.focus_state)?n.focusState=R[s.focus_state]:i(`Unsupported focusState value ${s.focus_state}, ignore attribute`):i(`No focusState value found in input (${JSON.stringify(s)})`),Array.isArray(s.output_devices)&&(n.outputDevices=s.output_devices),f(s,n,"content_identifier","contentIdentifier",i),N(s,n,"itunes_store_identifier","iTunesStoreIdentifier",i),N(s,n,"episode_number","episodeNumber",i),N(s,n,"season_number","seasonNumber",i),f(s,n,"series_name","seriesName",i),n}function c(s){s&&D.includes(s)&&D.splice(D.indexOf(s),1)}async function P(s,e,t,i){let n={code:0,stderr:"",stdout:""};if(await new Promise((r,o)=>{let a=F(s,e,t,i),d=v=>n.stdout+=String(v).trim(),u=v=>n.stderr+=String(v).trim(),b=v=>o(v instanceof Error?v:new Error(String(v))),h=v=>{n.code=v,a.stdout&&a.stdout.off("data",d),a.stderr&&a.stderr.off("data",u),a.off("error",b),a.off("close",h),r(void 0)};a.stdout&&a.stdout.on("data",d),a.stderr&&a.stderr.on("data",u),a.on("error",b),a.on("close",h)}),n.stderr.length>0){let r=`Unable to execute request ${s}: ${n.stderr}`;throw p(s,r,i),new Error(r)}if(e==="atvscript")try{return i.allowMultipleResponses?n.stdout.split(`
|
|
5
5
|
`).filter(r=>r.trim().length>0).map(r=>JSON.parse(r)):JSON.parse(n.stdout)}catch(r){let o=`Unable to parse result ${s} json: ${r}`;throw p(s,o,i),new Error(o)}return n.stdout}function N(s,e,t,i,n){if(typeof s[t]=="number"){e[i]=s[t];return}n(`No ${i} value found in input (${JSON.stringify(s)})`)}function f(s,e,t,i,n){if(typeof s[t]=="string"){e[i]=s[t];return}n(`No ${i} value found in input (${JSON.stringify(s)})`)}var w=class extends W.EventEmitter{device;listenerState;options;pyatv;state;timeout;constructor(e,t,i){super(),this.state=e,this.device=t,this.options=Object.assign({},i),this.listenerState=0}addListener(e,t){return super.addListener(e,t),this.checkListener(),this}applyStateAndEmitEvents(e){let t=Object.keys(this.state);t=t.filter(i=>!["focusState","outputDevices","powerState","volume"].includes(i)),"powerState"in e&&e.powerState&&(t=["powerState"]),"focusState"in e&&e.focusState&&(t=["focusState"]),"outputDevices"in e&&e.outputDevices&&(t=["outputDevices"]),"volume"in e&&e.volume!==null&&(t=["volume"]),Object.entries(e).find(([i,n])=>!["dateTime","result"].includes(i)&&n!==null)&&t.forEach(i=>{let n=this.state[i],r=e[i];if(n===void 0||r===void 0||n===r||i==="outputDevices"&&G(n,r))return;let o=new T({device:this.device,key:i,new:r,old:n});this.state[i]=e[i];try{this.emit("update:"+i,o),this.emit("update",o)}catch(a){this.emit("error",a)}})}listenerCount(e){return e!==void 0?super.listenerCount(e):this.eventNames().map(t=>this.listenerCount(t)).reduce((t,i)=>t+i,0)}off(e,t){return super.off(e,t),this.checkListener(),this}on(e,t){return super.on(e,t),this.checkListener(),this}once(e,t){return super.once(e,i=>{t(i),setTimeout(()=>this.checkListener(),0)}),this.checkListener(),this}prependListener(e,t){return super.prependListener(e,t),this.checkListener(),this}removeAllListeners(e){return super.removeAllListeners(e),this.checkListener(),this}removeListener(e,t){return super.removeListener(e,t),this.checkListener(),this}async stopListening(e){if(!(this.listenerState!==1&&this.listenerState!==2)){if(this.listenerState=3,this.pyatv===void 0)throw new Error("Unable to stop listening due to internal error: state is stopping, but there's no child process. This should never happen, please report this.");this.pyatv.stdin&&(p(e,"Pressing enter to close atvscript\u2026",this.options),this.pyatv.stdin.write(`
|
|
6
6
|
`),await new Promise(t=>this.timeout=setTimeout(t,250))),this.listenerState===3&&this.pyatv&&this.pyatv.kill(),this.listenerState=0}}applyPushUpdate(e,t){try{let i=A(e,t,this.options);this.applyStateAndEmitEvents(i)}catch(i){this.emit("error",i)}}checkListener(){if(this.listenerState===0&&this.listenerCount()===0&&this.timeout)clearTimeout(this.timeout),this.timeout=void 0;else if(this.listenerState===0&&this.listenerCount()>0){let e=m();p(e,`Start listeing to events from device ${this.options.name}`,this.options),this.startListening(e),c(e)}else if([2,1].includes(this.listenerState)&&this.listenerCount()===0){let e=m();p(e,`Stop listening to events from device ${this.options.name}`,this.options),this.stopListening(e).catch(t=>p(e,`Unable to stop listeing: ${t}`,this.options)).finally(()=>c(e))}}parsePushUpdate(e,t){let i;try{i=JSON.parse(t)}catch(n){let r=`Unable to parse stdout json: ${n}`;p(e,r,this.options),this.emit("error",new Error(r));return}this.applyPushUpdate(i,e),this.listenerState===1&&(this.listenerState=2,this.checkListener())}startListening(e){if(this.listenerState!==0)return;this.listenerState=1;let t=new Date().getTime(),i=g(this.options);if(this.pyatv=F(e,"atvscript",[...i,"push_updates"],this.options),!this.pyatv)throw new Error("Unable to start listener: Unable to start atvscript");let n=d=>{p(e,`Got error from child process: ${d}`,this.options),this.emit("error",d)},r=d=>{let u=new Error(`Got stderr output from pyatv: ${d}`);p(e,d.toString(),this.options),this.emit("error",u)},o=d=>{String(d).split(`
|
|
7
7
|
`).map(u=>u.trim()).filter(Boolean).forEach(u=>{p(e,`> ${u}`,this.options),this.parsePushUpdate(e,u)})},a=d=>{this.pyatv!==void 0&&(this.listenerState=0,p(e,`Listening with atvscript exited with code ${d}`,this.options),this.timeout!==void 0&&(clearTimeout(this.timeout),this.timeout=void 0),this.pyatv.stdout&&this.pyatv.stdout.off("data",o),this.pyatv.stderr&&this.pyatv.stderr.off("data",r),this.pyatv.off("error",n),this.pyatv.off("close",a),this.listenerCount()>0&&new Date().getTime()-t<3e4?(p(e,`Wait 15s and restart listeing to events from device ${this.options.name}`,this.options),this.timeout=setTimeout(()=>{this.checkListener()},15e3)):this.listenerCount()>0&&(p(e,`Restart listeing to events from device ${this.options.name}`,this.options),this.checkListener()),c(e))};this.pyatv.on("error",n),this.pyatv.on("close",a),this.pyatv.stdout&&this.pyatv.stdout.on("data",o),this.pyatv.stderr&&this.pyatv.stderr.on("data",r)}};var V=class{get allIDs(){return this.options.allIDs}get debug(){return this.options.debug}set debug(e){typeof e=="function"?this.options.debug=e:this.options.debug=!!e||void 0}get host(){return this.options.host}get id(){return this.options.id}get mac(){return this.options.mac}get model(){return this.options.model}get modelName(){return this.options.modelName}get name(){return this.options.name}get os(){return this.options.os}get protocol(){return this.options.protocol}get services(){return this.options.services}get version(){return this.options.version}events;options;state;constructor(e){if(!e.host&&!e.id&&!e.mac)throw new Error("Either host, id or mac must be set!");this.options=Object.assign({},e),this.state=A({},"",{}),this.events=new w(this.state,this,this.options)}addListener(e,t){return this.events.addListener(e,t),this}clearState(){this.applyState(A({},"",{}))}async down(){await this._pressKeyWithScript("down")}emit(e,t){return this.events.emit(e,t)}eventNames(){return this.events.eventNames()}async getAlbum(e={}){return(await this.getState(e)).album}async getApp(e={}){return(await this.getState(e)).app}async getAppId(e={}){return(await this.getState(e)).appId}async getArtist(e={}){return(await this.getState(e)).artist}async getContentIdentifier(e={}){return this.getState(e).then(t=>t.contentIdentifier)}async getDateTime(e={}){return(await this.getState(e)).dateTime}async getDeviceState(e={}){return(await this.getState(e)).deviceState}async getEpisodeNumber(e={}){return this.getState(e).then(t=>t.episodeNumber)}async getFocusState(e={}){return this.getState(e).then(t=>t.focusState)}async getGenre(e={}){return(await this.getState(e)).genre}async getHash(e={}){return(await this.getState(e)).hash}async getITunesStoreIdentifier(e={}){return this.getState(e).then(t=>t.iTunesStoreIdentifier)}async getiTunesStoreIdentifier(e={}){return this.getITunesStoreIdentifier(e)}getMaxListeners(){return this.events.getMaxListeners()}async getMediaType(e={}){return(await this.getState(e)).mediaType}async getOutputDevices(e={}){return this.getState(e).then(t=>t.outputDevices)}async getPosition(e={}){return(await this.getState(e)).position}async getPowerState(e={}){return this.getState(e).then(t=>t.powerState)}async getRepeat(e={}){return(await this.getState(e)).repeat}async getSeasonNumber(e={}){return this.getState(e).then(t=>t.seasonNumber)}async getSeriesName(e={}){return this.getState(e).then(t=>t.seriesName)}async getShuffle(e={}){return(await this.getState(e)).shuffle}async getState(e={}){if(this.state?.dateTime&&new Date().getTime()-this.state.dateTime.getTime()<(e.maxAge||5e3)){let i=null;return this.state.position&&this.state.dateTime&&(i=Math.round(this.state.position+(new Date().getTime()-this.state.dateTime.getTime())/1e3)),Object.assign({},this.state,{position:i})}let t=m();try{let i=g(this.options),n=await P(t,"atvscript",[...i,"playing"],this.options),r=A(n,t,this.options);return this.applyState(r),r}finally{c(t)}}async getTitle(e={}){return(await this.getState(e)).title}async getTotalTime(e={}){return(await this.getState(e)).totalTime}async getVolume(e={}){return this.getState(e).then(t=>t.volume)}async home(){await this._pressKeyWithScript("home")}async homeHold(){await this._pressKeyWithScript("home_hold")}async launchApp(e){await this._pressKeyWithRemote("launch_app="+e)}async left(){await this._pressKeyWithScript("left")}async listApps(){let e=m(),t=g(this.options),i=await P(e,"atvremote",[...t,"app_list"],this.options);if(typeof i!="string"||!i.startsWith("App: "))throw new Error("Unexpected atvremote response: "+i);c(e);let n=/(.+) \(([^)]+)\)$/i;return i.substring(5).split(", App: ").map(o=>{let a=o.match(n);if(a!==null)return{id:a[2],launch:()=>this.launchApp(a[2]),name:a[1]}}).filter(Boolean)}listenerCount(e){return this.events.listenerCount(e)}listeners(e){return this.events.listeners(e)}async menu(){await this._pressKeyWithScript("menu")}async next(){await this._pressKeyWithScript("next")}off(e,t){return this.events.off(e,t),this}on(e,t){return this.events.on(e,t),this}once(e,t){return this.events.once(e,t),this}async pause(){await this._pressKeyWithScript("pause")}async play(){await this._pressKeyWithScript("play")}async playPause(){await this._pressKeyWithScript("play_pause")}prependListener(e,t){return this.events.prependListener(e,t),this}prependOnceListener(e,t){return this.events.prependOnceListener(e,t),this}async pressKey(e){let t=Object.entries(j).find(([n])=>e===n);if(!t)throw new Error(`Unsupported key value ${e}!`);let i=t[1];["turnOff","turnOn"].includes(e)?await this._pressKeyWithRemote(i):await this._pressKeyWithScript(i)}async previous(){await this._pressKeyWithScript("previous")}rawListeners(e){return this.events.rawListeners(e)}removeAllListeners(e){return this.events.removeAllListeners(e),this}removeListener(e,t){return this.events.removeListener(e,t),this}async right(){await this._pressKeyWithScript("right")}async select(){await this._pressKeyWithScript("select")}setMaxListeners(e){return this.events.setMaxListeners(e),this}async skipBackward(){await this._pressKeyWithScript("skip_backward")}async skipForward(){await this._pressKeyWithScript("skip_forward")}async stop(){await this._pressKeyWithScript("stop")}async suspend(){await this._pressKeyWithScript("suspend")}toJSON(){return{host:this.host,id:this.id,mac:this.mac,name:this.name,protocol:this.protocol}}async topMenu(){await this._pressKeyWithScript("top_menu")}toString(){return`NodePyATVDevice(${this.name}, ${this.host})`}async turnOff(){await this._pressKeyWithRemote("turn_off")}async turnOn(){await this._pressKeyWithRemote("turn_on")}async up(){await this._pressKeyWithScript("up")}async volumeDown(){await this._pressKeyWithScript("volume_down")}async volumeUp(){await this._pressKeyWithScript("volume_up")}async wakeup(){await this._pressKeyWithScript("wakeup")}async _pressKeyWithRemote(e){let t=m(),i=g(this.options);await P(t,"atvremote",[...i,e],this.options),c(t)}async _pressKeyWithScript(e){let t=m(),i=g(this.options),n=await P(t,"atvscript",[...i,e],this.options);if(typeof n!="object"||n.result!=="success")throw new Error(`Unable to parse pyatv response: ${JSON.stringify(n,null," ")}`);c(t)}applyState(e){this.events.applyStateAndEmitEvents(e)}};var S=class s{options={};constructor(e={}){this.options=Object.assign({},e)}static async check(e={}){let t=await this.version(e);if(!t.pyatv)throw new Error("Unable to find pyatv. Is it installed?");if(C.default.lt(t.pyatv,"0.6.0"))throw new Error("Found pyatv, but unforunately it's too old. Please update pyatv.");try{await this.find(e)}catch(i){throw new Error(`Unable to scan for devices: ${String(i).replace("Error: ","")}`)}}static device(e){return new V(e)}static async find(e={},t){let i=m(),n=g(e),r=[],o=[],a=await P(i,"atvscript",[...n,"scan"],{...e||{},allowMultipleResponses:!0});for(let d of a)if(typeof d=="object"&&"result"in d&&d.result==="failure")o.push(d);else if(typeof d=="object"&&"result"in d&&d.result==="success"&&Array.isArray(d.devices))r.push(...d.devices.map(u=>this.device(Object.assign({},e,{allIDs:u.all_identifiers,host:u.address,id:u.identifier,mac:u.device_info?.mac||void 0,model:u.device_info?.model,modelName:u.device_info?.model_str,name:u.name,os:u.device_info?.operating_system,services:u.services,version:u.device_info?.version}))));else throw new Error(`Unable to parse pyatv response: ${JSON.stringify(d,null," ")}`);if(c(i),t)return{devices:r,errors:o};if(!r.length&&o.length)throw new Error(`Unable to find any devices, but received ${o.length} error${o.length!==1?"s":""}: ${JSON.stringify(o,null," ")}`);return r}static async version(e={}){let t=m(),i=null,n=null;try{i=await P(t,"atvremote",["--version"],e)}catch(r){p(t,`Unable to get pyatv version due to ${r}`,e)}i&&i.substr(0,10)==="atvremote "&&(i=i.substr(10)),C.default.valid(i)||(p(t,`String "${i}" is not a valid pyatv version, set it to null`,e),i=null);try{let r=(0,I.join)((0,I.dirname)((0,M.fileURLToPath)(y)),"..","..","package.json");n=JSON.parse(await J.promises.readFile(r,"utf8"))?.version||null}catch(r){p(t,`Unable to get module version due to ${r}`,e)}return n&&!C.default.valid(n)&&(p(t,`String "${n}" is not a valid module version, set it to null`,e),n=null),c(t),{module:n,pyatv:i}}async check(e={}){return s.check(Object.assign({},this.options,e))}device(e){return s.device(Object.assign({},this.options,e))}async find(e={}){return s.find(Object.assign({},this.options,e))}async version(e={}){return s.version(Object.assign({},this.options,e))}};(async()=>{try{await S.check(),console.log(""),console.log("\u2714 node-pyatv seems to be ready to use!"),console.log(" Thank you and have a great day. Or night. Whatever."),console.log("")}catch(s){console.log(""),console.log("#".repeat(60)),console.log("#"+" ".repeat(58)+"#"),console.log("# \u26A0 Warning: node-pyatv is not ready to be used!"+" ".repeat(10)+"#"),console.log("#"+" ".repeat(58)+"#"),console.log("# To use the JavaScript module, pyatv >= 0.6.0 must be #"),console.log("# installed. Unfortunately this could not be found. During #"),console.log("# the check following error message was reported: #"),console.log("#"+" ".repeat(58)+"#"),console.log(String(s).replace("Error: ","").replace(/(.{1,54})/g,`$1
|