From 2a77d12b94bf96bfcb6f08852a451fadfe0ab8ca Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Mon, 4 Mar 2024 23:45:11 -0500 Subject: [PATCH] simplified main control page. fixed some bugs. added admin control page --- atv/assets/admin.html | 326 ++++++++++++++++++++++++++++++++++++++++ atv/assets/control.html | 6 +- atv/assets/index.html | 12 +- atv/bin/atv | 3 - atv/lib/atv/channel.rb | 13 +- atv/lib/atv/database.rb | 6 +- 6 files changed, 346 insertions(+), 20 deletions(-) create mode 100644 atv/assets/admin.html diff --git a/atv/assets/admin.html b/atv/assets/admin.html new file mode 100644 index 0000000..719cbec --- /dev/null +++ b/atv/assets/admin.html @@ -0,0 +1,326 @@ + + + + + + + + + +
+
+ + + + + + + + + +
Now PlayingSome File
Playing NextSome Other File
+
+ +
+

Queued Videos

+
The queue is currently empty
+
+ +
+
+ + + + +
+
+
+ + + + + + + + diff --git a/atv/assets/control.html b/atv/assets/control.html index c232fee..2e0f5e3 100644 --- a/atv/assets/control.html +++ b/atv/assets/control.html @@ -113,9 +113,6 @@
- - -
@@ -126,7 +123,7 @@

Browse Media


- +

@@ -190,7 +187,6 @@ const UI = (()=>{ self.set_play_state = (up_now, up_next, playing)=>{ currVid.innerText = up_now; nextVid.innerText = up_next; - playBtn.value = (playing ? "Pause" : "Play"); }; self.browse_up = ()=>{ diff --git a/atv/assets/index.html b/atv/assets/index.html index 398af08..604eaff 100644 --- a/atv/assets/index.html +++ b/atv/assets/index.html @@ -78,7 +78,7 @@ const updateChannelTitle = ()=>{ } }; -const updatePlayer = ()=>{ +const updatePlayer = (prev)=>{ const curr_time = secondsSinceMidnight(); if (!current["start_time"]) { @@ -93,7 +93,10 @@ const updatePlayer = ()=>{ const diffTooBig = Math.abs(Math.floor(Video.currentTime) - elapsed) > 3; const srcChanged = Video.src.replace(/#t=[0-9]+$/, '') != encodeURI(document.location + current["curr"]["path"]); - if (diffTooBig || srcChanged) + const playStateChanged = prev["playing"] != current["playing"]; + const chanChanged = prev["chan"] != current["chan"]; + + if (diffTooBig || srcChanged || playStateChanged || chanChanged) { Video.src = current["curr"]["path"] + "#t=" + elapsed; if (current["playing"]) @@ -113,11 +116,12 @@ const connect = ()=>{ ws.onmessage = (event)=>{ const msg = JSON.parse(event.data); - if (msg["cmd"] == "play" || msg["cmd"] == "chan_next" || msg["cmd"] == "chan_prev" || msg["cmd"] == "pause") { + console.log(msg); + const prev = current; current = msg; updateChannelTitle(); - updatePlayer(); + updatePlayer(prev); } }; diff --git a/atv/bin/atv b/atv/bin/atv index b45a054..f75e788 100755 --- a/atv/bin/atv +++ b/atv/bin/atv @@ -16,9 +16,6 @@ Dir.glob("#{ASSET_DIR}/**/*.*").each do |path| FileUtils.cp(path, "#{ATV_ROOT}/#{file}") end -#JSON.parse(File.read("#{ATV_ROOT}/config.json")) -#exit 1 - # Then run the server db = ATV::Database.new(ATV_ROOT) diff --git a/atv/lib/atv/channel.rb b/atv/lib/atv/channel.rb index 42af495..9a1842f 100644 --- a/atv/lib/atv/channel.rb +++ b/atv/lib/atv/channel.rb @@ -8,7 +8,7 @@ module ATV @time = 0 @index = 0 @queue = [] - @current = items[@index] if items.length > 0 + @current = files[@index] if files.length > 0 end @@ -29,14 +29,14 @@ module ATV if @queue.length > 0 @current = @queue.shift else - @index = ((@index+1) >= items.length ? 0 : (@index+1)) - @current = items[@index] + @index = ((@index+1) >= files.length ? 0 : (@index+1)) + @current = files[@index] end end def state() - next_index = ((@index+1) >= items.length ? 0 : (@index+1)) - next_item = (@queue.length > 0 ? @queue.first : items[next_index]) + next_index = ((@index+1) >= files.length ? 0 : (@index+1)) + next_item = (@queue.length > 0 ? @queue.first : files[next_index]) { "chan" => @name, "time" => @time, @@ -46,6 +46,7 @@ module ATV end def items() +# pp filedata[:tree] { "items" => filedata[:tree] } end @@ -63,7 +64,7 @@ module ATV @db.select_files(@name, @selectors) end - def items() + def files() filedata[:items].values end end diff --git a/atv/lib/atv/database.rb b/atv/lib/atv/database.rb index 02f21a7..eb0d98e 100644 --- a/atv/lib/atv/database.rb +++ b/atv/lib/atv/database.rb @@ -70,10 +70,12 @@ module ATV node[folder] ||= {} node = node[folder] end - node[path.last] = e + + obj = { "path" => e, "duration" => @data[e]["duration"]} + node[path.last] = obj # Return the key/value pair - [e, { "path" => e, "duration" => @data[e]["duration"]}] + [e, obj] end.to_h # save off the tree -- 2.52.0