Sha256: f007e7280c392ad7891978f71db4909adca6849ec90bd7b9ff498223a68c4ef3
Contents?: true
Size: 1.62 KB
Versions: 26
Compression:
Stored size: 1.62 KB
Contents
#!/usr/bin/env ruby require 'thor' require 'pathname' require 'yaml' require 'ostruct' require 'webradio' require 'podcast' class GetWebRadio < Thor class_option :mp3, type: :boolean, default:true, desc:'convert to mp3 with ffmpeg' class_option :path, type: :string, desc:'store path (accept "dropbox://~")' config_file = nil [ ENV['RGET_CONFIG'], './rget.yaml', '~/.rget', "#{Pathname(__dir__)}/../rget.yaml", ].each do |file| path = Pathname(file).expand_path rescue next if path.exist? config_file = path.to_s break end end unless config_file $stderr.puts 'config file not found' exit 1 end config = {'options' => {}, 'programs' => {}}.merge(YAML::load_file(config_file) || {}) (config['programs'] || {}).each do |command, params| desc command, params['desc'] define_method(command) do opts = OpenStruct.new(config['options'].merge(options)) begin if params['podcast'] Podcast.new(params, opts){|media|media.download} else WebRadio(params, opts){|media|media.download} end rescue WebRadio::NotFoundError, WebRadio::DownloadError, WebRadio::UnsupportError => e $stderr.puts e.message end end end desc 'init', 'show initial config file, save to "rget.yaml" or "~/.rget"' def init puts <<~CONFIG options: mp3nize: ffmpeg -i '$1' -vn -acodec copy '$2' || ffmpeg -i '$1' -vn -y -ab 64k '$2' path: . programs: CONFIG end desc 'yaml <URL>', 'dump YAML of specified URL' def yaml(url) dump = WebRadio({'url'=>url}, OpenStruct.new({dump: true})).dump puts YAML.dump(dump).lines.drop(1).map{|l| " #{l}"} end end GetWebRadio.start(ARGV)
Version data entries
26 entries across 26 versions & 1 rubygems