ayadn 3.0 → 4.0

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.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -4
  3. data/CHANGELOG.md +12 -4
  4. data/README.md +2 -5
  5. data/ayadn.gemspec +0 -2
  6. data/doc/01-index.md +0 -3
  7. data/doc/02-install.md +0 -4
  8. data/doc/06-post.md +0 -16
  9. data/doc/{18-contact.md → 16-contact.md} +0 -0
  10. data/doc/{19-examples.md → 17-examples.md} +0 -0
  11. data/doc/18-develop.md +165 -0
  12. data/lib/ayadn/action.rb +206 -396
  13. data/lib/ayadn/alias.rb +1 -1
  14. data/lib/ayadn/annotations.rb +15 -27
  15. data/lib/ayadn/api.rb +39 -28
  16. data/lib/ayadn/app.rb +19 -29
  17. data/lib/ayadn/authorize.rb +22 -13
  18. data/lib/ayadn/blacklist.rb +6 -19
  19. data/lib/ayadn/channel_object.rb +75 -0
  20. data/lib/ayadn/check.rb +19 -11
  21. data/lib/ayadn/cnx.rb +9 -15
  22. data/lib/ayadn/databases.rb +15 -27
  23. data/lib/ayadn/debug.rb +9 -9
  24. data/lib/ayadn/descriptions.rb +1 -99
  25. data/lib/ayadn/diagnostics.rb +16 -15
  26. data/lib/ayadn/endpoints.rb +18 -22
  27. data/lib/ayadn/errors.rb +1 -1
  28. data/lib/ayadn/fileops.rb +12 -12
  29. data/lib/ayadn/filtered_post_object.rb +11 -0
  30. data/lib/ayadn/ids.rb +0 -3
  31. data/lib/ayadn/logs.rb +4 -4
  32. data/lib/ayadn/mark.rb +34 -30
  33. data/lib/ayadn/nicerank.rb +7 -7
  34. data/lib/ayadn/nowplaying.rb +8 -22
  35. data/lib/ayadn/pinboard.rb +8 -12
  36. data/lib/ayadn/post.rb +18 -18
  37. data/lib/ayadn/post_object.rb +118 -0
  38. data/lib/ayadn/preferences_object.rb +290 -0
  39. data/lib/ayadn/profile.rb +2 -2
  40. data/lib/ayadn/scroll.rb +58 -67
  41. data/lib/ayadn/search.rb +22 -15
  42. data/lib/ayadn/set.rb +93 -83
  43. data/lib/ayadn/settings.rb +25 -33
  44. data/lib/ayadn/status.rb +24 -26
  45. data/lib/ayadn/stream.rb +68 -66
  46. data/lib/ayadn/stream_object.rb +56 -0
  47. data/lib/ayadn/switch.rb +2 -2
  48. data/lib/ayadn/user_object.rb +116 -0
  49. data/lib/ayadn/version.rb +1 -1
  50. data/lib/ayadn/view.rb +255 -278
  51. data/lib/ayadn/workers.rb +172 -174
  52. data/spec/integration/action_spec.rb +55 -34
  53. data/spec/mock/ayadn.sqlite +0 -0
  54. data/spec/unit/annotations_spec.rb +54 -41
  55. data/spec/unit/api_spec.rb +78 -7
  56. data/spec/unit/blacklistworkers_spec.rb +92 -20
  57. data/spec/unit/databases_spec.rb +117 -36
  58. data/spec/unit/endpoints_spec.rb +82 -10
  59. data/spec/unit/nicerank_spec.rb +56 -27
  60. data/spec/unit/post_spec.rb +94 -21
  61. data/spec/unit/set_spec.rb +141 -210
  62. data/spec/unit/view_spec.rb +105 -32
  63. data/spec/unit/workers_spec.rb +143 -52
  64. metadata +12 -37
  65. data/doc/16-movie.md +0 -39
  66. data/doc/17-tvshow.md +0 -46
  67. data/lib/ayadn/nowwatching.rb +0 -118
  68. data/lib/ayadn/tvshow.rb +0 -162
data/doc/16-movie.md DELETED
@@ -1,39 +0,0 @@
1
- # MOVIE (nowwatching)
2
-
3
- Create a post from (part of) a movie title.
4
-
5
- Includes movie poster, IMDb url and hashtag.
6
-
7
- Usage:
8
-
9
- `ayadn movie ghost in the shell`
10
-
11
- `ayadn movie existenz`
12
-
13
- `ayadn -NW beetlejuice`
14
-
15
- (shortcut is 'NW' because of 'nowwatching')
16
-
17
- ## ALT
18
-
19
- If the movie is not the one you're looking for, you can specify the 'alt' option to force find an alternative.
20
-
21
- This is useful for remakes:
22
-
23
- `ayadn -NW solaris`
24
-
25
- (gives the 2002 version)
26
-
27
- `ayadn -NW solaris --alt`
28
-
29
- (gives the 1972 version)
30
-
31
- ## HASHTAG
32
-
33
- You can modify the default hashtag with 'set':
34
-
35
- `ayadn set movie hashtag movietime`
36
-
37
- `ayadn set movie hashtag adnmovieclub`
38
-
39
- (default is 'nowwatching')
data/doc/17-tvshow.md DELETED
@@ -1,46 +0,0 @@
1
- # TVSHOW (nowwatching)
2
-
3
- Create a post from (part of) a TV show title.
4
-
5
- Includes show poster, IMDb url and hashtag.
6
-
7
- Usage:
8
-
9
- `ayadn tvshow game of thrones`
10
-
11
- `ayadn tvshow magnum`
12
-
13
- `ayadn -TV 24`
14
-
15
- ## ALT
16
-
17
- If the show is not the one you're looking for, you can specify the 'alt' option to force find an alternative.
18
-
19
- `ayadn -TV whose line`
20
-
21
- (gives the US version)
22
-
23
- `ayadn -TV whose line --alt`
24
-
25
- (gives the UK version)
26
-
27
- ## HASHTAG
28
-
29
- You can modify the hashtag with 'set':
30
-
31
- `ayadn set tvshow hashtag showtime`
32
-
33
- `ayadn set tvshow hashtag tvshow`
34
-
35
- (default is 'nowwatching')
36
-
37
- ## BANNER
38
-
39
- You can display a banner instead of a poster, with the `--banner` (`-b`) option:
40
-
41
- ```
42
- ayadn -TV magnum --banner
43
- ayadn -TV -b magnum
44
- ```
45
-
46
-
@@ -1,118 +0,0 @@
1
- # encoding: utf-8
2
- module Ayadn
3
-
4
- class NowWatching
5
-
6
- begin
7
- require 'spotlite'
8
- rescue LoadError => e
9
- puts "\nAYADN: Error while loading an external resource\n\n"
10
- puts "RUBY: #{e}\n\n"
11
- exit
12
- end
13
-
14
- def initialize view = nil
15
- @view = view
16
- @spotlite = Spotlite::Movie
17
- @status = Status.new
18
- end
19
-
20
- # -----
21
-
22
- def get_response args, options
23
- find_by_title(args, options)
24
- end
25
-
26
- def create_filename response
27
- reg = /[~:-;,?!\'&`^=+<>*%()\/"“”’°£$€.…]/
28
- "#{response.title.downcase.strip.gsub(reg, '_').split(' ').join('_')}.jpg"
29
- end
30
-
31
- # This is only for the `-M` option in the CLI
32
- def get_poster args, options
33
- options = options.dup
34
- response = get_response(args, options)
35
- filename = create_filename(response)
36
- FileOps.download_url(filename, response.poster_url)
37
- options[:embed] ||= []
38
- options[:embed] << "#{Settings.config[:paths][:downloads]}/#{filename}"
39
- return options
40
- end
41
-
42
- # -----
43
-
44
- def post args, options
45
- options = options.dup
46
- @status.info("connected", "IMDb", "yellow")
47
- response = find_by_title(args, options)
48
- text = format_post(response)
49
- show_post(text)
50
- filename = create_filename(response)
51
- FileOps.download_url(filename, response.poster_url)
52
- @view.clear_screen
53
- @status.info("uploading", "movie poster", "yellow")
54
- options[:embed] = ["#{Settings.config[:paths][:downloads]}/#{filename}"]
55
- options[:movie] = true
56
- dic = {
57
- options: options,
58
- text: text,
59
- title: response.title,
60
- source: 'IMDb'
61
- }
62
- resp = Post.new.post(dic)
63
- FileOps.save_post(resp) if Settings.options[:backup][:posts]
64
- @view.clear_screen
65
- @status.yourpost
66
- puts "\n\n"
67
- @view.show_posted(resp)
68
- end
69
-
70
- def find_by_title args, options = {}
71
- resp = @spotlite.find(args.join(' '))
72
- if options['alt']
73
- resp[1]
74
- else
75
- resp[0]
76
- end
77
- end
78
-
79
- def format_post response
80
- tag = Settings.options[:movie][:hashtag]
81
- text_1 = "'#{response.title}' (#{response.year})"
82
- link = "[IMDb](#{response.url})"
83
- plot = format_plot(response, text_1)
84
- "#{text_1}\n \n#{plot}\n \n#{link}\n \n##{tag}\n\n"
85
- end
86
-
87
- def format_plot response, text
88
- max = 239 - (text.length + Settings.options[:movie][:hashtag].length)
89
- short = max - 3
90
- plot = response.description
91
- if plot.length > max
92
- "#{plot[0..short]}..."
93
- else
94
- plot
95
- end
96
- end
97
-
98
- private
99
-
100
- def show_post text
101
- @view.clear_screen
102
- @status.writing
103
- @status.to_be_posted
104
- thor = Thor::Shell::Basic.new
105
- puts "\n"
106
- text.split("\n").each do |line|
107
- thor.say_status(nil, line.color(Settings.options[:colors][:excerpt]))
108
- end
109
- puts "\n"
110
- @status.ok?
111
- unless STDIN.getch == ("y" || "Y")
112
- @status.canceled
113
- exit
114
- end
115
- end
116
-
117
- end
118
- end
data/lib/ayadn/tvshow.rb DELETED
@@ -1,162 +0,0 @@
1
- # encoding: utf-8
2
- module Ayadn
3
-
4
- class TvShow
5
-
6
- # Warning
7
- # comment next line
8
- require_relative "ids"
9
- # uncomment and insert your own id
10
- # TVDB_API_KEY = ""
11
-
12
- begin
13
- require 'tvdb_party'
14
- rescue LoadError => e
15
- puts "\nAYADN: Error while loading an external resource\n\n"
16
- puts "RUBY: #{e}\n\n"
17
- exit
18
- end
19
-
20
- attr_accessor :language, :name, :poster_url, :banner_url, :plot, :text, :imdb_link, :tag, :link, :date
21
-
22
- def initialize
23
- @language = 'en'
24
- @view = View.new
25
- @tvdb = TvdbParty::Search.new(TVDB_API_KEY)
26
- @status = Status.new
27
- end
28
-
29
- def find title
30
- res = find_all(title)
31
- if res[0].nil?
32
- @status.no_show
33
- exit
34
- end
35
- if res[0].has_key?('FirstAired')
36
- return @tvdb.get_series_by_id(res[0]['seriesid'])
37
- else
38
- return @tvdb.get_series_by_id(res[1]['seriesid']) unless res[1].nil?
39
- end
40
- @status.no_show
41
- exit
42
- end
43
-
44
- def find_alt title
45
- res = find_all(title)
46
- if res[0].nil?
47
- @status.no_show
48
- exit
49
- end
50
- if res[0].has_key?('FirstAired')
51
- return @tvdb.get_series_by_id(res[1]['seriesid']) unless res[1].nil?
52
- else
53
- return @tvdb.get_series_by_id(res[2]['seriesid']) unless res[2].nil?
54
- end
55
- @status.no_show
56
- exit
57
- end
58
-
59
- def create_details show_obj
60
- @name = show_obj.name
61
- @poster_url = find_poster_url(show_obj)
62
- @banner_url = find_banner_url(show_obj)
63
- @plot = find_plot(show_obj)
64
- @date = show_obj.first_aired.year
65
- @imdb_link = "http://imdb.com/title/#{show_obj.imdb_id}/"
66
- create_text()
67
- return self
68
- end
69
-
70
- def create_text
71
- @link = "[IMDb](#{@imdb_link})"
72
- @tag = Settings.options[:tvshow][:hashtag]
73
- @date.nil? ? date = '' : date = "(#{@date})"
74
- pre = "#{@name} #{date}\n \n"
75
- presize = pre.length + @tag.length + 4 + @plot.length
76
- max = 241
77
- if presize > max
78
- plot_max = max - (pre.length + @tag.length)
79
- @text = "#{pre}#{@plot[0..plot_max]}...\n \n#{@link}\n \n##{@tag}"
80
- else
81
- @text = "#{pre}#{@plot}\n \n#{@link}\n \n##{@tag}"
82
- end
83
- end
84
-
85
- def ok
86
- @view.clear_screen
87
- @status.writing
88
- @status.to_be_posted
89
- thor = Thor::Shell::Basic.new
90
- puts "\n"
91
- @text.split("\n").each do |line|
92
- thor.say_status(nil, line.color(Settings.options[:colors][:excerpt]))
93
- end
94
- puts "\n"
95
- @status.ok?
96
- STDIN.getch == ("y" || "Y") ? true : false
97
- end
98
-
99
- def post options = {}
100
- options = options.dup
101
- reg = /[~:-;,?!\'&`^=+<>*%()\/"“”’°£$€.…]/
102
- filename = "#{@name.downcase.strip.gsub(reg, '_').split(' ').join('_')}.jpg"
103
- if options['banner']
104
- FileOps.download_url(filename, @banner_url)
105
- else
106
- FileOps.download_url(filename, @poster_url)
107
- end
108
- @view.clear_screen
109
- @status.info("uploading", "show poster", "yellow")
110
- options[:embed] = ["#{Settings.config[:paths][:downloads]}/#{filename}"]
111
- options[:tvshow] = true
112
- dic = {
113
- options: options,
114
- text: @text,
115
- title: @name,
116
- source: 'TVDb'
117
- }
118
- resp = Post.new.post(dic)
119
- FileOps.save_post(resp) if Settings.options[:backup][:posts]
120
- @view.clear_screen
121
- @status.yourpost
122
- puts "\n\n"
123
- @view.show_posted(resp)
124
- end
125
-
126
- def cancel
127
- @status.canceled
128
- exit
129
- end
130
-
131
- private
132
-
133
- def find_all title
134
- @tvdb.search(title)
135
- end
136
-
137
- def find_poster_url show_obj
138
- poster = show_obj.posters(@language).first
139
- if poster.nil?
140
- @status.no_show_infos
141
- exit
142
- else
143
- poster.url
144
- end
145
- end
146
-
147
- def find_banner_url show_obj
148
- banner = show_obj.series_banners(@language).first
149
- if banner.nil?
150
- @status.no_show_infos
151
- exit
152
- else
153
- banner.url
154
- end
155
- end
156
-
157
- def find_plot show_obj
158
- show_obj.overview
159
- end
160
-
161
- end
162
- end