ATV_ROOT = (ENV["ATV_ROOT"] || "/var/www/atv")
ASSET_DIR = File.join(File.dirname(__FILE__), "../assets")
+CONFIG_PATH = "#{ATV_ROOT}/config.json"
+DEFAULT_CONFIG = {
+ "sources" => [
+ "local",
+ "nas"
+ ],
+
+ "channels" => [
+ {
+ "name" => "Everything",
+ "randomize" => false,
+ "play_ads" => true,
+ "selectors" => [
+ "Movies",
+ "Shorts",
+ "Shows",
+ "Photos",
+ ]
+ },
+ {
+ "name" => "Christmas",
+ "randomize" => true,
+ "selectors" => [
+ "Christmas"
+ ]
+ },
+ ]
+}
+
+# load the config or use teh default config
+if File.exist? CONFIG_PATH
+ CONFIG = JSON.parse(File.read(CONFIG_PATH))
+else
+ CONFIG = DEFAULT_CONFIG
+end
# Update website files first
Dir.glob("#{ASSET_DIR}/**/*.*").each do |path|
end
# Then run the server
-db = ATV::Database.new(ATV_ROOT)
-
-channels = [
- ATV::Channel.new('Everything', db,
- ["Movies", "Shorts", "Shows"]),
- ATV::Channel.new('Christmas', db,
- ["Christmas"]),
-]
+db = ATV::Database.new(ATV_ROOT, CONFIG["sources"])
+
+channels = CONFIG["channels"].map do |c|
+ ATV::Channel.new(c["name"], db, c["selectors"])
+end
+
player = ATV::Player.new(db, channels)
ATV::Server.start(player)
class Database
CMD="ffprobe -show_entries format=duration -v quiet -of csv=\"p=0\" -i"
- def initialize(root)
+ def initialize(root, scan_dirs = [])
@root = root
@path = "#{root}/index.json"
@data = {}
+ @dirs = scan_dirs
load()
end
def scan()
# scan for videos
- Dir.glob("#{@root}/**/*.{mp4,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 }
+ @dirs.each do |dir|
+ Dir.glob("#{@root}/#{dir}/**/*.{mp4,webm,ogg}").each do |f|
+ short_path = f.sub(%r{[^/]+/}, '').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.start_with? sel }
+ @data.keys.select {|f| f.sub(%r{[^/]+/}, '').start_with? sel }
end.flatten.uniq.map do |e|
# Add item to the virtual directory tree
node = tree
- path = e.split("/")
+ path = e.sub(%r{[^/]+/}, '').split("/")
path[0..-2].each do |folder|
node[folder] ||= {}
node = node[folder]