Top Level Namespace
Defined Under Namespace
Classes: Fede
Instance Method Summary collapse
- #episode_bytes_length(episode) ⇒ Object
- #episode_duration(episode) ⇒ Object
- #episode_image(episode) ⇒ Object
- #format_description(description, details: '', indent_level: 0, strip_all: false) ⇒ Object
- #format_subtitle(subtitle) ⇒ Object
- #get_setting(setting_name) ⇒ Object
- #parse_data(path) ⇒ Object
- #parse_yaml(file) ⇒ Object
- #which(cmd) ⇒ Object
Instance Method Details
#episode_bytes_length(episode) ⇒ Object
49 50 51 52 53 |
# File 'lib/fede/utils.rb', line 49 def episode_bytes_length(episode) return episode['bytes_length'] if episode['bytes_length'] File.new("#{Dir.getwd}#{episode[@ep_url]}").size end |
#episode_duration(episode) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/fede/utils.rb', line 55 def episode_duration(episode) return episode['duration'] if episode['duration'] raise 'FFMPEG not found. ffmpeg is needed to fech episode length' unless which('ffmpeg') cmd = "ffmpeg -i #{Dir.getwd}#{episode[@ep_url]} 2>&1 | grep 'Duration' | cut -d ' ' -f 4 | sed s/\.[0-9]*,//" `#{cmd}`.strip! end |
#episode_image(episode) ⇒ Object
64 65 66 |
# File 'lib/fede/utils.rb', line 64 def episode_image(episode) episode[@ep_img] || get_setting('logo') end |
#format_description(description, details: '', indent_level: 0, strip_all: false) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/fede/utils.rb', line 24 def format_description(description, details: '', indent_level: 0, strip_all: false) indentation = "\t" * indent_level description = "#{description}\n#{indentation}#{details}".gsub '</br>', "\n#{indentation}" description.gsub! '<p>', "\n#{indentation}" description.gsub! '</p>', '' description.gsub! '<ul>', '' description.gsub! '<li>', "\n#{indentation} + " description.gsub! '</li>', '' description.gsub! '</ul>', "\n#{indentation}" if strip_all description.gsub!(/<.?[^>]+>/, '') else # strip rest of html tags (a tags are allowed) description.gsub!(%r{<[^a][^a]/?[^>]+>}, '') end description.gsub!(" \n", "\n") description.strip end |
#format_subtitle(subtitle) ⇒ Object
44 45 46 47 |
# File 'lib/fede/utils.rb', line 44 def format_subtitle(subtitle) desc = format_description(subtitle, strip_all: true) desc.length > 255 ? "#{desc.slice(0, 252)}..." : desc end |
#get_setting(setting_name) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/fede/utils.rb', line 15 def get_setting(setting_name) setting = @config['podcast'][setting_name] || @config[setting_name] if setting.nil? raise StandardError, "Error: setting #{setting_name} is not defined in the config file, cannot continue" end setting end |
#parse_data(path) ⇒ Object
1 2 3 4 5 6 7 8 9 |
# File 'lib/fede/utils.rb', line 1 def parse_data(path) data = {} Dir.entries(path).each do |file| next if ['.', '..'].include? file data[file.split('.')[0]] = YAML.load_file "#{path}/#{file}" end data end |
#parse_yaml(file) ⇒ Object
11 12 13 |
# File 'lib/fede/utils.rb', line 11 def parse_yaml(file) YAML.load_file file end |
#which(cmd) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/fede/utils.rb', line 68 def which(cmd) exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exts.each do |ext| exe = File.join(path, "#{cmd}#{ext}") return exe if File.executable?(exe) && !File.directory?(exe) end end nil end |