#!/usr/bin/env ruby require 'thor' require 'pathname' require 'yaml' require 'webradio' require 'podcast' class GetWebRadio < Thor class_option :mp3, type: :boolean, default:true, desc:'convert to mp3 with ffmpeg' config = nil [ './rget.yaml', '~/.rget', "#{Pathname(__dir__)}/../rget.yaml", ].each do |file| path = Pathname(file).expand_path if path.exist? config = path.to_s break end end unless config $stderr.puts 'config file not found' exit 1 end YAML::load_file(config)['programs'].each do |command, params| desc command, params['desc'] define_method(command) do if params['podcast'] podcast(params['url'], params['label']) else process(params['url'], params['label']) end end end private def process(uri, label) WebRadio(uri, options) do |radio| radio.download(label) end end def podcast(uri, label = nil) Podcast.new(uri, options) do |pod| pod.download(label) end end end GetWebRadio.start(ARGV)