]> git.mdlowis.com Git - proto/atv.git/commitdiff
fix some bugs stemming from new source handling. Also added rtio control for ranomization
authorMike Lowis <mike.lowis@gentex.com>
Tue, 2 Apr 2024 18:06:31 +0000 (14:06 -0400)
committerMike Lowis <mike.lowis@gentex.com>
Tue, 2 Apr 2024 18:06:31 +0000 (14:06 -0400)
atv/Gemfile.lock
atv/assets/admin.html
atv/assets/control.html
atv/assets/index.html
atv/assets/ui.js
atv/bin/atv
atv/lib/atv/channel.rb
atv/lib/atv/database.rb

index 3ff8bcfacd8b3c394ca5253c5ba60da97d538814..cab5c65f1cdfe8a38862a5a334d3ce7eaf7cb051 100644 (file)
@@ -1,7 +1,7 @@
 PATH
   remote: .
   specs:
-    atv (1.0.0)
+    atv (1.1.0)
       iodine
 
 GEM
index 8d1ddfe717962d3771546c2fddd24a822c5499ff..49095f1c79237db6e4bbaabdc859f6e0240ef61d 100644 (file)
             <input type="button" value="Play" onclick="javascript:UI.play_pause()" id="playBtn"/>
             <input type="button" value="Chan +" onclick="javascript:UI.chan_next()"/>
             <input type="button" value="Chan -" onclick="javascript:UI.chan_prev()"/>
-            <input type="button" value="Skip" onclick="javascript:UI.skip()"/>
+        </div>
+        <div class="row">
             <input type="button" value="Enqueue" onclick="javascript:UI.select_file()"/>
+            <input type="button" value="Skip" onclick="javascript:UI.skip()"/>
         </div>
     </section>
 </article>
@@ -72,7 +74,7 @@
         else
         {
             UI.set_play_state(
-                data["curr"]["path"], // Now Playing
+                data["curr"]["spath"], // Now Playing
                 data.playing          // Playing or paused
             );
         }
index b315c8a87d10d972185209a77333a459c0243cd9..73e6cf959a5c2d06961850b5e8705fdc54d47446 100644 (file)
@@ -26,6 +26,7 @@
     <section>
         <div class="row">
             <input type="button" value="Enqueue" onclick="javascript:UI.select_file()"/>
+            <input type="button" value="Skip" onclick="javascript:UI.skip()"/>
         </div>
     </section>
 </article>
@@ -69,7 +70,7 @@
         else
         {
             UI.set_play_state(
-                data["curr"]["path"], // Now Playing
+                data["curr"]["spath"], // Now Playing
                 data.playing          // Playing or paused
             );
         }
index b7315b5c2decc894db9170f5fe17e508b242ad62..108bb11a7339d5bed22ab5c25a26de2bc354773d 100644 (file)
@@ -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(); })();
 </script>
index 2a6effe82fb2bde0749c0e3ca8709af532222681..01b50496cbc2338f527670c1132d59a0d85e0519 100644 (file)
@@ -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); };
             }
index 089761698a4e4b97e1c78d8fba73def39b8bd030..e56dc0f25755e3b94bb98a952367b3325f57ace0 100755 (executable)
@@ -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)
index 509a2a96138d11ca5637532d57ae9429aae7de15..bd2386495bf1a62188148e1ffd8450321a38f51e 100644 (file)
@@ -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
index d96bfeea00523446efbc89eb191e1a4434a2bd43..a925afbdeb67f8e8d44b60f12bdf2fa49b979ea0 100644 (file)
@@ -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]