@krx3d/tizentube2 1.31.590 → 1.31.600

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@krx3d/tizentube2",
3
3
  "appName": "TizenTube",
4
- "version": "1.31.590",
4
+ "version": "1.31.600",
5
5
  "description": "TizenTube is an ad-free and sponsor-free solution for your favourite streaming website on your Tizen (Samsung) TVs.",
6
6
  "packageType": "mods",
7
7
  "websiteURL": "https://youtube.com/tv?additionalDataUrl=http%3A%2F%2Flocalhost%3A8085%2Fdial%2Fapps%2FYouTube",
@@ -21,6 +21,12 @@ var fs = require('fs');
21
21
  var path = require('path');
22
22
 
23
23
  var PREVIEW_FILE = 'tt-home-bar-preview.json';
24
+ // When this last published and what. Samsung takes one setPreviewData every
25
+ // ten minutes and drops the rest without an error, so a repeat of the same row
26
+ // is skipped and a changed one waits; StandaloneService starts this service
27
+ // again once the ten minutes are up.
28
+ var STATE_FILE = 'tt-home-bar-preview-published.json';
29
+ var MIN_GAP_MS = 10 * 60 * 1000;
24
30
 
25
31
  // Lines land in the syslog through StandaloneService, when it is running.
26
32
  function report(level, message) {
@@ -73,6 +79,20 @@ function exitSoon() {
73
79
  }, 1500);
74
80
  }
75
81
 
82
+ function readState(dir) {
83
+ try { return JSON.parse(fs.readFileSync(path.join(dir, STATE_FILE), 'utf8')) || {}; } catch (e) { return {}; }
84
+ }
85
+
86
+ function writeState(dir, raw) {
87
+ try { fs.writeFileSync(path.join(dir, STATE_FILE), JSON.stringify({ at: Date.now(), raw: raw })); } catch (e) {}
88
+ }
89
+
90
+ // The 4:3 thumbnail form the test build proved, for a TV that refuses the
91
+ // 16:9 mqdefault images (smaller than Samsung's documented minimum).
92
+ function fallbackRaw(raw) {
93
+ return raw.split('/mqdefault.jpg').join('/hqdefault.jpg').split('"16by9"').join('"4by3"');
94
+ }
95
+
76
96
  function publish(trigger) {
77
97
  var hasPreview = typeof webapis !== 'undefined' && webapis && webapis.preview
78
98
  && typeof webapis.preview.setPreviewData === 'function';
@@ -90,19 +110,37 @@ function publish(trigger) {
90
110
  }
91
111
  var tiles = 0;
92
112
  for (var i = 0; i < stored.data.sections.length; i++) tiles += (stored.data.sections[i].tiles || []).length;
93
- try {
94
- webapis.preview.setPreviewData(stored.raw, function () {
95
- report('INFO', 'published ' + stored.data.sections.length + ' sections, ' + tiles + ' tiles (trigger ' + trigger + ')');
96
- exitSoon();
97
- }, function (err) {
98
- report('ERROR', 'setPreviewData failed (trigger ' + trigger + ', ' + stored.data.sections.length + ' sections): '
99
- + (err && (err.name + ': ' + err.message) || err));
100
- exitSoon();
101
- });
102
- } catch (e) {
103
- report('ERROR', 'setPreviewData threw (trigger ' + trigger + '): ' + (e && e.message || e));
113
+ var dir = path.dirname(stored.file);
114
+ var state = readState(dir);
115
+ var sinceMs = Date.now() - Number(state.at || 0);
116
+ if (state.raw === stored.raw && trigger === 'app') {
117
+ // Already showing this row; publishing it again would only use up the
118
+ // one update Samsung allows per ten minutes.
104
119
  exitSoon();
120
+ return;
105
121
  }
122
+ if (sinceMs >= 0 && sinceMs < MIN_GAP_MS) {
123
+ report('INFO', 'row changed, waiting ' + Math.round((MIN_GAP_MS - sinceMs) / 1000) + ' s: Samsung allows one update per 10 min (trigger ' + trigger + ')');
124
+ exitSoon();
125
+ return;
126
+ }
127
+ var attempt = function (raw, label, onFail) {
128
+ try {
129
+ webapis.preview.setPreviewData(raw, function () {
130
+ writeState(dir, stored.raw);
131
+ report('INFO', 'published ' + stored.data.sections.length + ' sections, ' + tiles + ' tiles' + label + ' (trigger ' + trigger + ')');
132
+ exitSoon();
133
+ }, function (err) {
134
+ report('ERROR', 'setPreviewData failed' + label + ' (trigger ' + trigger + '): ' + (err && (err.name + ': ' + err.message) || err));
135
+ if (onFail) onFail(); else exitSoon();
136
+ });
137
+ } catch (e) {
138
+ report('ERROR', 'setPreviewData threw' + label + ' (trigger ' + trigger + '): ' + (e && e.message || e));
139
+ if (onFail) onFail(); else exitSoon();
140
+ }
141
+ };
142
+ var fallback = fallbackRaw(stored.raw);
143
+ attempt(stored.raw, '', fallback !== stored.raw ? function () { attempt(fallback, ' with 4:3 thumbnails', null); } : null);
106
144
  }
107
145
 
108
146
  module.exports.onStart = function () {};