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

Version Path
rget-4.14.0 bin/rget
rget-4.13.2 bin/rget
rget-4.13.1 bin/rget
rget-4.13.0 bin/rget
rget-4.12.0 bin/rget
rget-4.11.0 bin/rget
rget-4.10.0 bin/rget
rget-4.9.3 bin/rget
rget-4.9.2 bin/rget
rget-4.9.1 bin/rget
rget-4.9.0 bin/rget
rget-4.8.4 bin/rget
rget-4.8.3 bin/rget
rget-4.8.2 bin/rget
rget-4.8.1 bin/rget
rget-4.8.0 bin/rget
rget-4.7.9 bin/rget
rget-4.7.8 bin/rget
rget-4.7.7 bin/rget
rget-4.7.6 bin/rget