From 474f941aa76950e829bfe0afa1d2b189a4263c81 Mon Sep 17 00:00:00 2001 From: Jon Kristian Nilsen Date: Thu, 7 Mar 2024 23:47:43 +0100 Subject: [PATCH] Added ability to load images from external source. --- README.md | 1 + dist/mediatracker-card.js | 22 ++++++++++++++++------ package.json | 2 +- src/localize/languages/en.json | 1 + src/localize/languages/nb.json | 1 + src/mediatracker-card-editor.ts | 8 ++++++++ src/templates/event-backdrop.ts | 10 +++++++++- src/templates/event-poster.ts | 10 +++++++++- src/templates/events.ts | 2 ++ src/types.ts | 1 + 10 files changed, 49 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index cbd7eee..30da011 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ Media Tracker Card can be installed through [HACS][hacs] (Home Assistant Communi | entities | `list(required)` | A list of entity IDs or entity objects, see below. | | number_of_days | `integer(required)` | How many days ahead you want to fetch. | | constrict_height | `boolean` | Sets a predetermined card height and adds an inline scroll. | +| external_media | `boolean` | Fetches media/images from an external source. | | refresh_interval | `integer(required)` | How often the calendar should refresh. | | show_description | `boolean` | Show calendar entry description if returned from `mediatracker-ha`. | | human_readable_countdown | `boolean` | Show human readable countdown next to day name. | diff --git a/dist/mediatracker-card.js b/dist/mediatracker-card.js index 85d5cb8..72486ee 100644 --- a/dist/mediatracker-card.js +++ b/dist/mediatracker-card.js @@ -7,7 +7,7 @@ var e=function(t,i){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Arr ${t.audible?U`Audible`:""} ${t.igdb?U`IGDB`:""} ${t.tmdb?U`TMDB`:""} - `:U``}var Me={},Fe={get exports(){return Me},set exports(e){Me=e}};Fe.exports=function(e,t,i){i.updateLocale=function(e,t){var n=i.Ls[e];if(n)return(t?Object.keys(t):[]).forEach((function(e){n[e]=t[e]})),n}};var Ne=Me,Le={version:"Version",invalid_configuration:"Invalid configuration",show_warning:"Show warning"},Pe={name:"Name",title:"Title",refresh_interval:"Refresh Interval",number_of_days:"Number of Days",constrict_height:"Constrict Card Height",human_readable_countdown:"Human Readable Countdown",show_rating:"Show Rating",style:{title:"Select style ...",backdrop:"Backdrop",poster:"Poster",plain:"Plain"},source_links:{title:"Source Links",primary:"Primary",all:"Show all"},description:{title:"Include Description",today:"Today",week:"1 Week",all:"Show for All"}},Be={today:"Today",rating:"Rating",studio_link:"Visit Studio"},He={common:Le,editor:Pe,card:Be},ze={version:"Versjon",invalid_configuration:"Ugyldig oppsett",show_warning:"Vis advarsel"},Ue={name:"Navn",title:"Tittel",refresh_interval:"Oppdateringsintervall",number_of_days:"Antall dager",constrict_height:"Tving korthøyde",human_readable_countdown:"Nedtelling som setning",show_rating:"Vis vurdering",style:{title:"Velg stil ...",backdrop:"Bakgrunnsgrafikk",poster:"Poster",plain:"Vanlig"},source_links:{title:"Kildelenker",primary:"Primær",all:"Vis alle"},description:{title:"Inkluder beskrivelse",today:"I dag",week:"1 uke",all:"Vis for alle"}},Ve={today:"I dag",rating:"Vurdering",studio_link:"Besøk studio"},Ye={common:ze,editor:Ue,card:Ve};const je={en:Object.freeze({__proto__:null,card:Be,common:Le,default:He,editor:Pe}),nb:Object.freeze({__proto__:null,card:Ve,common:ze,default:Ye,editor:Ue})};function We(e,t){try{return e.split(".").reduce(((e,t)=>e[t]),je[t])}catch(e){return}}function Ge(e){return function(t){var i;let n=We(t,null!==(i=null==e?void 0:e.locale.language)&&void 0!==i?i:"en");return n||(n=We(t,"en")),null!=n?n:t}}xe.extend(Ne),xe.extend(Oe);let Xe=class extends se{render(){if(!this.event)return U``;const e=JSON.parse(this.event.location),t=Ge(this.hass);let i=!1;return"week"==this.description&&xe(this.event.start)<=xe().add(7,"day")&&(i=!0),"today"==this.description&&xe(this.event.start).isToday()&&(i=!0),U` + `:U``}var Me={},Fe={get exports(){return Me},set exports(e){Me=e}};Fe.exports=function(e,t,i){i.updateLocale=function(e,t){var n=i.Ls[e];if(n)return(t?Object.keys(t):[]).forEach((function(e){n[e]=t[e]})),n}};var Ne=Me,Le={version:"Version",invalid_configuration:"Invalid configuration",show_warning:"Show warning"},Pe={name:"Name",title:"Title",refresh_interval:"Refresh Interval",number_of_days:"Number of Days",constrict_height:"Constrict Card Height",external_media:"Fetch External Media",human_readable_countdown:"Human Readable Countdown",show_rating:"Show Rating",style:{title:"Select style ...",backdrop:"Backdrop",poster:"Poster",plain:"Plain"},source_links:{title:"Source Links",primary:"Primary",all:"Show all"},description:{title:"Include Description",today:"Today",week:"1 Week",all:"Show for All"}},Be={today:"Today",rating:"Rating",studio_link:"Visit Studio"},He={common:Le,editor:Pe,card:Be},ze={version:"Versjon",invalid_configuration:"Ugyldig oppsett",show_warning:"Vis advarsel"},Ue={name:"Navn",title:"Tittel",refresh_interval:"Oppdateringsintervall",number_of_days:"Antall dager",constrict_height:"Tving korthøyde",external_media:"Hent media eksternt",human_readable_countdown:"Nedtelling som setning",show_rating:"Vis vurdering",style:{title:"Velg stil ...",backdrop:"Bakgrunnsgrafikk",poster:"Poster",plain:"Vanlig"},source_links:{title:"Kildelenker",primary:"Primær",all:"Vis alle"},description:{title:"Inkluder beskrivelse",today:"I dag",week:"1 uke",all:"Vis for alle"}},Ve={today:"I dag",rating:"Vurdering",studio_link:"Besøk studio"},Ye={common:ze,editor:Ue,card:Ve};const je={en:Object.freeze({__proto__:null,card:Be,common:Le,default:He,editor:Pe}),nb:Object.freeze({__proto__:null,card:Ve,common:ze,default:Ye,editor:Ue})};function We(e,t){try{return e.split(".").reduce(((e,t)=>e[t]),je[t])}catch(e){return}}function Ge(e){return function(t){var i;let n=We(t,null!==(i=null==e?void 0:e.locale.language)&&void 0!==i?i:"en");return n||(n=We(t,"en")),null!=n?n:t}}xe.extend(Ne),xe.extend(Oe);let Xe=class extends se{render(){if(!this.event)return U``;const e=JSON.parse(this.event.location),t=Ge(this.hass);let i=!1;return"week"==this.description&&xe(this.event.start)<=xe().add(7,"day")&&(i=!0),"today"==this.description&&xe(this.event.start).isToday()&&(i=!0),U`
@@ -94,8 +94,8 @@ var e=function(t,i){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Arr a { color: var(--mt-link-color); } -`;xe.extend(Ne),xe.extend(Oe);let Ke=class extends se{render(){if(!this.event)return U``;const e=JSON.parse(this.event.location),t=Ge(this.hass);let i=!1;return"week"==this.description&&xe(this.event.start)<=xe().add(7,"day")&&(i=!0),"today"==this.description&&xe(this.event.start).isToday()&&(i=!0),U` -
+`;xe.extend(Ne),xe.extend(Oe);let Ke=class extends se{render(){if(!this.event)return U``;const e=JSON.parse(this.event.location),t=Ge(this.hass);let i=!1;"week"==this.description&&xe(this.event.start)<=xe().add(7,"day")&&(i=!0),"today"==this.description&&xe(this.event.start).isToday()&&(i=!0);let n=`//${e.host}${e.backdrop}?token=${e.token}`;return this.external_media&&e.poster_external&&(n=e.backdrop_external.replace(/\/original\//,"/w500/")),U` +
@@ -176,10 +176,10 @@ var e=function(t,i){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Arr color: var(--secondary-text-color); max-width: 600px; } - `]}};n([pe()],Ke.prototype,"hass",void 0),n([pe()],Ke.prototype,"event",void 0),n([pe()],Ke.prototype,"rating",void 0),n([pe()],Ke.prototype,"dark_mode",void 0),n([pe()],Ke.prototype,"description",void 0),n([pe()],Ke.prototype,"source_links",void 0),Ke=n([ce("mediatracker-event-backdrop")],Ke),xe.extend(Ne),xe.extend(Oe);let Ze=class extends se{render(){if(!this.event)return U``;const e=JSON.parse(this.event.location),t=Ge(this.hass);let i=!1;return"week"==this.description&&xe(this.event.start)<=xe().add(7,"day")&&(i=!0),"today"==this.description&&xe(this.event.start).isToday()&&(i=!0),U` + `]}};n([pe()],Ke.prototype,"hass",void 0),n([pe()],Ke.prototype,"event",void 0),n([pe()],Ke.prototype,"rating",void 0),n([pe()],Ke.prototype,"dark_mode",void 0),n([pe()],Ke.prototype,"description",void 0),n([pe()],Ke.prototype,"source_links",void 0),n([pe()],Ke.prototype,"external_media",void 0),Ke=n([ce("mediatracker-event-backdrop")],Ke),xe.extend(Ne),xe.extend(Oe);let Ze=class extends se{render(){if(!this.event)return U``;const e=JSON.parse(this.event.location),t=Ge(this.hass);let i=!1;"week"==this.description&&xe(this.event.start)<=xe().add(7,"day")&&(i=!0),"today"==this.description&&xe(this.event.start).isToday()&&(i=!0);let n=`//${e.host}${e.poster}?size=small&token=${e.token}`;return this.external_media&&e.poster_external&&(n=e.poster_external.replace(/\/original\//,"/w200/")),U`
- +
@@ -268,7 +268,7 @@ var e=function(t,i){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Arr color: var(--light-primary-color); max-width: 600px; } - `}};n([pe()],Ze.prototype,"hass",void 0),n([pe()],Ze.prototype,"event",void 0),n([pe()],Ze.prototype,"rating",void 0),n([pe()],Ze.prototype,"description",void 0),n([pe()],Ze.prototype,"source_links",void 0),Ze=n([ce("mediatracker-event-poster")],Ze);var Qe={},Je={get exports(){return Qe},set exports(e){Qe=e}};Je.exports=function(e,t,i){t.prototype.isToday=function(){var e="YYYY-MM-DD",t=i();return this.format(e)===t.format(e)}};var et=Qe;xe.extend(Ne),xe.extend(Oe),xe.extend(et);let tt=class extends se{render(){if(!this.events)return U``;const e=this.hass.themes.darkMode,t=Ge(this.hass);return U` + `}};n([pe()],Ze.prototype,"hass",void 0),n([pe()],Ze.prototype,"event",void 0),n([pe()],Ze.prototype,"rating",void 0),n([pe()],Ze.prototype,"description",void 0),n([pe()],Ze.prototype,"source_links",void 0),n([pe()],Ze.prototype,"external_media",void 0),Ze=n([ce("mediatracker-event-poster")],Ze);var Qe={},Je={get exports(){return Qe},set exports(e){Qe=e}};Je.exports=function(e,t,i){t.prototype.isToday=function(){var e="YYYY-MM-DD",t=i();return this.format(e)===t.format(e)}};var et=Qe;xe.extend(Ne),xe.extend(Oe),xe.extend(et);let tt=class extends se{render(){if(!this.events)return U``;const e=this.hass.themes.darkMode,t=Ge(this.hass);return U`
${xe(this.date).isToday()?U`

${t("card.today")}

@@ -291,6 +291,7 @@ var e=function(t,i){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Arr .rating="${this.config.show_rating}" .description="${this.config.description}" .source_links="${this.config.source_links}" + .external_media="${this.config.external_media}" > `))}
@@ -303,6 +304,7 @@ var e=function(t,i){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Arr .rating="${this.config.show_rating}" .description="${this.config.description}" .source_links="${this.config.source_links}" + .external_media="${this.config.external_media}" > `))}
@@ -773,6 +775,14 @@ var e=function(t,i){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Arr .configValue="${"constrict_height"}" > + + + +
diff --git a/package.json b/package.json index dee2a0e..7b2b88c 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mediatracker-card", - "version": "0.1.0", + "version": "0.1.1", "description": "This card is made to work with the Media Tracker custom component.", "keywords": [ "home-assistant", diff --git a/src/localize/languages/en.json b/src/localize/languages/en.json index aecf648..9e358b0 100644 --- a/src/localize/languages/en.json +++ b/src/localize/languages/en.json @@ -10,6 +10,7 @@ "refresh_interval": "Refresh Interval", "number_of_days": "Number of Days", "constrict_height": "Constrict Card Height", + "external_media": "Fetch External Media", "human_readable_countdown": "Human Readable Countdown", "show_rating": "Show Rating", "style": { diff --git a/src/localize/languages/nb.json b/src/localize/languages/nb.json index 8cc5b50..3a5dbf6 100644 --- a/src/localize/languages/nb.json +++ b/src/localize/languages/nb.json @@ -10,6 +10,7 @@ "refresh_interval": "Oppdateringsintervall", "number_of_days": "Antall dager", "constrict_height": "Tving korthøyde", + "external_media": "Hent media eksternt", "human_readable_countdown": "Nedtelling som setning", "show_rating": "Vis vurdering", "style": { diff --git a/src/mediatracker-card-editor.ts b/src/mediatracker-card-editor.ts index df1e381..d8efb56 100644 --- a/src/mediatracker-card-editor.ts +++ b/src/mediatracker-card-editor.ts @@ -208,6 +208,14 @@ export class MediaTrackerCardEditor .configValue="${"constrict_height"}" > + + + +
diff --git a/src/templates/event-backdrop.ts b/src/templates/event-backdrop.ts index b1280c5..0fddc55 100644 --- a/src/templates/event-backdrop.ts +++ b/src/templates/event-backdrop.ts @@ -18,6 +18,7 @@ export class MediaTrackerCardEvent extends LitElement { @property() dark_mode; @property() description; @property() source_links; + @property() external_media; protected render(): TemplateResult { if (!this.event) { @@ -35,8 +36,15 @@ export class MediaTrackerCardEvent extends LitElement { showDescription = true; } + let backdropUrl = `//${data.host}${data.backdrop}?token=${data.token}`; + + // Check if config has external_media boolean set to true. + if(this.external_media && data.poster_external) { + backdropUrl = data.backdrop_external.replace(/\/original\//, "/w500/"); + } + return html` -
+
diff --git a/src/templates/event-poster.ts b/src/templates/event-poster.ts index dcc5feb..a6512c7 100644 --- a/src/templates/event-poster.ts +++ b/src/templates/event-poster.ts @@ -16,6 +16,7 @@ export class MediaTrackerCardEvent extends LitElement { @property() rating; @property() description; @property() source_links; + @property() external_media; protected render(): TemplateResult { if (!this.event) { @@ -33,10 +34,17 @@ export class MediaTrackerCardEvent extends LitElement { showDescription = true; } + let posterUrl = `//${data.host}${data.poster}?size=small&token=${data.token}`; + + // Check if config has external_media boolean set to true. + if(this.external_media && data.poster_external) { + posterUrl = data.poster_external.replace(/\/original\//, "/w200/"); + } + return html`
- +
diff --git a/src/templates/events.ts b/src/templates/events.ts index a989cec..f9c2bd0 100644 --- a/src/templates/events.ts +++ b/src/templates/events.ts @@ -53,6 +53,7 @@ export class MediaTrackerCardEvents extends LitElement { .rating="${this.config.show_rating}" .description="${this.config.description}" .source_links="${this.config.source_links}" + .external_media="${this.config.external_media}" > `)}
@@ -66,6 +67,7 @@ export class MediaTrackerCardEvents extends LitElement { .rating="${this.config.show_rating}" .description="${this.config.description}" .source_links="${this.config.source_links}" + .external_media="${this.config.external_media}" > `)}
diff --git a/src/types.ts b/src/types.ts index 87c5590..4fb268a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -17,6 +17,7 @@ export interface MediaTrackerCardConfig extends LovelaceCardConfig { source_links: string; show_rating: boolean; constrict_height: boolean; + external_media: boolean; human_readable_countdown: boolean; show_warning?: boolean; show_error?: boolean;