Module: FYT
- Defined in:
- lib/fyt.rb,
lib/fyt/base.rb,
lib/fyt/config.rb,
lib/fyt/parser.rb,
lib/fyt/builder.rb,
lib/fyt/storage.rb,
lib/fyt/s3_storage.rb,
lib/fyt/storage_helper.rb
Overview
handles the general behaviour of FYT
Defined Under Namespace
Modules: StorageHelper
Classes: Base, Builder, Config, Parser, S3Storage, Storage
Class Method Summary
collapse
Class Method Details
.add ⇒ Object
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/fyt.rb', line 95
def self.add
print 'Please name of the feed e.g. "My Favorite Videos": '
name = STDIN.gets.rstrip
print 'Please enter feed url e.g. "https://www.youtube.com/feeds/videos.xml?channel_id=AbCdEf1234567890aBcDeF00": '
url = STDIN.gets.rstrip
raise 'No name given' if name.size.zero?
raise 'No feed url given' if url.size.zero?
config = FYT::Config.new
feeds = config[:feeds]
feeds << { name: name, url: url }
config[:feeds] = feeds
end
|
.config ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/fyt.rb', line 79
def self.config
config = FYT::Config.new
print "Please enter storage path [#{config[:storage_path]}]: "
config[:storage_path] = STDIN.gets.rstrip
print "Please enter server prefix [#{config[:server_prefix]}]: "
config[:server_prefix] = STDIN.gets.rstrip
print "Please enter format options [#{config[:format_options]}]: "
config[:format_options] = STDIN.gets.rstrip
print "Please enter output_format [#{config[:output_format]}]: "
config[:output_format] = STDIN.gets.rstrip
end
|
.lock ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/fyt.rb', line 25
def self.lock
lockfile = ENV['HOME'] + '/.fyt/pid.lock'
dirname = File.dirname(lockfile)
FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
File.open(lockfile, ::File::CREAT | ::File::EXCL | ::File::WRONLY) do |f|
f.write(Process.pid.to_s)
end
at_exit { File.delete(lockfile) if File.exist?(lockfile) }
end
|
.run ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/fyt.rb', line 38
def self.run
config = FYT::Config.new
manager =
ProxyFetcher::Manager.new(filters: { country: 'DE', maxtime: '500' })
case config[:storage_type]
when :local
storage = FYT::S3Storage.new(
config[:storage_path],
config[:format_options],
config[:output_format],
manager
)
when :aws
storage = FYT::S3Storage.new(
config[:tmp_path],
config[:format_options],
config[:output_format],
manager
)
Aws.config.update(
credentials: Aws::Credentials.new(
config[:aws][:access_key], config[:aws][:secret_key]
)
)
else
raise 'no storage_type configured'
end
config[:feeds].each do |feed_config|
source_feed = FYT::Parser.new(feed_config[:url], manager).read
new_feed = FYT::Builder.new(source_feed, storage, config[:server_prefix], manager).build
storage.add_feed(feed_config[:name], new_feed)
end
storage.cleanup!
end
|