// Check if we need to refresh the URI
const diffTooBig = Math.abs(Math.floor(Video.currentTime) - elapsed) > 3;
- const srcChanged = Video.src.replace(/#t=[0-9]+$/, '') != encodeURI(document.location + current["curr"]["path"]);
-
+ const srcChanged = Video.src.replace(/#t=[0-9]+$/, '') != current["curr"]["path"];
const playStateChanged = prev["playing"] != current["playing"];
const chanChanged = prev["chan"] != current["chan"];
#!/bin/env ruby
+require 'json'
+
TYPES = "{mp4,ogg,webm}"
-FILES = ARGV.map {|f| Dir.glob("#{f}/**/*.#{TYPES}") }.flatten
-FILES.each do |f|
-end
+FILES = []
+CMD="ffprobe -show_entries format=duration -v quiet -of csv=\"p=0\" -i"
+ARGV.each do |root|
+ # Generate the index
+ index = []
+ Dir.glob("#{root}/**/*.#{TYPES}").each do |path|
+ short_path = path.sub("#{root}/", '')
+ puts short_path
+ duration = `#{CMD} \"#{path}\"`.chomp.to_f
+ entry = {
+ "path" => short_path,
+ "duration" => duration
+ }
+ index << entry
+ end
+
+ # Save the index to disc
+ File.open("#{root}/index.json", "wb") do |f|
+ f.write JSON.dump(index)
+ end
+end
require 'json'
+require 'open-uri'
module ATV
class Database
CMD="ffprobe -show_entries format=duration -v quiet -of csv=\"p=0\" -i"
- def initialize(root, scan_dirs = [])
+ def initialize(root, sources = [])
@root = root
@path = "#{root}/index.json"
@data = {}
- @dirs = scan_dirs
- pp scan_dirs
+ @cache = {}
+ @sources = sources
load()
end
def load()
- @cache = {}
- if File.exist? @path
- @data = JSON.parse(File.read(@path))
+ @sources.each do |source|
+ uri = "#{source}/index.json"
+ begin
+ index = JSON.parse(URI.open(uri).read)
+ index.each do |item|
+ short_path = item["path"]
+ item["path"] = URI::Parser.new.escape("#{source}/#{short_path}")
+ @data[short_path] = item
+ end
+ rescue Exception => e
+ puts "Failed to open URI #{uri}: #{e}"
+ end
end
- cleanup()
- scan()
- save()
pp @data
end
- def save()
- File.open(@path, "wb") do |f|
- puts f
- f.write JSON.dump(@data)
- end
- end
-
def files
@data.keys.map do |f|
@data[f].merge({ "path" => f })
@data[key]
end
- def cleanup()
- files.each do |f|
- if not File.exist?("#{ATV_ROOT}/#{f["path"]}")
- puts "Cleanup #{f["path"]}"
- @data.delete(f["path"])
- end
- end
- end
-
- def scan()
- # scan for videos
- @dirs.each do |dir|
- Dir.glob("#{@root}/#{dir}/**/*.{mp4,m4v,webm,ogg}").each do |f|
- short_path = f.sub("#{@root}/", '')
- next if @data[short_path]
- puts f
- duration = `#{CMD} \"#{f}\"`.chomp.to_f
- @data[short_path] = { "duration" => duration }
- end
- end
- end
-
def select_files(channel, selectors)
if @cache[channel].nil? then
@cache[channel] = { name: channel, items: {} }
tree = {}
@cache[channel][:items] = selectors.map do |sel|
- @data.keys.select {|f| f.sub(%r{[^/]+/}, '').start_with? sel }
+ @data.keys.select {|f| f.start_with? sel }
end.flatten.uniq.map do |e|
# Add item to the virtual directory tree
node = tree
node = node[folder]
end
- obj = { "path" => e, "duration" => @data[e]["duration"]}
- node[path.last] = obj
+ node[path.last] = @data[e]
# Return the key/value pair
- [e, obj]
+ [e, @data[e]]
end.to_h
# save off the tree
@cache[channel][:tree] = tree
+ pp @cache[channel]
+
end
@cache[channel]
end