fede 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/fede/generator.rb +4 -80
- data/lib/fede/utils.rb +77 -0
- data/lib/fede.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3fee128a87a54db85b035d06ad8dac5980997d340b3c61b6ff63e23126bb3e46
|
4
|
+
data.tar.gz: d112446751fdbd8b1389accf6df4b54aad70f09658bfe7d716ecfd7daa4ec4ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3666bdafffbfeed0ce3c385ac550fdfa75fbca97853beabee4bfcea8be15a54a76c81a5fdc2ac3cc248d60a5d0af07e619ffd20a397f6e333d184c263fc5ed88
|
7
|
+
data.tar.gz: 508dbeaf2a0ac4ac31159cf9e3434a3d9e4387d8aa6881646f2b31be759b07b4f8d09e73087ccf58d8e845ad23c9272d0b1954c158b9cc916cc8abdc13f0cabf
|
data/lib/fede/generator.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
require 'date'
|
3
3
|
|
4
|
+
require_relative 'utils'
|
5
|
+
|
4
6
|
class Fede
|
5
7
|
class FeedGenerator
|
6
8
|
def initialize(site_config, data_directory)
|
@@ -21,7 +23,7 @@ class Fede
|
|
21
23
|
|
22
24
|
def generate
|
23
25
|
output_feed
|
24
|
-
puts "#{@feed_file} written!"
|
26
|
+
puts "\tFEDE: #{@feed_file} written!"
|
25
27
|
end
|
26
28
|
|
27
29
|
def append(item_count = 1)
|
@@ -54,36 +56,13 @@ class Fede
|
|
54
56
|
episodes_string = last_n_episodes.reduce('') { |prev, ep| "#{prev}#{ep.to_s(2)}" }
|
55
57
|
file.write("#{episodes_string}#{footer}")
|
56
58
|
end
|
57
|
-
puts "Last #{last_n_episodes.length} episode(s) appended to #{@feed_file}!"
|
59
|
+
puts "\tFEDE: Last #{last_n_episodes.length} episode(s) appended to #{@feed_file}!"
|
58
60
|
rescue Errno::ENOENT
|
59
61
|
puts "Cannot append if feed doesn't exist"
|
60
62
|
end
|
61
63
|
|
62
64
|
private
|
63
65
|
|
64
|
-
def parse_data(path)
|
65
|
-
data = {}
|
66
|
-
Dir.entries(path).each do |file|
|
67
|
-
next if ['.', '..'].include? file
|
68
|
-
|
69
|
-
data[file.split('.')[0]] = YAML.load_file "#{path}/#{file}"
|
70
|
-
end
|
71
|
-
data
|
72
|
-
end
|
73
|
-
|
74
|
-
def parse_yaml(file)
|
75
|
-
YAML.load_file file
|
76
|
-
end
|
77
|
-
|
78
|
-
def get_setting(setting_name)
|
79
|
-
setting = @config['podcast'][setting_name] || @config[setting_name]
|
80
|
-
if setting.nil?
|
81
|
-
raise StandardError, "Error: setting #{setting_name} is not defined in the config file, cannot continue"
|
82
|
-
end
|
83
|
-
|
84
|
-
setting
|
85
|
-
end
|
86
|
-
|
87
66
|
def output_feed
|
88
67
|
build_date = DateTime.now.strftime(get_setting('datetime_format_string'))
|
89
68
|
base_url = get_setting 'url'
|
@@ -193,61 +172,6 @@ class Fede
|
|
193
172
|
episode_list
|
194
173
|
end
|
195
174
|
|
196
|
-
def format_description(description, details: '', indent_level: 0, strip_all: false)
|
197
|
-
indentation = "\t" * indent_level
|
198
|
-
description = "#{description}\n#{indentation}#{details}".gsub '</br>', "\n#{indentation}"
|
199
|
-
description.gsub! '<p>', ''
|
200
|
-
description.gsub! '</p>', "\n#{indentation}"
|
201
|
-
description.gsub! '<ul>', ''
|
202
|
-
description.gsub! '<li>', "\n#{indentation} + "
|
203
|
-
description.gsub! '</li>', ''
|
204
|
-
description.gsub! '</ul>', "\n#{indentation}"
|
205
|
-
|
206
|
-
if strip_all
|
207
|
-
description.gsub!(/<.?[^>]+>/, '')
|
208
|
-
else
|
209
|
-
# strip rest of html tags (a tags are allowed)
|
210
|
-
description.gsub!(%r{<[^a][^a]/?[^>]+>}, '')
|
211
|
-
end
|
212
|
-
description.gsub!(" \n", "\n")
|
213
|
-
description.strip
|
214
|
-
end
|
215
|
-
|
216
|
-
def format_subtitle(subtitle)
|
217
|
-
desc = format_description(subtitle, strip_all: true)
|
218
|
-
desc.length > 255 ? "#{desc.slice(0, 252)}..." : desc
|
219
|
-
end
|
220
|
-
|
221
|
-
def episode_bytes_length(episode)
|
222
|
-
return episode['bytes_length'] if episode['bytes_length']
|
223
|
-
|
224
|
-
File.new("#{Dir.getwd}#{episode[@ep_url]}").size
|
225
|
-
end
|
226
|
-
|
227
|
-
def episode_duration(episode)
|
228
|
-
return episode['duration'] if episode['duration']
|
229
|
-
|
230
|
-
raise 'FFMPEG not found. ffmpeg is needed to fech episode length' unless which('ffmpeg')
|
231
|
-
|
232
|
-
cmd = "ffmpeg -i #{Dir.getwd}#{episode[@ep_url]} 2>&1 | grep 'Duration' | cut -d ' ' -f 4 | sed s/\.[0-9]*,//"
|
233
|
-
`#{cmd}`.strip!
|
234
|
-
end
|
235
|
-
|
236
|
-
def episode_image(episode)
|
237
|
-
episode[@ep_img] || get_setting('logo')
|
238
|
-
end
|
239
|
-
|
240
|
-
def which(cmd)
|
241
|
-
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
242
|
-
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
243
|
-
exts.each do |ext|
|
244
|
-
exe = File.join(path, "#{cmd}#{ext}")
|
245
|
-
return exe if File.executable?(exe) && !File.directory?(exe)
|
246
|
-
end
|
247
|
-
end
|
248
|
-
nil
|
249
|
-
end
|
250
|
-
|
251
175
|
def load_episode_list
|
252
176
|
episodes
|
253
177
|
episodes_from_seasons
|
data/lib/fede/utils.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
def parse_data(path)
|
2
|
+
data = {}
|
3
|
+
Dir.entries(path).each do |file|
|
4
|
+
next if ['.', '..'].include? file
|
5
|
+
|
6
|
+
data[file.split('.')[0]] = YAML.load_file "#{path}/#{file}"
|
7
|
+
end
|
8
|
+
data
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse_yaml(file)
|
12
|
+
YAML.load_file file
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_setting(setting_name)
|
16
|
+
setting = @config['podcast'][setting_name] || @config[setting_name]
|
17
|
+
if setting.nil?
|
18
|
+
raise StandardError, "Error: setting #{setting_name} is not defined in the config file, cannot continue"
|
19
|
+
end
|
20
|
+
|
21
|
+
setting
|
22
|
+
end
|
23
|
+
|
24
|
+
def format_description(description, details: '', indent_level: 0, strip_all: false)
|
25
|
+
indentation = "\t" * indent_level
|
26
|
+
description = "#{description}\n#{indentation}#{details}".gsub '</br>', "\n#{indentation}"
|
27
|
+
description.gsub! '<p>', "\n#{indentation}"
|
28
|
+
description.gsub! '</p>', ''
|
29
|
+
description.gsub! '<ul>', ''
|
30
|
+
description.gsub! '<li>', "\n#{indentation} + "
|
31
|
+
description.gsub! '</li>', ''
|
32
|
+
description.gsub! '</ul>', "\n#{indentation}"
|
33
|
+
|
34
|
+
if strip_all
|
35
|
+
description.gsub!(/<.?[^>]+>/, '')
|
36
|
+
else
|
37
|
+
# strip rest of html tags (a tags are allowed)
|
38
|
+
description.gsub!(%r{<[^a][^a]/?[^>]+>}, '')
|
39
|
+
end
|
40
|
+
description.gsub!(" \n", "\n")
|
41
|
+
description.strip
|
42
|
+
end
|
43
|
+
|
44
|
+
def format_subtitle(subtitle)
|
45
|
+
desc = format_description(subtitle, strip_all: true)
|
46
|
+
desc.length > 255 ? "#{desc.slice(0, 252)}..." : desc
|
47
|
+
end
|
48
|
+
|
49
|
+
def episode_bytes_length(episode)
|
50
|
+
return episode['bytes_length'] if episode['bytes_length']
|
51
|
+
|
52
|
+
File.new("#{Dir.getwd}#{episode[@ep_url]}").size
|
53
|
+
end
|
54
|
+
|
55
|
+
def episode_duration(episode)
|
56
|
+
return episode['duration'] if episode['duration']
|
57
|
+
|
58
|
+
raise 'FFMPEG not found. ffmpeg is needed to fech episode length' unless which('ffmpeg')
|
59
|
+
|
60
|
+
cmd = "ffmpeg -i #{Dir.getwd}#{episode[@ep_url]} 2>&1 | grep 'Duration' | cut -d ' ' -f 4 | sed s/\.[0-9]*,//"
|
61
|
+
`#{cmd}`.strip!
|
62
|
+
end
|
63
|
+
|
64
|
+
def episode_image(episode)
|
65
|
+
episode[@ep_img] || get_setting('logo')
|
66
|
+
end
|
67
|
+
|
68
|
+
def which(cmd)
|
69
|
+
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
70
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
71
|
+
exts.each do |ext|
|
72
|
+
exe = File.join(path, "#{cmd}#{ext}")
|
73
|
+
return exe if File.executable?(exe) && !File.directory?(exe)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
nil
|
77
|
+
end
|
data/lib/fede.rb
CHANGED
@@ -8,7 +8,7 @@ class Fede
|
|
8
8
|
elsif mode == 'append-available'
|
9
9
|
append_available
|
10
10
|
else
|
11
|
-
puts "Invalid mode #{mode}. Valid modes are 'generate' or 'append'"
|
11
|
+
puts "\tFEDE ERROR:Invalid mode #{mode}. Valid modes are 'generate' or 'append'"
|
12
12
|
end
|
13
13
|
rescue StandardError => e
|
14
14
|
puts e
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fede
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lucca Augusto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-04-
|
11
|
+
date: 2024-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Very Simple XML feed generator from yaml data files
|
14
14
|
email: lucca@luccaaugusto.xyz
|
@@ -20,6 +20,7 @@ files:
|
|
20
20
|
- bin/fede
|
21
21
|
- lib/fede.rb
|
22
22
|
- lib/fede/generator.rb
|
23
|
+
- lib/fede/utils.rb
|
23
24
|
- lib/fede/xml_feed.rb
|
24
25
|
- lib/fede/xml_node.rb
|
25
26
|
homepage: https://github.com/luccaugusto/fede
|