From 40b296bd049d81e6aea77f6d51d29d3b4649b812 Mon Sep 17 00:00:00 2001 From: Mike Lowis Date: Tue, 2 Apr 2024 14:06:31 -0400 Subject: [PATCH] fix some bugs stemming from new source handling. Also added rtio control for ranomization --- atv/Gemfile.lock | 2 +- atv/assets/admin.html | 6 ++++-- atv/assets/control.html | 3 ++- atv/assets/index.html | 9 ++++++++- atv/assets/ui.js | 12 +++++------- atv/bin/atv | 12 +++++++++--- atv/lib/atv/channel.rb | 12 ++++++++++-- atv/lib/atv/database.rb | 3 ++- 8 files changed, 41 insertions(+), 18 deletions(-) diff --git a/atv/Gemfile.lock b/atv/Gemfile.lock index 3ff8bcf..cab5c65 100644 --- a/atv/Gemfile.lock +++ b/atv/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - atv (1.0.0) + atv (1.1.0) iodine GEM diff --git a/atv/assets/admin.html b/atv/assets/admin.html index 8d1ddfe..49095f1 100644 --- a/atv/assets/admin.html +++ b/atv/assets/admin.html @@ -27,8 +27,10 @@ - + +
+
@@ -72,7 +74,7 @@ else { UI.set_play_state( - data["curr"]["path"], // Now Playing + data["curr"]["spath"], // Now Playing data.playing // Playing or paused ); } diff --git a/atv/assets/control.html b/atv/assets/control.html index b315c8a..73e6cf9 100644 --- a/atv/assets/control.html +++ b/atv/assets/control.html @@ -26,6 +26,7 @@
+
@@ -69,7 +70,7 @@ else { UI.set_play_state( - data["curr"]["path"], // Now Playing + data["curr"]["spath"], // Now Playing data.playing // Playing or paused ); } diff --git a/atv/assets/index.html b/atv/assets/index.html index b7315b5..108bb11 100644 --- a/atv/assets/index.html +++ b/atv/assets/index.html @@ -77,7 +77,7 @@ const updatePlayer = (prev)=>{ SubtitleTrack.src = current["curr"]["path"] + ".vtt"; if (current["playing"]) { - Video.play(); + Video.play() } else { @@ -107,8 +107,15 @@ const connect = ()=>{ }; }; +const toggleMute = ()=>{ + Video.muted = !Video.muted; + console.log(Video.muted); +}; + Video.addEventListener("ended", updatePlayer); document.addEventListener("visibilitychange", updatePlayer); +document.addEventListener("click", toggleMute); +document.addEventListener("keypress", toggleMute); (()=>{ connect(); })(); diff --git a/atv/assets/ui.js b/atv/assets/ui.js index 2a6effe..01b5049 100644 --- a/atv/assets/ui.js +++ b/atv/assets/ui.js @@ -6,13 +6,11 @@ const UI = (()=>{ let path = []; const showBrowser = ()=>{ - path = []; browseView.style.display = "flex"; mainView.style.display = "none"; }; const showMain = ()=>{ - path = []; browseView.style.display = "none"; mainView.style.display = "flex"; }; @@ -64,7 +62,7 @@ const UI = (()=>{ queueList.innerHTML = ""; for (const item of queue) { const el = document.createElement("div"); - el.innerText = item.path; + el.innerText = item.spath; queueList.appendChild(el); } } else { @@ -86,10 +84,10 @@ const UI = (()=>{ for (const item of items) { const el = document.createElement("div"); el.innerText = item.name; - console.log(item); - console.log('path' in item); - if ('path' in item) { - el.onclick = ()=>{ self.enqueue(item.path); }; + if (item.type == "file") { + el.onclick = ()=>{ + self.enqueue(path.concat(item.name).join("/")); + }; } else { el.onclick = ()=>{ linkDown(item.name); }; } diff --git a/atv/bin/atv b/atv/bin/atv index 0897616..e56dc0f 100755 --- a/atv/bin/atv +++ b/atv/bin/atv @@ -11,8 +11,9 @@ ASSET_DIR = File.join(File.dirname(__FILE__), "../assets") CONFIG_PATH = "#{ATV_ROOT}/config.json" DEFAULT_CONFIG = { "sources" => [ + "nas", "local", - "nas" + "usb" ], "channels" => [ @@ -25,7 +26,13 @@ DEFAULT_CONFIG = { "Shorts", "Shows", "Photos", - ] + ], + "ratios": { + "Movies": 1, + "TV Series": 2, + "Shorts": 4, + "Photos": 3 + } }, { "name" => "Christmas", @@ -57,7 +64,6 @@ db = ATV::Database.new(ATV_ROOT, CONFIG["sources"]) channels = CONFIG["channels"].map do |c| ATV::Channel.new(db, c) -# ATV::Channel.new(c["name"], db, c["selectors"]) end player = ATV::Player.new(db, channels) diff --git a/atv/lib/atv/channel.rb b/atv/lib/atv/channel.rb index 509a2a9..bd23864 100644 --- a/atv/lib/atv/channel.rb +++ b/atv/lib/atv/channel.rb @@ -7,6 +7,7 @@ module ATV @selectors = config["selectors"] @play_ads = config["play_ads"] @randomize = config["randomize"] + @ratios = config["ratios"] # dynamic state @time = 0 @@ -39,8 +40,15 @@ module ATV end def pick_random() - # random walk the tree to find a leaf item and play that - tree = filedata[:tree] + if not @ratios.nil? then + options = @ratios.map {|e| Array.new(e[1], e[0]) }.flatten.map{|k| filedata[:tree][k] }.compact + else + options = filedata[:tree].values + end + random_walk(options.sample) + end + + def random_walk(tree) while tree["path"].nil? tree = tree[tree.keys.sample] end diff --git a/atv/lib/atv/database.rb b/atv/lib/atv/database.rb index d96bfee..a925afb 100644 --- a/atv/lib/atv/database.rb +++ b/atv/lib/atv/database.rb @@ -22,6 +22,7 @@ module ATV index.each do |item| short_path = item["path"] item["path"] = URI::Parser.new.escape("#{source}/#{short_path}") + item["spath"] = short_path @data[short_path] = item end rescue Exception => e @@ -51,7 +52,7 @@ module ATV end.flatten.uniq.map do |e| # Add item to the virtual directory tree node = tree - path = e.sub(%r{[^/]+/}, '').split("/") + path = e.split("/") path[0..-2].each do |folder| node[folder] ||= {} node = node[folder] -- 2.54.0