ayadn 1.5.1 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/MANUAL.md +1 -1
- data/README.md +3 -1
- data/ayadn.gemspec +2 -0
- data/doc/16-movie.md +46 -0
- data/doc/17-tvshow.md +44 -0
- data/doc/{16-contact.md → 18-contact.md} +0 -0
- data/doc/{18-examples.md → 19-examples.md} +0 -0
- data/doc/{17-shortcuts.md → shortcuts.md} +0 -0
- data/lib/ayadn/action.rb +139 -848
- data/lib/ayadn/alias.rb +3 -3
- data/lib/ayadn/api.rb +5 -1
- data/lib/ayadn/app.rb +22 -3
- data/lib/ayadn/blacklist.rb +7 -6
- data/lib/ayadn/check.rb +187 -0
- data/lib/ayadn/descriptions.rb +86 -0
- data/lib/ayadn/errors.rb +17 -0
- data/lib/ayadn/fileops.rb +1 -1
- data/lib/ayadn/mark.rb +5 -4
- data/lib/ayadn/nowplaying.rb +184 -0
- data/lib/ayadn/nowwatching.rb +76 -0
- data/lib/ayadn/post.rb +40 -0
- data/lib/ayadn/search.rb +77 -0
- data/lib/ayadn/set.rb +66 -0
- data/lib/ayadn/settings.rb +9 -1
- data/lib/ayadn/status.rb +18 -2
- data/lib/ayadn/stream.rb +254 -0
- data/lib/ayadn/switch.rb +1 -1
- data/lib/ayadn/tvshow.rb +123 -0
- data/lib/ayadn/version.rb +1 -1
- data/lib/ayadn/view.rb +86 -1
- data/lib/ayadn/workers.rb +70 -14
- data/spec/unit/view_spec.rb +0 -16
- data/spec/unit/workers_spec.rb +17 -16
- metadata +41 -5
data/lib/ayadn/settings.rb
CHANGED
@@ -96,6 +96,8 @@ module Ayadn
|
|
96
96
|
conf[:timeline][:show_spinner] = true if conf[:timeline][:show_spinner].nil?
|
97
97
|
conf[:colors][:debug] = :red if conf[:colors][:debug].nil?
|
98
98
|
conf[:nowplaying] = {} if conf[:nowplaying].nil?
|
99
|
+
conf[:movie] = {hashtag: 'nowwatching'} if conf[:movie].nil?
|
100
|
+
conf[:tvshow] = {hashtag: 'nowwatching'} if conf[:tvshow].nil?
|
99
101
|
|
100
102
|
@options = conf
|
101
103
|
self.write_config_file(config_file, @options)
|
@@ -219,7 +221,13 @@ module Ayadn
|
|
219
221
|
timer: 3
|
220
222
|
},
|
221
223
|
nicerank: @default_nr,
|
222
|
-
nowplaying: {}
|
224
|
+
nowplaying: {},
|
225
|
+
movie: {
|
226
|
+
hashtag: 'nowwatching'
|
227
|
+
},
|
228
|
+
tvshow: {
|
229
|
+
hashtag: 'nowwatching'
|
230
|
+
}
|
223
231
|
}
|
224
232
|
end
|
225
233
|
|
data/lib/ayadn/status.rb
CHANGED
@@ -122,6 +122,9 @@ module Ayadn
|
|
122
122
|
def self.blocked(username)
|
123
123
|
"\nUser #{username} has been blocked.\n".color(:green)
|
124
124
|
end
|
125
|
+
def self.error_missing_title
|
126
|
+
"\nYou have to specify (part of) a movie title.\n".color(:red)
|
127
|
+
end
|
125
128
|
def self.error_missing_username
|
126
129
|
"\nYou have to specify a username.\n".color(:red)
|
127
130
|
end
|
@@ -155,8 +158,12 @@ module Ayadn
|
|
155
158
|
def self.yourpost
|
156
159
|
"Your post:\n\n".color(:cyan)
|
157
160
|
end
|
158
|
-
def self.yourmessage
|
159
|
-
|
161
|
+
def self.yourmessage username = nil
|
162
|
+
if username.nil?
|
163
|
+
"Your message:\n\n".color(:cyan)
|
164
|
+
else
|
165
|
+
"Your message to ".color(:cyan) + username.color(:green) + ":\n\n".color(:cyan)
|
166
|
+
end
|
160
167
|
end
|
161
168
|
def self.message_from(username)
|
162
169
|
"\nMessage from ".color(:cyan) + "#{Settings.config[:identity][:handle]} ".color(:green) + "to ".color(:cyan) + "#{username[0]}".color(:yellow) + ".".color(:cyan)
|
@@ -293,5 +300,14 @@ module Ayadn
|
|
293
300
|
def self.fetching_from source
|
294
301
|
"\nFetching informations from #{source}...\n".color(:green)
|
295
302
|
end
|
303
|
+
def self.no_movie
|
304
|
+
"\nSorry, can't find this movie.\n".color(:blue)
|
305
|
+
end
|
306
|
+
def self.no_show
|
307
|
+
"\nSorry, can't find this show.\n".color(:blue)
|
308
|
+
end
|
309
|
+
def self.no_show_infos
|
310
|
+
"\nSorry, can't find informations about this show.\n".color(:blue)
|
311
|
+
end
|
296
312
|
end
|
297
313
|
end
|
data/lib/ayadn/stream.rb
ADDED
@@ -0,0 +1,254 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Ayadn
|
3
|
+
|
4
|
+
class Stream
|
5
|
+
|
6
|
+
def initialize api, view, workers
|
7
|
+
@api = api
|
8
|
+
@view = view
|
9
|
+
@workers = workers
|
10
|
+
end
|
11
|
+
|
12
|
+
def unified options
|
13
|
+
@view.downloading(options)
|
14
|
+
stream = @api.get_unified(options)
|
15
|
+
Check.no_new_posts(stream, options, 'unified')
|
16
|
+
Databases.save_max_id(stream)
|
17
|
+
@view.render(stream, options)
|
18
|
+
Scroll.new(@api, @view).unified(options) if options[:scroll]
|
19
|
+
end
|
20
|
+
|
21
|
+
def checkins options
|
22
|
+
@view.downloading(options)
|
23
|
+
stream = @api.get_checkins(options)
|
24
|
+
Check.no_new_posts(stream, options, 'explore:checkins')
|
25
|
+
Databases.save_max_id(stream)
|
26
|
+
@view.render(stream, options)
|
27
|
+
Scroll.new(@api, @view).checkins(options) if options[:scroll]
|
28
|
+
end
|
29
|
+
|
30
|
+
def global settings
|
31
|
+
options = settings.dup
|
32
|
+
options[:filter] = nicerank_true()
|
33
|
+
@view.downloading(options)
|
34
|
+
stream = @api.get_global(options)
|
35
|
+
niceranks = NiceRank.new.get_ranks(stream)
|
36
|
+
Check.no_new_posts(stream, options, 'global')
|
37
|
+
Databases.save_max_id(stream)
|
38
|
+
@view.render(stream, options, niceranks)
|
39
|
+
Scroll.new(@api, @view).global(options) if options[:scroll]
|
40
|
+
end
|
41
|
+
|
42
|
+
def trending options
|
43
|
+
@view.downloading(options)
|
44
|
+
stream = @api.get_trending(options)
|
45
|
+
Check.no_new_posts(stream, options, 'explore:trending')
|
46
|
+
Databases.save_max_id(stream)
|
47
|
+
@view.render(stream, options)
|
48
|
+
Scroll.new(@api, @view).trending(options) if options[:scroll]
|
49
|
+
end
|
50
|
+
|
51
|
+
def photos options
|
52
|
+
@view.downloading(options)
|
53
|
+
stream = @api.get_photos(options)
|
54
|
+
Check.no_new_posts(stream, options, 'explore:photos')
|
55
|
+
Databases.save_max_id(stream)
|
56
|
+
@view.render(stream, options)
|
57
|
+
Scroll.new(@api, @view).photos(options) if options[:scroll]
|
58
|
+
end
|
59
|
+
|
60
|
+
def conversations options
|
61
|
+
@view.downloading(options)
|
62
|
+
stream = @api.get_conversations(options)
|
63
|
+
Check.no_new_posts(stream, options, 'explore:replies')
|
64
|
+
Databases.save_max_id(stream)
|
65
|
+
@view.render(stream, options)
|
66
|
+
Scroll.new(@api, @view).replies(options) if options[:scroll]
|
67
|
+
end
|
68
|
+
|
69
|
+
def mentions username, options
|
70
|
+
Check.no_username(username)
|
71
|
+
username = @workers.add_arobase(username)
|
72
|
+
@view.downloading(options)
|
73
|
+
stream = @api.get_mentions(username, options)
|
74
|
+
Check.no_user(stream, username)
|
75
|
+
Databases.save_max_id(stream)
|
76
|
+
Check.no_data(stream, 'mentions')
|
77
|
+
options = options.dup
|
78
|
+
options[:in_mentions] = true
|
79
|
+
@view.render(stream, options)
|
80
|
+
Scroll.new(@api, @view).mentions(username, options) if options[:scroll]
|
81
|
+
end
|
82
|
+
|
83
|
+
def posts username, options
|
84
|
+
Check.no_username(username)
|
85
|
+
username = @workers.add_arobase(username)
|
86
|
+
@view.downloading(options)
|
87
|
+
stream = @api.get_posts(username, options)
|
88
|
+
Check.no_user(stream, username)
|
89
|
+
Databases.save_max_id(stream)
|
90
|
+
Check.no_data(stream, 'mentions')
|
91
|
+
@view.render(stream, options)
|
92
|
+
Scroll.new(@api, @view).posts(username, options) if options[:scroll]
|
93
|
+
end
|
94
|
+
|
95
|
+
def whatstarred(username, options)
|
96
|
+
Check.no_username(username)
|
97
|
+
username = @workers.add_arobase(username)
|
98
|
+
@view.downloading(options)
|
99
|
+
stream = @api.get_whatstarred(username, options)
|
100
|
+
Check.no_user(stream, username)
|
101
|
+
Check.no_data(stream, 'whatstarred')
|
102
|
+
options[:extract] ? @view.all_stars_links(stream) : @view.render(stream, options)
|
103
|
+
end
|
104
|
+
|
105
|
+
def followings(username, options)
|
106
|
+
Check.no_username(username)
|
107
|
+
username = @workers.add_arobase(username)
|
108
|
+
@view.downloading(options)
|
109
|
+
show_raw_list(username, :followings, options)
|
110
|
+
list = @api.get_followings(username)
|
111
|
+
Check.auto_save_followings(list)
|
112
|
+
Errors.no_data('followings') if list.empty?
|
113
|
+
@view.list(:followings, list, username)
|
114
|
+
Databases.add_to_users_db_from_list(list)
|
115
|
+
end
|
116
|
+
|
117
|
+
def followers(username, options)
|
118
|
+
Check.no_username(username)
|
119
|
+
username = @workers.add_arobase(username)
|
120
|
+
@view.downloading(options)
|
121
|
+
show_raw_list(username, :followers, options)
|
122
|
+
list = @api.get_followers(username)
|
123
|
+
Check.auto_save_followers(list)
|
124
|
+
Errors.no_data('followers') if list.empty?
|
125
|
+
@view.list(:followers, list, username)
|
126
|
+
Databases.add_to_users_db_from_list(list)
|
127
|
+
end
|
128
|
+
|
129
|
+
def muted(options)
|
130
|
+
@view.downloading(options)
|
131
|
+
show_raw_list(nil, :muted, options)
|
132
|
+
list = @api.get_muted
|
133
|
+
Check.auto_save_muted(list)
|
134
|
+
Errors.no_data('muted') if list.empty?
|
135
|
+
@view.list(:muted, list, nil)
|
136
|
+
Databases.add_to_users_db_from_list(list)
|
137
|
+
end
|
138
|
+
|
139
|
+
def blocked(options)
|
140
|
+
@view.downloading(options)
|
141
|
+
show_raw_list(nil, :blocked, options)
|
142
|
+
list = @api.get_blocked
|
143
|
+
Errors.no_data('blocked') if list.empty?
|
144
|
+
@view.list(:blocked, list, nil)
|
145
|
+
Databases.add_to_users_db_from_list(list)
|
146
|
+
end
|
147
|
+
|
148
|
+
def interactions(options)
|
149
|
+
@view.downloading(options)
|
150
|
+
stream = @api.get_interactions
|
151
|
+
@view.if_raw(stream, options)
|
152
|
+
@view.clear_screen
|
153
|
+
@view.show_interactions(stream['data'])
|
154
|
+
end
|
155
|
+
|
156
|
+
def whoreposted(post_id, options)
|
157
|
+
Check.bad_post_id(post_id)
|
158
|
+
@view.downloading(options)
|
159
|
+
details = @api.get_details(post_id, options)
|
160
|
+
Check.no_post(details, post_id)
|
161
|
+
id = @workers.get_original_id(post_id, details)
|
162
|
+
list = @api.get_whoreposted(id)
|
163
|
+
@view.if_raw(list, options)
|
164
|
+
abort(Status.nobody_reposted) if list['data'].empty?
|
165
|
+
@view.list(:whoreposted, list['data'], post_id)
|
166
|
+
end
|
167
|
+
|
168
|
+
def whostarred(post_id, options)
|
169
|
+
Check.bad_post_id(post_id)
|
170
|
+
@view.downloading(options)
|
171
|
+
details = @api.get_details(post_id, options)
|
172
|
+
Check.no_post(details, post_id)
|
173
|
+
id = @workers.get_original_id(post_id, details)
|
174
|
+
list = @api.get_whostarred(id)
|
175
|
+
@view.if_raw(list, options)
|
176
|
+
abort(Status.nobody_starred) if list['data'].empty?
|
177
|
+
@view.list(:whostarred, list['data'], id)
|
178
|
+
end
|
179
|
+
|
180
|
+
def convo(post_id, options)
|
181
|
+
Check.bad_post_id(post_id)
|
182
|
+
@view.downloading(options)
|
183
|
+
details = @api.get_details(post_id, options)
|
184
|
+
Check.no_post(details, post_id)
|
185
|
+
id = @workers.get_original_id(post_id, details)
|
186
|
+
stream = @api.get_convo(id, options)
|
187
|
+
Check.no_post(stream, id)
|
188
|
+
Databases.pagination["replies:#{id}"] = stream['meta']['max_id']
|
189
|
+
options = options.dup
|
190
|
+
options[:reply_to] = details['data']['reply_to'].to_i unless details['data']['reply_to'].nil?
|
191
|
+
options[:post_id] = post_id.to_i
|
192
|
+
@view.render(stream, options)
|
193
|
+
Scroll.new(@api, @view).convo(id, options) if options[:scroll]
|
194
|
+
end
|
195
|
+
|
196
|
+
def messages(channel_id, options)
|
197
|
+
channel_id = @workers.get_channel_id_from_alias(channel_id)
|
198
|
+
@view.downloading(options)
|
199
|
+
resp = @api.get_messages(channel_id, options)
|
200
|
+
Check.no_new_posts(resp, options, "channel:#{channel_id}")
|
201
|
+
Databases.save_max_id(resp)
|
202
|
+
@view.if_raw(resp, options)
|
203
|
+
Check.no_data(resp, 'messages')
|
204
|
+
@view.render(resp, options)
|
205
|
+
Scroll.new(@api, @view).messages(channel_id, options) if options[:scroll]
|
206
|
+
end
|
207
|
+
|
208
|
+
def random_posts(options)
|
209
|
+
#_, cols = @view.winsize
|
210
|
+
#max_posts = cols / 16
|
211
|
+
max_posts = 6
|
212
|
+
@view.clear_screen
|
213
|
+
puts "Fetching random posts, please wait...".color(:cyan)
|
214
|
+
@max_id = @api.get_global({count: 1})['meta']['max_id'].to_i
|
215
|
+
@view.clear_screen
|
216
|
+
counter = 1
|
217
|
+
wait = options[:wait] || 5
|
218
|
+
loop do
|
219
|
+
begin
|
220
|
+
@random_post_id = rand(@max_id)
|
221
|
+
@resp = @api.get_details(@random_post_id, {})
|
222
|
+
next if @resp['data']['is_deleted']
|
223
|
+
@view.show_simple_post([@resp['data']], {})
|
224
|
+
counter += 1
|
225
|
+
if counter == max_posts
|
226
|
+
wait.downto(1) do |i|
|
227
|
+
print "\r#{sprintf("%02d", i)} sec... QUIT WITH [CTRL+C]".color(:cyan)
|
228
|
+
sleep 1
|
229
|
+
end
|
230
|
+
@view.clear_screen
|
231
|
+
counter = 1
|
232
|
+
end
|
233
|
+
rescue Interrupt
|
234
|
+
abort(Status.canceled)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
private
|
240
|
+
|
241
|
+
def show_raw_list username, what, options
|
242
|
+
if options[:raw]
|
243
|
+
@view.show_raw(@api.get_raw_list(username, what), options)
|
244
|
+
exit
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
def nicerank_true
|
249
|
+
return true if Settings.options[:nicerank][:filter] == true
|
250
|
+
end
|
251
|
+
|
252
|
+
end
|
253
|
+
|
254
|
+
end
|
data/lib/ayadn/switch.rb
CHANGED
@@ -32,7 +32,7 @@ module Ayadn
|
|
32
32
|
exit
|
33
33
|
end
|
34
34
|
#puts "\e[H\e[2J"
|
35
|
-
username = Workers.remove_arobase_if_present([user.first])[0]
|
35
|
+
username = Workers.new.remove_arobase_if_present([user.first])[0]
|
36
36
|
home_path = Dir.home + "/ayadn"
|
37
37
|
if File.exist?("#{home_path}/accounts.db")
|
38
38
|
accounts_db = Databases.init("#{home_path}/accounts.db")
|
data/lib/ayadn/tvshow.rb
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Ayadn
|
3
|
+
|
4
|
+
class TvShow
|
5
|
+
|
6
|
+
require 'tvdb_party'
|
7
|
+
|
8
|
+
AYADN_TVDB_API_KEY = '3F21527FE4C9C274'
|
9
|
+
|
10
|
+
attr_accessor :language, :name, :poster_url, :banner_url, :plot, :text, :imdb_link, :tag, :link, :date
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@language = 'en'
|
14
|
+
@view = View.new
|
15
|
+
@tvdb = TvdbParty::Search.new(AYADN_TVDB_API_KEY)
|
16
|
+
end
|
17
|
+
|
18
|
+
def find title
|
19
|
+
res = find_all(title)
|
20
|
+
abort(Status.no_show) if res[0].nil?
|
21
|
+
if res[0].has_key?('FirstAired')
|
22
|
+
return @tvdb.get_series_by_id(res[0]['seriesid'])
|
23
|
+
else
|
24
|
+
return @tvdb.get_series_by_id(res[1]['seriesid']) unless res[1].nil?
|
25
|
+
end
|
26
|
+
abort(Status.no_show)
|
27
|
+
end
|
28
|
+
|
29
|
+
def find_alt title
|
30
|
+
res = find_all(title)
|
31
|
+
abort(Status.no_show) if res[0].nil?
|
32
|
+
if res[0].has_key?('FirstAired')
|
33
|
+
return @tvdb.get_series_by_id(res[1]['seriesid']) unless res[1].nil?
|
34
|
+
else
|
35
|
+
return @tvdb.get_series_by_id(res[2]['seriesid']) unless res[2].nil?
|
36
|
+
end
|
37
|
+
abort(Status.no_show)
|
38
|
+
end
|
39
|
+
|
40
|
+
def create_details show_obj
|
41
|
+
@name = show_obj.name
|
42
|
+
@poster_url = find_poster_url(show_obj)
|
43
|
+
@banner_url = find_banner_url(show_obj)
|
44
|
+
@plot = find_plot(show_obj)
|
45
|
+
@date = show_obj.first_aired.year
|
46
|
+
@imdb_link = "http://imdb.com/title/#{show_obj.imdb_id}/"
|
47
|
+
create_text()
|
48
|
+
return self
|
49
|
+
end
|
50
|
+
|
51
|
+
def create_text
|
52
|
+
@link = "[IMDb](#{@imdb_link})"
|
53
|
+
@tag = Settings.options[:tvshow][:hashtag]
|
54
|
+
@date.nil? ? date = '' : date = "(#{@date})"
|
55
|
+
pre = "#{@name} #{date}\n \n"
|
56
|
+
presize = pre.length + @tag.length + 4 + @plot.length
|
57
|
+
max = 241
|
58
|
+
if presize > max
|
59
|
+
plot_max = max - (pre.length + @tag.length)
|
60
|
+
@text = "#{pre}#{@plot[0..plot_max]}...\n \n#{@link}\n \n##{@tag}"
|
61
|
+
else
|
62
|
+
@text = "#{pre}#{@plot}\n \n#{@link}\n \n##{@tag}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def ok
|
67
|
+
@view.clear_screen
|
68
|
+
puts "\nYour post:\n\n".color(:cyan)
|
69
|
+
puts @text
|
70
|
+
puts "\n\nIs it ok? (y/N)".color(:yellow)
|
71
|
+
STDIN.getch == ("y" || "Y") ? true : false
|
72
|
+
end
|
73
|
+
|
74
|
+
def post options = {}
|
75
|
+
reg = /[~:-;,?!\'&`^=+<>*%()\/"“”’°£$€.…]/
|
76
|
+
filename = "#{@name.downcase.strip.gsub(reg, '_').split(' ').join('_')}.jpg"
|
77
|
+
if options['banner']
|
78
|
+
FileOps.download_url(filename, @banner_url)
|
79
|
+
else
|
80
|
+
FileOps.download_url(filename, @poster_url)
|
81
|
+
end
|
82
|
+
@view.clear_screen
|
83
|
+
puts "\nPosting and uploading the show poster...\n".color(:green)
|
84
|
+
file = ["#{Settings.config[:paths][:downloads]}/#{filename}"]
|
85
|
+
dic = {
|
86
|
+
'text' => @text,
|
87
|
+
'data' => FileOps.upload_files(file),
|
88
|
+
'title' => @name,
|
89
|
+
'source' => 'TVDb'
|
90
|
+
}
|
91
|
+
resp = Post.new.send_tvshow(dic)
|
92
|
+
FileOps.save_post(resp) if Settings.options[:backup][:auto_save_sent_posts]
|
93
|
+
@view.clear_screen
|
94
|
+
puts Status.yourpost
|
95
|
+
@view.show_posted(resp)
|
96
|
+
end
|
97
|
+
|
98
|
+
def cancel
|
99
|
+
abort(Status.canceled)
|
100
|
+
end
|
101
|
+
|
102
|
+
private
|
103
|
+
|
104
|
+
def find_all title
|
105
|
+
@tvdb.search(title)
|
106
|
+
end
|
107
|
+
|
108
|
+
def find_poster_url show_obj
|
109
|
+
poster = show_obj.posters(@language).first
|
110
|
+
poster.nil? ? abort(Status.no_show_infos) : poster.url
|
111
|
+
end
|
112
|
+
|
113
|
+
def find_banner_url show_obj
|
114
|
+
banner = show_obj.series_banners(@language).first
|
115
|
+
banner.nil? ? abort(Status.no_show_infos) : banner.url
|
116
|
+
end
|
117
|
+
|
118
|
+
def find_plot show_obj
|
119
|
+
show_obj.overview
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
end
|