mirror of
https://github.com/mistergibson/radio.git
synced 2026-11-03 19:31:41 -08:00
added console.sh
This commit is contained in:
parent
6fbb9cf0c7
commit
a23e6376cd
2 changed files with 35 additions and 7 deletions
25
console.sh
Executable file
25
console.sh
Executable file
|
|
@ -0,0 +1,25 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
GEMS_DIR="${SCRIPT_DIR}/.gems"
|
||||||
|
JAVA_OPTS="--enable-native-access=ALL-UNNAMED --enable-native-access=org.jruby.dist"
|
||||||
|
JRUBY_BIN="/usr/bin/jruby"
|
||||||
|
JIRB_BIN="/usr/bin/jirb"
|
||||||
|
JRUBY_OPTIONS="-J-Xms256m -J-Xmx2g"
|
||||||
|
FILE_TO_LOAD="$1"
|
||||||
|
#
|
||||||
|
export GEM_HOME="${GEMS_DIR}"
|
||||||
|
export GEM_PATH="${GEMS_DIR}"
|
||||||
|
#
|
||||||
|
if [ -e "${JIRB_BIN}" ]; then
|
||||||
|
if [ -e "${SCRIPT_DIR}/${FILE_TO_LOAD}" ]; then
|
||||||
|
exec env JAVA_OPTS="${JAVA_OPTS}" JRUBY_OPTIONS="${JRUBY_OPTIONS}" "${JIRB_BIN}" -r "${SCRIPT_DIR}/${FILE_TO_LOAD}"
|
||||||
|
else
|
||||||
|
exec env JAVA_OPTS="${JAVA_OPTS}" JRUBY_OPTIONS="${JRUBY_OPTIONS}" "${JIRB_BIN}"
|
||||||
|
fi
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo "Error: could not locate ${JIRB_BIN}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env jruby
|
!#/usr/bin/env jruby
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "net/http"
|
require "net/http"
|
||||||
|
|
@ -7,7 +7,9 @@ require "json"
|
||||||
require "digest/sha1"
|
require "digest/sha1"
|
||||||
require "sequel"
|
require "sequel"
|
||||||
require "nokogiri"
|
require "nokogiri"
|
||||||
|
unless defined?(Nokogiri::XML)
|
||||||
|
raise Exception.new "Nokogiri did NOT load"
|
||||||
|
end
|
||||||
SCRIPT_DIR = File.expand_path(File.dirname(__FILE__))
|
SCRIPT_DIR = File.expand_path(File.dirname(__FILE__))
|
||||||
CONFIG_PATH = File.join(SCRIPT_DIR, "config.json")
|
CONFIG_PATH = File.join(SCRIPT_DIR, "config.json")
|
||||||
|
|
||||||
|
|
@ -137,14 +139,15 @@ def http_stream_to_file(url, dest_path, user = nil, pass = nil)
|
||||||
unless res.is_a?(Net::HTTPSuccess)
|
unless res.is_a?(Net::HTTPSuccess)
|
||||||
raise "HTTP #{res.code}: #{res.message}"
|
raise "HTTP #{res.code}: #{res.message}"
|
||||||
end
|
end
|
||||||
|
buffer = ::StringIO.new (res.read_body)
|
||||||
|
buffer.rewind
|
||||||
File.open(tmp_dest, "wb") do |f|
|
File.open(tmp_dest, "wb") do |f|
|
||||||
res.read_body { |chunk| f.write(chunk) }
|
buffer.read() { |chunk| f.write(chunk) }
|
||||||
end
|
end
|
||||||
File.rename(tmp_dest, dest_path)
|
File.rename(tmp_dest, dest_path)
|
||||||
success = true
|
success = true
|
||||||
rescue Exception => error
|
rescue Exception => error
|
||||||
log("ERROR", "Download failed for #{url}: #{error.class}: #{error.message}")
|
log("ERROR", "Download failed for #{url}: #{error.class}: #{error.message}, Backtrace --> #{error.backtrace}")
|
||||||
begin
|
begin
|
||||||
File.delete(tmp_dest) if File.exist?(tmp_dest)
|
File.delete(tmp_dest) if File.exist?(tmp_dest)
|
||||||
rescue StandardError
|
rescue StandardError
|
||||||
|
|
@ -158,7 +161,7 @@ def parse_feed(opts)
|
||||||
file_path = opts[:file_path] || raise("parse_feed: :file_path is required")
|
file_path = opts[:file_path] || raise("parse_feed: :file_path is required")
|
||||||
feed_url = opts[:feed_url] || ""
|
feed_url = opts[:feed_url] || ""
|
||||||
|
|
||||||
doc = Nokogiri::XML(File.read(file_path), nil, XML::NO_NETWORK)
|
doc = Nokogiri::XML(File.read(file_path), nil)
|
||||||
channel = doc.at_xpath("//channel")
|
channel = doc.at_xpath("//channel")
|
||||||
raise "No <channel> element found in feed" unless channel
|
raise "No <channel> element found in feed" unless channel
|
||||||
|
|
||||||
|
|
@ -245,7 +248,7 @@ def register_show(show_title, feed_url, archive: false, opml_import: false)
|
||||||
opml_import: opml_import ? 1 : 0,
|
opml_import: opml_import ? 1 : 0,
|
||||||
created_at: now
|
created_at: now
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
log("INFO", "Registered: #{title} (#{slug})")
|
log("INFO", "Registered: #{title} (#{slug})")
|
||||||
true
|
true
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue