glyr 0.9.9 → 0.9.9.1

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.
data/README.md CHANGED
@@ -1,2 +1,41 @@
1
1
  ruby-glyr - Ruby wrapper for glyr.
2
2
  ==================================
3
+ This is just a simple wrapper library for libglyr.
4
+
5
+ Example
6
+ -------
7
+
8
+ ```ruby
9
+ >> require 'glyr'
10
+ >> Glyr.query(title: 'The Dead Flag Blues', artist: 'Godspeed You! Black Emperor').lyrics.first
11
+ => The car's on fire and there's no driver at the wheel
12
+ And the sewers are all muddied with a thousand lonely suicides
13
+ And a dark wind blows
14
+
15
+ The government is corrupt
16
+ And we're on so many drugs
17
+ With the radio on and the curtains drawn
18
+ We're trapped in the belly of this horrible machine
19
+ And the machine is bleeding to death
20
+ The sun has fallen down
21
+ And the billboards are all leering
22
+ And the flags are all dead at the top of their poles
23
+ It went like this:
24
+ The buildings tumbled in on themselves
25
+ Mothers clutching babies picked through the rubble
26
+ And pulled out their hair
27
+
28
+ The skyline was beautiful on fire
29
+ All twisted metal stretching upwards
30
+ Everything washed in a thin orange haze
31
+
32
+ I said: "kiss me, you're beautiful -
33
+ These are truly the last days"
34
+ You grabbed my hand and we fell into it
35
+ Like a daydream or a fever
36
+ We woke up one morning and fell a little further down -
37
+ For sure it's the valley of death
38
+
39
+ I open up my wallet
40
+ And it's full of blood
41
+ ```
@@ -12,4 +12,17 @@ require 'glyr/c'
12
12
 
13
13
  require 'glyr/version'
14
14
  require 'glyr/query'
15
- require 'glyr/result'
15
+ require 'glyr/results'
16
+ require 'glyr/providers'
17
+ require 'glyr/sources'
18
+
19
+ module Glyr
20
+ # helper to create a Query object
21
+ def self.query (options = {})
22
+ Query.create(options)
23
+ end
24
+
25
+ def self.providers
26
+ @providers ||= Providers.create
27
+ end
28
+ end
@@ -0,0 +1,96 @@
1
+ #--
2
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
+ # Version 2, December 2004
4
+ #
5
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
+ #
8
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
+ #++
10
+
11
+ module Glyr
12
+
13
+ class Providers
14
+ def self.create
15
+ pointer = C.glyr_info_get
16
+
17
+ wrap(pointer)
18
+ end
19
+
20
+ def self.wrap (pointer)
21
+ new(pointer).tap {|x|
22
+ ObjectSpace.define_finalizer x, finalizer(pointer)
23
+ }
24
+ end
25
+
26
+ def self.finalizer (pointer)
27
+ proc {
28
+ C.glyr_info_free(pointer)
29
+ }
30
+ end
31
+
32
+ include Enumerable
33
+
34
+ def initialize (pointer)
35
+ @internal = pointer.is_a?(FFI::Pointer) ? C::FetcherInfo.new(pointer) : pointer
36
+ end
37
+
38
+ def each (&block)
39
+ current = @internal
40
+
41
+ until current.null?
42
+ block.call(Provider.new(current, self))
43
+
44
+ current = C::FetcherInfo.new(current[:next])
45
+ end
46
+ end
47
+
48
+ def [] (name)
49
+ find { |p| p.name == name || p.type == name }
50
+ end
51
+
52
+ def to_hash
53
+ Hash[map { |p| [p.to_sym, p] }]
54
+ end
55
+
56
+ def to_native
57
+ @internal
58
+ end
59
+ end
60
+
61
+ class Provider
62
+ def initialize (pointer, providers)
63
+ @internal = pointer.is_a?(FFI::Pointer) ? C::FetcherInfo.new(pointer) : pointer
64
+ @providers = providers
65
+ end
66
+
67
+ def name
68
+ to_native[:name]
69
+ end
70
+
71
+ def type
72
+ to_native[:type]
73
+ end
74
+
75
+ def requirements
76
+ FieldRequirements[to_native[:reqs]]
77
+ end
78
+
79
+ def sources
80
+ Sources.new(to_native[:head], self)
81
+ end
82
+
83
+ alias to_s name
84
+
85
+ alias to_sym type
86
+
87
+ def to_native
88
+ @internal
89
+ end
90
+
91
+ def inspect
92
+ "#<Glyr::Provider(#{name}): #{requirements}>"
93
+ end
94
+ end
95
+
96
+ end
@@ -11,13 +11,13 @@
11
11
  module Glyr
12
12
 
13
13
  class Query
14
+ # create a Query object with the passed options
14
15
  def self.create (options = {})
15
16
  struct = C::Query.new
16
17
 
17
18
  C.glyr_query_init(struct.pointer)
18
19
 
19
20
  wrap(struct.pointer, options)
20
-
21
21
  end
22
22
 
23
23
  def self.wrap (pointer, options = {})
@@ -26,7 +26,7 @@ class Query
26
26
  }
27
27
  end
28
28
 
29
- def self.finalizer (pointer)
29
+ def self.finalizer (pointer) # :nodoc:
30
30
  proc {
31
31
  C.glyr_query_destroy(pointer)
32
32
  }
@@ -46,84 +46,206 @@ class Query
46
46
  }
47
47
  end
48
48
 
49
- def type (value)
50
- raise_if_error C.glyr_opt_type(to_native, value.is_a?(Symbol) ? value : C::GetType[value])
49
+ # tell the Query what you want to get
50
+ def type (value = nil)
51
+ if value
52
+ raise_if_error C.glyr_opt_type(to_native, value.is_a?(Symbol) ? value : C::GetType[value])
53
+ else
54
+ to_native[:type]
55
+ end
51
56
  end
52
57
 
53
- def artist (value)
54
- raise_if_error C.glyr_opt_artist(to_native, value)
58
+ # set the artist
59
+ def artist (value = nil)
60
+ if value
61
+ raise_if_error C.glyr_opt_artist(to_native, value)
62
+ else
63
+ to_native[:artist]
64
+ end
55
65
  end
56
66
 
57
- def album (value)
58
- raise_if_error C.glyr_opt_album(to_native, value)
67
+ # set the album
68
+ def album (value = nil)
69
+ if value
70
+ raise_if_error C.glyr_opt_album(to_native, value)
71
+ else
72
+ to_native[:album]
73
+ end
59
74
  end
60
75
 
61
- def title (value)
62
- raise_if_error C.glyr_opt_title(to_native, value)
76
+ # set the title
77
+ def title (value = nil)
78
+ if value
79
+ raise_if_error C.glyr_opt_title(to_native, value)
80
+ else
81
+ to_native[:title]
82
+ end
63
83
  end
64
84
 
65
- def parallel (value)
66
- raise_if_error C.glyr_opt_parallel(to_native, value)
85
+ # set the image size boundaries
86
+ def image_boundaries (min = nil, max = min)
87
+ if min && max
88
+ raise_if_error C.glyr_opt_img_minsize(to_native, min)
89
+ raise_if_error C.glyr_opt_img_maxsize(to_native, max)
90
+ else
91
+ [to_native[:img_min_size], to_native[:img_max_size]]
92
+ end
67
93
  end
68
94
 
69
- def timeout (value)
70
- raise_if_error C.glyr_opt_timeout(to_native, value)
95
+ # set the number of parallel searches
96
+ def parallel (value = nil)
97
+ if value
98
+ raise_if_error C.glyr_opt_parallel(to_native, value)
99
+ else
100
+ to_native[:parallel]
101
+ end
71
102
  end
72
103
 
73
- def redirects (value)
74
- raise_if_error C.glyr_opt_redirects(to_native, value)
104
+ # set the timeout for the searching
105
+ def timeout (value = nil)
106
+ if value
107
+ raise_if_error C.glyr_opt_timeout(to_native, value)
108
+ else
109
+ to_native[:timeout]
110
+ end
75
111
  end
76
112
 
77
- def user_agent (value)
78
- raise_if_error C.glyr_opt_useragent(to_native, value)
113
+ # set the max amount of redirects
114
+ def redirects (value = nil)
115
+ if value
116
+ raise_if_error C.glyr_opt_redirects(to_native, value)
117
+ else
118
+ to_native[:redirects]
119
+ end
79
120
  end
80
121
 
81
- def language (value)
82
- raise_if_error C.glyr_opt_lang(to_native, value)
122
+ # set the user agent to use
123
+ def user_agent (value = nil)
124
+ if value
125
+ raise_if_error C.glyr_opt_useragent(to_native, value)
126
+ else
127
+ to_native[:useragent]
128
+ end
129
+ end
130
+
131
+ # set or get the language to search for
132
+ def language (value = nil)
133
+ if value
134
+ raise_if_error C.glyr_opt_lang(to_native, value)
135
+ else
136
+ to_native[:lang]
137
+ end
83
138
  end
84
139
 
140
+ def language_aware?
141
+ to_native[:lang_aware_only]
142
+ end
143
+
144
+ # only fetch from language aware providers
85
145
  def language_aware!
86
146
  raise_if_error C.glyr_opt_lang_aware_only(to_native, true)
87
147
  end
88
148
 
149
+ # don't force language aware providers
89
150
  def no_language_aware!
90
151
  raise_if_error C.glyr_opt_lang_aware_only(to_native, false)
91
152
  end
92
153
 
93
- def number (value)
94
- raise_if_error C.glyr_opt_number(to_native, value)
154
+ # set the maximum number of results
155
+ def maximum (value = nil)
156
+ if value
157
+ raise_if_error C.glyr_opt_number(to_native, value)
158
+ else
159
+ to_native[:number]
160
+ end
161
+ end
162
+
163
+ # set the maximum number of results per provider
164
+ def maximum_per_provider (value = nil)
165
+ if value
166
+ raise_if_error C.glyr_opt_plugmax(to_native, value)
167
+ else
168
+ to_native[:plugmax]
169
+ end
95
170
  end
96
171
 
97
- def verbosity (value)
98
- raise_if_error C.glyr_opt_verbosity(to_native, value)
172
+ # set the level of verbosity
173
+ def verbosity (value = nil)
174
+ if value
175
+ raise_if_error C.glyr_opt_verbosity(to_native, value)
176
+ else
177
+ to_native[:verbosity]
178
+ end
99
179
  end
100
180
 
181
+ # use only the passed providers (you can use all and disable single providers by prefixing
182
+ # them with a -)
101
183
  def from (*providers)
102
- raise_if_error C.glyr_opt_from(to_native, providers.flatten.compact.uniq.join(';'))
184
+ unless providers.empty?
185
+ raise_if_error C.glyr_opt_from(to_native, providers.flatten.compact.uniq.join(';'))
186
+ else
187
+ to_native[:from] && to_native[:from].split(/\s*;\s*/)
188
+ end
103
189
  end
104
190
 
191
+ # use only the passed formats
105
192
  def allowed_formats (*formats)
106
- raise_if_error C.glyr_opt_allowed_formats(to_native, formats.flatten.compact.uniq.join(';'))
193
+ unless formats.empty?
194
+ raise_if_error C.glyr_opt_allowed_formats(to_native, formats.flatten.compact.uniq.join(';'))
195
+ else
196
+ to_native[:allowed_formats] && to_native[:allowed_formats].split(/\s*;\s*/)
197
+ end
107
198
  end
108
199
 
200
+ def download?
201
+ to_native[:download]
202
+ end
203
+
204
+ # download the data instead of just passing a URL
109
205
  def download!
110
206
  raise_if_error C.glyr_opt_download(to_native, true)
111
207
  end
112
208
 
209
+ # don't download the data, just pass the URL
113
210
  def no_download!
114
211
  raise_if_error C.glyr_opt_download(to_native, false)
115
212
  end
116
213
 
117
- def fuzzyness (value)
118
- raise_if_error C.glyr_opt_fuzzyness(to_native, value)
214
+ def fuzzyness (value = nil)
215
+ if value
216
+ raise_if_error C.glyr_opt_fuzzyness(to_native, value)
217
+ else
218
+ to_native[:fuzzyness]
219
+ end
119
220
  end
120
221
 
121
- def ratio (value)
122
- raise_if_error C.glyr_opt_qsratio(to_native, value)
222
+ def ratio (value = nil)
223
+ if value
224
+ raise_if_error C.glyr_opt_qsratio(to_native, value)
225
+ else
226
+ to_native[:qsratio]
227
+ end
123
228
  end
124
229
 
125
- def proxy (value)
126
- raise_if_error C.glyr_opt_proxy(to_native, value)
230
+ # use the passed proxy to fetch the stuff
231
+ def proxy (value = nil)
232
+ if value
233
+ raise_if_error C.glyr_opt_proxy(to_native, value)
234
+ else
235
+ to_native[:proxy]
236
+ end
237
+ end
238
+
239
+ def path (value = nil)
240
+ if value
241
+ raise_if_error C.glyr_opt_musictree_path(to_native, vlaue)
242
+ else
243
+ to_native[:musictree_path]
244
+ end
245
+ end
246
+
247
+ def force_utf8?
248
+ to_native[:force_utf8]
127
249
  end
128
250
 
129
251
  def force_utf8!
@@ -134,33 +256,53 @@ class Query
134
256
  raise_if_error C.glyr_opt_force_utf8(to_native, false)
135
257
  end
136
258
 
137
- def get
259
+ def get (&block)
138
260
  error = FFI::MemoryPointer.new :int
139
- result = C.glyr_get(to_native, error, nil)
261
+ length = FFI::MemoryPointer.new :int
262
+
263
+ if block
264
+ raise_if_error C.glyr_opt_dlcallback(to_native, proc {|data, query|
265
+ result = block.call(Result.copy(C::MemCache.new(data)))
266
+
267
+ if result.respond_to? :to_i
268
+ C::Error[result.to_i]
269
+ elsif result.respond_to? :to_sym
270
+ result.to_sym.downcase
271
+ else
272
+ :ok
273
+ end
274
+ }, nil)
275
+ else
276
+ C.glyr_opt_dlcallback(to_native, nil, nil)
277
+ end
278
+
279
+ result = C.glyr_get(to_native, error, length)
140
280
 
141
281
  raise_if_error error.typecast(:int)
142
282
 
143
- Result.wrap(result)
283
+ Results.wrap(result, length.typecast(:int))
144
284
  end
145
285
 
146
286
  %w[cover_art lyrics artist_photos artist_bio similar_artists similar_songs album_reviews tracklist tags relations album_list guitar_tabs backdrops].each {|name|
147
287
  name = name.to_sym
148
288
 
149
- define_method name do
150
- type(name).get
289
+ define_method name do |&block|
290
+ type(name).get(&block)
151
291
  end
152
292
  }
153
293
 
294
+ # stop the current fetching
154
295
  def stop
155
296
  C.glyr_signal_exit(to_native)
156
297
  end
157
298
 
299
+ # get the FFI::Struct
158
300
  def to_native
159
301
  @internal
160
302
  end
161
303
 
162
304
  private
163
- def raise_if_error (value)
305
+ def raise_if_error (value) # :nodoc:
164
306
  value = C::Error[value] unless value.is_a? Symbol
165
307
 
166
308
  if value != :ok
@@ -0,0 +1,216 @@
1
+ #--
2
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
+ # Version 2, December 2004
4
+ #
5
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
+ #
8
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
+ #++
10
+
11
+ module Glyr
12
+
13
+ class Results
14
+ def self.wrap (pointer, length = nil) # :nodoc:
15
+ new(pointer, length).tap {|x|
16
+ ObjectSpace.define_finalizer x, finalizer(pointer)
17
+ }
18
+ end
19
+
20
+ def self.finalizer (pointer) # :nodoc:
21
+ proc {
22
+ C.glyr_free_list(pointer)
23
+ }
24
+ end
25
+
26
+ include Enumerable
27
+
28
+ attr_reader :length
29
+
30
+ def initialize (pointer, length = nil)
31
+ @internal = pointer.is_a?(FFI::Pointer) ? C::MemCache.new(pointer) : pointer
32
+ @length = length
33
+ end
34
+
35
+ def each (&block)
36
+ current = @internal
37
+
38
+ until current.null?
39
+ block.call(Result.wrap(current, self))
40
+
41
+ current = C::MemCache.new(current[:next])
42
+ end
43
+
44
+ self
45
+ end
46
+
47
+ def to_native
48
+ @internal
49
+ end
50
+ end
51
+
52
+ class Result
53
+ def self.wrap (struct, result) # :nodoc:
54
+ return if struct[:type] == :noidea
55
+
56
+ ::Glyr.const_get(struct[:type].to_s.capitalize.gsub(/_(\w)/) { $1.upcase }).
57
+ new(struct, result)
58
+ end
59
+
60
+ def self.copy (struct) # :nodoc:
61
+ return if struct[:type] == :noidea
62
+
63
+ pointer = C.glyr_cache_copy(struct)
64
+
65
+ ::Glyr.const_get(struct[:type].to_s.capitalize.gsub(/_(\w)/) { $1.upcase }).
66
+ new(pointer).tap {|data|
67
+ ObjectSpace.define_finalizer data, finalizer(pointer)
68
+ }
69
+ end
70
+
71
+ def self.finalizer (pointer) # :nodoc:
72
+ proc {
73
+ C.glyr_cache_free(pointer)
74
+ }
75
+ end
76
+
77
+ def initialize (pointer, result = nil)
78
+ @internal = pointer.is_a?(FFI::Pointer) ? C::MemCache.new(pointer) : pointer
79
+ @result = result
80
+ end
81
+
82
+ def clone
83
+ self.class.copy(to_native)
84
+ end
85
+
86
+ alias dup clone
87
+
88
+ def data
89
+ to_native[:data].typecast(:string, to_native[:size])
90
+ end
91
+
92
+ def url
93
+ to_native[:dsrc].typecast(:string)
94
+ end
95
+
96
+ def source
97
+ Glyr.providers[type].sources[to_native[:prov].typecast(:string)]
98
+ end
99
+
100
+ def rating
101
+ to_native[:rating]
102
+ end
103
+
104
+ def rating= (value)
105
+ to_native[:rating] = value
106
+ end
107
+
108
+ def type
109
+ to_native[:type]
110
+ end
111
+
112
+ def to_native
113
+ @internal
114
+ end
115
+
116
+ module Image
117
+ def to_blob
118
+ data
119
+ end
120
+
121
+ def format
122
+ to_native[:img_format].typecast(:string)
123
+ end
124
+ end
125
+
126
+ module Text
127
+ def to_s
128
+ data
129
+ end
130
+
131
+ alias to_str to_s
132
+ end
133
+
134
+ end
135
+
136
+ class CoverArt < Result
137
+ include Result::Image
138
+ end
139
+
140
+ class Lyrics < Result
141
+ include Result::Text
142
+ end
143
+
144
+ class AlbumReview < Result
145
+ include Result::Text
146
+ end
147
+
148
+ class ArtistPhoto < Result
149
+ include Result::Image
150
+ end
151
+
152
+ class SimilarArtist < Result
153
+ attr_reader :name, :url
154
+
155
+ def initialize (*)
156
+ super
157
+
158
+ @name, _, @url = data.lines.map(&:chomp)
159
+ end
160
+
161
+ end
162
+
163
+ class SimilarSong < Result
164
+ attr_reader :title, :artist, :url
165
+
166
+ def initialize (*)
167
+ super
168
+
169
+ @title, @artist, _, @url = data.lines.map(&:chomp)
170
+ end
171
+ end
172
+
173
+ class AlbumList < Result
174
+ end
175
+
176
+ class Tag < Result
177
+ include Result::Text
178
+ end
179
+
180
+ class TagArtist < Result
181
+ include Result::Text
182
+ end
183
+
184
+ class TagAlbum < Result
185
+ include Result::Text
186
+ end
187
+
188
+ class TagTitle < Result
189
+ include Result::Text
190
+ end
191
+
192
+ class Relation < Result
193
+ include Result::Text
194
+ end
195
+
196
+ class ImageUrl < Result
197
+ include Result::Text
198
+ end
199
+
200
+ class TextUrl < Result
201
+ include Result::Text
202
+ end
203
+
204
+ class Track < Result
205
+ include Result::Text
206
+ end
207
+
208
+ class GuitarTabs < Result
209
+ include Result::Text
210
+ end
211
+
212
+ class Backdrops < Result
213
+ include Result::Text
214
+ end
215
+
216
+ end
@@ -0,0 +1,89 @@
1
+ #--
2
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
+ # Version 2, December 2004
4
+ #
5
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
+ #
8
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
+ #++
10
+
11
+ module Glyr
12
+
13
+ class Sources
14
+ include Enumerable
15
+
16
+ attr_reader :provider
17
+
18
+ def initialize (pointer, provider)
19
+ @internal = pointer.is_a?(FFI::Pointer) ? C::SourceInfo.new(pointer) : pointer
20
+ @provider = provider
21
+ end
22
+
23
+ def each (&block)
24
+ current = @internal
25
+
26
+ until current.null?
27
+ block.call(Source.new(current, provider))
28
+
29
+ current = C::SourceInfo.new(current[:next])
30
+ end
31
+ end
32
+
33
+ def [] (name)
34
+ find { |p| p.name == name || p.key == name }
35
+ end
36
+
37
+ def to_hash
38
+ Hash[map { |p| [p.to_sym, p] }]
39
+ end
40
+
41
+ def to_native
42
+ @internal
43
+ end
44
+ end
45
+
46
+ class Source
47
+ attr_reader :provider
48
+
49
+ def initialize (pointer, provider)
50
+ @internal = pointer.is_a?(FFI::Pointer) ? C::SourceInfo.new(pointer) : pointer
51
+ @provider = provider
52
+ end
53
+
54
+ def name
55
+ to_native[:name]
56
+ end
57
+
58
+ def key
59
+ to_native[:key].chr
60
+ end
61
+
62
+ def quality
63
+ to_native[:quality]
64
+ end
65
+
66
+ def speed
67
+ to_native[:speed]
68
+ end
69
+
70
+ def language_aware?
71
+ to_native[:lang_aware]
72
+ end
73
+
74
+ alias to_s name
75
+
76
+ def to_sym
77
+ to_s.to_sym
78
+ end
79
+
80
+ def to_native
81
+ @internal
82
+ end
83
+
84
+ def inspect
85
+ "#<Glyr::Source(#{name}): quality=#{quality} speed=#{speed}#{' language_aware' if language_aware?}>"
86
+ end
87
+ end
88
+
89
+ end
@@ -12,6 +12,6 @@ require 'glyr'
12
12
 
13
13
  module Glyr
14
14
  def self.version
15
- '0.9.9'
15
+ '0.9.9.1'
16
16
  end
17
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glyr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.9
4
+ version: 0.9.9.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-22 00:00:00.000000000 Z
12
+ date: 2012-06-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
@@ -71,8 +71,10 @@ files:
71
71
  - lib/glyr/c.rb
72
72
  - lib/glyr/c/functions.rb
73
73
  - lib/glyr/c/types.rb
74
+ - lib/glyr/providers.rb
74
75
  - lib/glyr/query.rb
75
- - lib/glyr/result.rb
76
+ - lib/glyr/results.rb
77
+ - lib/glyr/sources.rb
76
78
  - lib/glyr/version.rb
77
79
  homepage: http://github.com/meh/ruby-glyr
78
80
  licenses: []
@@ -1,176 +0,0 @@
1
- #--
2
- # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
- # Version 2, December 2004
4
- #
5
- # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
- # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
- #
8
- # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
- #++
10
-
11
- module Glyr
12
-
13
- class Result
14
- def self.wrap (pointer)
15
- new(pointer).tap {|x|
16
- ObjectSpace.define_finalizer x, finalizer(pointer)
17
- }
18
- end
19
-
20
- def self.finalizer (pointer)
21
- proc {
22
- C.glyr_free_list(pointer)
23
- }
24
- end
25
-
26
- class Data
27
- def self.wrap (struct, result)
28
- return new(struct, result) if struct[:type] == :noidea
29
-
30
- ::Glyr.const_get(struct[:type].to_s.capitalize.gsub(/_(\w)/) { $1.upcase }).
31
- new(struct, result)
32
- end
33
-
34
- attr_reader :result
35
- attr_accessor :rating
36
-
37
- def initialize (pointer, result)
38
- @internal = pointer.is_a?(FFI::Pointer) ? C::MemCache.new(pointer) : pointer
39
- @result = result
40
- end
41
-
42
- def source
43
- to_native[:dsrc].read_string
44
- end
45
-
46
- def provider
47
- to_native[:prov].read_string
48
- end
49
-
50
- def to_native
51
- @internal
52
- end
53
-
54
- module Image
55
- def to_blob
56
- to_native[:data].read_string(to_native[:size]).force_encoding('BINARY')
57
- end
58
-
59
- def format
60
- to_native[:img_format].read_string
61
- end
62
- end
63
-
64
- module Text
65
- def to_s
66
- to_native[:data].read_string(to_native[:size])
67
- end
68
-
69
- alias to_str to_s
70
- end
71
-
72
- class ::Glyr::CoverArt < self
73
- include Image
74
- end
75
-
76
- class ::Glyr::Lyrics < self
77
- include Text
78
- end
79
-
80
- class ::Glyr::AlbumReview < self
81
- include Text
82
- end
83
-
84
- class ::Glyr::ArtistPhoto < self
85
- include Image
86
- end
87
-
88
- class ::Glyr::SimilarArtist < self
89
- attr_reader :name, :url
90
-
91
- def initialize (*)
92
- super
93
-
94
- @name, _, @url = to_native[:data].read_string(to_native[:size]).lines.map(&:chomp)
95
- end
96
-
97
- end
98
-
99
- class ::Glyr::SimilarSong < self
100
- attr_reader :title, :artist, :url
101
-
102
- def initialize (*)
103
- super
104
-
105
- @title, @artist, _, @url = to_native[:data].read_string(to_native[:size]).lines.map(&:chomp)
106
- end
107
- end
108
-
109
- class ::Glyr::AlbumList < self
110
- end
111
-
112
- class ::Glyr::Tag < self
113
- include Text
114
- end
115
-
116
- class ::Glyr::TagArtist < self
117
- include Text
118
- end
119
-
120
- class ::Glyr::TagAlbum < self
121
- include Text
122
- end
123
-
124
- class ::Glyr::TagTitle < self
125
- include Text
126
- end
127
-
128
- class ::Glyr::Relation < self
129
- include Text
130
- end
131
-
132
- class ::Glyr::ImageUrl < self
133
- include Text
134
- end
135
-
136
- class ::Glyr::TextUrl < self
137
- include Text
138
- end
139
-
140
- class ::Glyr::Track < self
141
- include Text
142
- end
143
-
144
- class ::Glyr::GuitarTabs < self
145
- include Text
146
- end
147
-
148
- class ::Glyr::Backdrops < self
149
- include Text
150
- end
151
- end
152
-
153
- include Enumerable
154
-
155
- def initialize (pointer)
156
- @internal = pointer.is_a?(FFI::Pointer) ? C::MemCache.new(pointer) : pointer
157
- end
158
-
159
- def each (&block)
160
- current = @internal
161
-
162
- until current.null?
163
- block.call(Data.wrap(current, self))
164
-
165
- current = C::MemCache.new(@internal[:next])
166
- end
167
-
168
- self
169
- end
170
-
171
- def to_native
172
- @internal
173
- end
174
- end
175
-
176
- end