glyr 0.9.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -0
- data/glyr.gemspec +20 -0
- data/lib/glyr.rb +15 -0
- data/lib/glyr/c.rb +31 -0
- data/lib/glyr/c/functions.rb +83 -0
- data/lib/glyr/c/types.rb +184 -0
- data/lib/glyr/query.rb +174 -0
- data/lib/glyr/result.rb +176 -0
- data/lib/glyr/version.rb +17 -0
- metadata +101 -0
data/README.md
ADDED
data/glyr.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
$:.unshift('lib') and require 'glyr'
|
2
|
+
|
3
|
+
Gem::Specification.new {|s|
|
4
|
+
s.name = 'glyr'
|
5
|
+
s.version = Glyr.version
|
6
|
+
s.author = 'meh.'
|
7
|
+
s.email = 'meh@paranoici.org'
|
8
|
+
s.homepage = 'http://github.com/meh/ruby-glyr'
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.summary = 'Wrapper library for glyr.'
|
11
|
+
|
12
|
+
s.files = `git ls-files`.split("\n")
|
13
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
14
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
+
s.require_paths = ['lib']
|
16
|
+
|
17
|
+
s.add_dependency 'ffi'
|
18
|
+
s.add_dependency 'ffi-extra'
|
19
|
+
s.add_dependency 'bitmap'
|
20
|
+
}
|
data/lib/glyr.rb
ADDED
@@ -0,0 +1,15 @@
|
|
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
|
+
require 'glyr/c'
|
12
|
+
|
13
|
+
require 'glyr/version'
|
14
|
+
require 'glyr/query'
|
15
|
+
require 'glyr/result'
|
data/lib/glyr/c.rb
ADDED
@@ -0,0 +1,31 @@
|
|
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
|
+
require 'ffi'
|
12
|
+
require 'ffi/extra'
|
13
|
+
|
14
|
+
module Glyr
|
15
|
+
|
16
|
+
module C
|
17
|
+
extend FFI::Library
|
18
|
+
|
19
|
+
ffi_lib 'glyr'
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'glyr/c/types'
|
25
|
+
require 'glyr/c/functions'
|
26
|
+
|
27
|
+
Glyr::C.glyr_init
|
28
|
+
|
29
|
+
at_exit {
|
30
|
+
Glyr::C.glyr_cleanup
|
31
|
+
}
|
@@ -0,0 +1,83 @@
|
|
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; module C
|
12
|
+
|
13
|
+
attach_function :glyr_init, [], :void
|
14
|
+
attach_function :glyr_cleanup, [], :void
|
15
|
+
|
16
|
+
attach_function :glyr_query_init, [:pointer], :void
|
17
|
+
attach_function :glyr_query_destroy, [:pointer], :void
|
18
|
+
attach_function :glyr_signal_exit, [:pointer], :void # this dumb name is aimed to stop a query
|
19
|
+
|
20
|
+
attach_function :glyr_get, [:pointer, :pointer, :pointer], :pointer
|
21
|
+
attach_function :glyr_free_list, [:pointer], :void
|
22
|
+
|
23
|
+
attach_function :glyr_cache_new, [], :pointer
|
24
|
+
attach_function :glyr_cache_free, [:pointer], :void
|
25
|
+
attach_function :glyr_cache_copy, [:pointer], :pointer
|
26
|
+
attach_function :glyr_cache_set_dsrc, [:pointer, :string], :void
|
27
|
+
attach_function :glyr_cache_set_prov, [:pointer, :string], :void
|
28
|
+
attach_function :glyr_cache_set_img_format, [:pointer, :string], :void
|
29
|
+
attach_function :glyr_cache_set_type, [:pointer, DataType], :void
|
30
|
+
attach_function :glyr_cache_set_rating, [:pointer, :int], :void
|
31
|
+
attach_function :glyr_cache_set_data, [:pointer, :pointer, :int], :void
|
32
|
+
attach_function :glyr_cache_write, [:pointer, :string], :int
|
33
|
+
attach_function :glyr_cache_update_md5sum, [:pointer], :void
|
34
|
+
attach_function :glyr_cache_print, [:pointer], :void
|
35
|
+
|
36
|
+
attach_function :glyr_opt_dlcallback, [:pointer, :DLCallback, :pointer], Error
|
37
|
+
attach_function :glyr_opt_type, [:pointer, GetType], Error
|
38
|
+
attach_function :glyr_opt_artist, [:pointer, :string], Error
|
39
|
+
attach_function :glyr_opt_album, [:pointer, :string], Error
|
40
|
+
attach_function :glyr_opt_title, [:pointer, :string], Error
|
41
|
+
attach_function :glyr_opt_img_minsize, [:pointer, :int], Error
|
42
|
+
attach_function :glyr_opt_img_maxsize, [:pointer, :int], Error
|
43
|
+
attach_function :glyr_opt_parallel, [:pointer, :ulong], Error
|
44
|
+
attach_function :glyr_opt_timeout, [:pointer, :ulong], Error
|
45
|
+
attach_function :glyr_opt_redirects, [:pointer, :ulong], Error
|
46
|
+
attach_function :glyr_opt_useragent, [:pointer, :string], Error
|
47
|
+
attach_function :glyr_opt_lang, [:pointer, :string], Error
|
48
|
+
attach_function :glyr_opt_lang_aware_only, [:pointer, :bool], Error
|
49
|
+
attach_function :glyr_opt_number, [:pointer, :ulong], Error
|
50
|
+
attach_function :glyr_opt_verbosity, [:pointer, :uint], Error
|
51
|
+
attach_function :glyr_opt_from, [:pointer, :string], Error
|
52
|
+
attach_function :glyr_opt_plugmax, [:pointer, :int], Error
|
53
|
+
attach_function :glyr_opt_allowed_formats, [:pointer, :string], Error
|
54
|
+
attach_function :glyr_opt_download, [:pointer, :bool], Error
|
55
|
+
attach_function :glyr_opt_fuzzyness, [:pointer, :int], Error
|
56
|
+
attach_function :glyr_opt_qsratio, [:pointer, :float], Error
|
57
|
+
attach_function :glyr_opt_proxy, [:pointer, :string], Error
|
58
|
+
attach_function :glyr_opt_force_utf8, [:pointer, :bool], Error
|
59
|
+
attach_function :glyr_opt_lookup_db, [:pointer, :pointer], Error
|
60
|
+
attach_function :glyr_opt_db_autowrite, [:pointer, :bool], Error
|
61
|
+
attach_function :glyr_opt_db_autoread, [:pointer, :bool], Error
|
62
|
+
attach_function :glyr_opt_musictree_path, [:pointer, :string], Error
|
63
|
+
|
64
|
+
attach_function :glyr_download, [:string, :pointer], :pointer
|
65
|
+
attach_function :glyr_strerror, [Error], :string
|
66
|
+
attach_function :glyr_version, [], :string
|
67
|
+
|
68
|
+
attach_function :glyr_info_get, [], :pointer
|
69
|
+
attach_function :glyr_info_free, [:pointer], :void
|
70
|
+
|
71
|
+
attach_function :glyr_data_type_to_string, [DataType], :string
|
72
|
+
attach_function :glyr_get_type_to_string, [GetType], :string
|
73
|
+
attach_function :glyr_md5sum_to_string, [:pointer], :string
|
74
|
+
|
75
|
+
attach_function :glyr_string_to_data_type, [:string], DataType
|
76
|
+
attach_function :glyr_string_to_get_type, [:string], GetType
|
77
|
+
attach_function :glyr_string_to_md5sum, [:string, :pointer], :void
|
78
|
+
|
79
|
+
attach_function :glyr_get_requirements, [GetType], :int
|
80
|
+
|
81
|
+
attach_function :glyr_type_is_image, [GetType], :bool
|
82
|
+
|
83
|
+
end; end
|
data/lib/glyr/c/types.rb
ADDED
@@ -0,0 +1,184 @@
|
|
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
|
+
require 'bitmap'
|
12
|
+
|
13
|
+
module Glyr; module C
|
14
|
+
|
15
|
+
Error = FFI::Enum.new([
|
16
|
+
:unknown, 0,
|
17
|
+
:ok,
|
18
|
+
:bad_option,
|
19
|
+
:bad_value,
|
20
|
+
:empty_struct,
|
21
|
+
:no_provider,
|
22
|
+
:unknown_get,
|
23
|
+
:insuff_data,
|
24
|
+
:skip,
|
25
|
+
:stop_post,
|
26
|
+
:stop_pre,
|
27
|
+
:no_init,
|
28
|
+
:was_stopped
|
29
|
+
])
|
30
|
+
|
31
|
+
GetType = FFI::Enum.new([
|
32
|
+
:noidea,
|
33
|
+
:cover_art,
|
34
|
+
:lyrics,
|
35
|
+
:artist_photos,
|
36
|
+
:artist_bio,
|
37
|
+
:similar_artists,
|
38
|
+
:similar_songs,
|
39
|
+
:album_reviews,
|
40
|
+
:tracklist,
|
41
|
+
:tags,
|
42
|
+
:relations,
|
43
|
+
:album_list,
|
44
|
+
:guitar_tabs,
|
45
|
+
:backdrops,
|
46
|
+
:any
|
47
|
+
])
|
48
|
+
|
49
|
+
DataType = FFI::Enum.new([
|
50
|
+
:noidea,
|
51
|
+
:lyrics,
|
52
|
+
:album_review,
|
53
|
+
:artist_photo,
|
54
|
+
:cover_art,
|
55
|
+
:artist_bio,
|
56
|
+
:similar_artist,
|
57
|
+
:similar_song,
|
58
|
+
:album_list,
|
59
|
+
:tag,
|
60
|
+
:tag_artist,
|
61
|
+
:tag_album,
|
62
|
+
:tag_title,
|
63
|
+
:relation,
|
64
|
+
:image_url,
|
65
|
+
:text_url,
|
66
|
+
:track,
|
67
|
+
:guitar_tabs,
|
68
|
+
:backdrops
|
69
|
+
])
|
70
|
+
|
71
|
+
FieldRequirement = Bitmap.new(
|
72
|
+
requires_artist: 1 << 0,
|
73
|
+
requires_album: 1 << 1,
|
74
|
+
requires_title: 1 << 2,
|
75
|
+
optional_artist: 1 << 3,
|
76
|
+
optional_album: 1 << 4,
|
77
|
+
optional_title: 1 << 5
|
78
|
+
)
|
79
|
+
|
80
|
+
callback :DLCallback, [:pointer, :pointer], Error
|
81
|
+
|
82
|
+
class MemCache < FFI::Struct
|
83
|
+
layout \
|
84
|
+
:data, :pointer,
|
85
|
+
:size, :size_t,
|
86
|
+
:dsrc, :pointer,
|
87
|
+
:prov, :pointer,
|
88
|
+
:type, DataType,
|
89
|
+
:duration, :int,
|
90
|
+
:rating, :int,
|
91
|
+
:is_image, :bool,
|
92
|
+
:img_format, :pointer,
|
93
|
+
:md5sum, [:uchar, 16],
|
94
|
+
:cached, :bool,
|
95
|
+
:timestamp, :double,
|
96
|
+
|
97
|
+
:next, :pointer,
|
98
|
+
:prev, :pointer
|
99
|
+
end
|
100
|
+
|
101
|
+
class Database < FFI::Struct
|
102
|
+
layout \
|
103
|
+
:root_path, :string,
|
104
|
+
:db_handle, :pointer
|
105
|
+
end
|
106
|
+
|
107
|
+
class Query < FFI::Struct
|
108
|
+
class Callback < FFI::Struct
|
109
|
+
layout \
|
110
|
+
:download, :DLCallback,
|
111
|
+
:user_pointer, :pointer
|
112
|
+
end
|
113
|
+
|
114
|
+
layout \
|
115
|
+
:type, GetType,
|
116
|
+
:number, :int,
|
117
|
+
:plugmax, :int,
|
118
|
+
:verbosity, :int,
|
119
|
+
:fuzzyness, :size_t,
|
120
|
+
|
121
|
+
:img_min_size, :int,
|
122
|
+
:img_max_size, :int,
|
123
|
+
|
124
|
+
:parallel, :int,
|
125
|
+
:timeout, :int,
|
126
|
+
:redirects, :int,
|
127
|
+
|
128
|
+
:force_utf8, :bool,
|
129
|
+
:download, :bool,
|
130
|
+
:qsratio, :float,
|
131
|
+
|
132
|
+
:q_errno, Error,
|
133
|
+
|
134
|
+
:db_autoread, :bool,
|
135
|
+
:db_autowrite, :bool,
|
136
|
+
:local_db, :pointer,
|
137
|
+
|
138
|
+
:lang_aware_only, :bool,
|
139
|
+
|
140
|
+
:signal_exit, :int,
|
141
|
+
|
142
|
+
:lang, :string,
|
143
|
+
:proxy, :string,
|
144
|
+
:artist, :string,
|
145
|
+
:album, :string,
|
146
|
+
:title, :string,
|
147
|
+
:from, :string,
|
148
|
+
:allowed_formats, :string,
|
149
|
+
:useragent, :string,
|
150
|
+
:musictree_path, :string,
|
151
|
+
|
152
|
+
:callback, Callback,
|
153
|
+
|
154
|
+
:itemcr, :int,
|
155
|
+
:info, [:pointer, 10],
|
156
|
+
:imagejob, :bool,
|
157
|
+
:is_initialized, :bool
|
158
|
+
end
|
159
|
+
|
160
|
+
class SourceInfo < FFI::Struct
|
161
|
+
layout \
|
162
|
+
:name, :string,
|
163
|
+
:key, :char,
|
164
|
+
:type, GetType,
|
165
|
+
:quality, :int,
|
166
|
+
:speed, :int,
|
167
|
+
:lang_aware, :bool,
|
168
|
+
|
169
|
+
:next, :pointer,
|
170
|
+
:prev, :pointer
|
171
|
+
end
|
172
|
+
|
173
|
+
class FetcherInfo < FFI::Struct
|
174
|
+
layout \
|
175
|
+
:name, :string,
|
176
|
+
:type, GetType,
|
177
|
+
:reqs, :int,
|
178
|
+
:head, :pointer,
|
179
|
+
|
180
|
+
:next, :pointer,
|
181
|
+
:prev, :pointer
|
182
|
+
end
|
183
|
+
|
184
|
+
end; end
|
data/lib/glyr/query.rb
ADDED
@@ -0,0 +1,174 @@
|
|
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 Query
|
14
|
+
def self.create (options = {})
|
15
|
+
struct = C::Query.new
|
16
|
+
|
17
|
+
C.glyr_query_init(struct.pointer)
|
18
|
+
|
19
|
+
wrap(struct.pointer, options)
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.wrap (pointer, options = {})
|
24
|
+
new(pointer, options).tap {|x|
|
25
|
+
ObjectSpace.define_finalizer x, finalizer(pointer)
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.finalizer (pointer)
|
30
|
+
proc {
|
31
|
+
C.glyr_query_destroy(pointer)
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def initialize (pointer, options = {})
|
36
|
+
@internal = pointer.is_a?(FFI::Pointer) ? C::Query.new(pointer) : pointer
|
37
|
+
|
38
|
+
options.each {|name, value|
|
39
|
+
if value == true
|
40
|
+
__send__ "#{name}!"
|
41
|
+
elsif value == false
|
42
|
+
__send__ "no_#{name}!"
|
43
|
+
else
|
44
|
+
__send__ name, *value
|
45
|
+
end
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def type (value)
|
50
|
+
raise_if_error C.glyr_opt_type(to_native, value.is_a?(Symbol) ? value : C::GetType[value])
|
51
|
+
end
|
52
|
+
|
53
|
+
def artist (value)
|
54
|
+
raise_if_error C.glyr_opt_artist(to_native, value)
|
55
|
+
end
|
56
|
+
|
57
|
+
def album (value)
|
58
|
+
raise_if_error C.glyr_opt_album(to_native, value)
|
59
|
+
end
|
60
|
+
|
61
|
+
def title (value)
|
62
|
+
raise_if_error C.glyr_opt_title(to_native, value)
|
63
|
+
end
|
64
|
+
|
65
|
+
def parallel (value)
|
66
|
+
raise_if_error C.glyr_opt_parallel(to_native, value)
|
67
|
+
end
|
68
|
+
|
69
|
+
def timeout (value)
|
70
|
+
raise_if_error C.glyr_opt_timeout(to_native, value)
|
71
|
+
end
|
72
|
+
|
73
|
+
def redirects (value)
|
74
|
+
raise_if_error C.glyr_opt_redirects(to_native, value)
|
75
|
+
end
|
76
|
+
|
77
|
+
def user_agent (value)
|
78
|
+
raise_if_error C.glyr_opt_useragent(to_native, value)
|
79
|
+
end
|
80
|
+
|
81
|
+
def language (value)
|
82
|
+
raise_if_error C.glyr_opt_lang(to_native, value)
|
83
|
+
end
|
84
|
+
|
85
|
+
def language_aware!
|
86
|
+
raise_if_error C.glyr_opt_lang_aware_only(to_native, true)
|
87
|
+
end
|
88
|
+
|
89
|
+
def no_language_aware!
|
90
|
+
raise_if_error C.glyr_opt_lang_aware_only(to_native, false)
|
91
|
+
end
|
92
|
+
|
93
|
+
def number (value)
|
94
|
+
raise_if_error C.glyr_opt_number(to_native, value)
|
95
|
+
end
|
96
|
+
|
97
|
+
def verbosity (value)
|
98
|
+
raise_if_error C.glyr_opt_verbosity(to_native, value)
|
99
|
+
end
|
100
|
+
|
101
|
+
def from (*providers)
|
102
|
+
raise_if_error C.glyr_opt_from(to_native, providers.flatten.compact.uniq.join(';'))
|
103
|
+
end
|
104
|
+
|
105
|
+
def allowed_formats (*formats)
|
106
|
+
raise_if_error C.glyr_opt_allowed_formats(to_native, formats.flatten.compact.uniq.join(';'))
|
107
|
+
end
|
108
|
+
|
109
|
+
def download!
|
110
|
+
raise_if_error C.glyr_opt_download(to_native, true)
|
111
|
+
end
|
112
|
+
|
113
|
+
def no_download!
|
114
|
+
raise_if_error C.glyr_opt_download(to_native, false)
|
115
|
+
end
|
116
|
+
|
117
|
+
def fuzzyness (value)
|
118
|
+
raise_if_error C.glyr_opt_fuzzyness(to_native, value)
|
119
|
+
end
|
120
|
+
|
121
|
+
def ratio (value)
|
122
|
+
raise_if_error C.glyr_opt_qsratio(to_native, value)
|
123
|
+
end
|
124
|
+
|
125
|
+
def proxy (value)
|
126
|
+
raise_if_error C.glyr_opt_proxy(to_native, value)
|
127
|
+
end
|
128
|
+
|
129
|
+
def force_utf8!
|
130
|
+
raise_if_error C.glyr_opt_force_utf8(to_native, true)
|
131
|
+
end
|
132
|
+
|
133
|
+
def no_force_utf8!
|
134
|
+
raise_if_error C.glyr_opt_force_utf8(to_native, false)
|
135
|
+
end
|
136
|
+
|
137
|
+
def get
|
138
|
+
error = FFI::MemoryPointer.new :int
|
139
|
+
result = C.glyr_get(to_native, error, nil)
|
140
|
+
|
141
|
+
raise_if_error error.typecast(:int)
|
142
|
+
|
143
|
+
Result.wrap(result)
|
144
|
+
end
|
145
|
+
|
146
|
+
%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
|
+
name = name.to_sym
|
148
|
+
|
149
|
+
define_method name do
|
150
|
+
type(name).get
|
151
|
+
end
|
152
|
+
}
|
153
|
+
|
154
|
+
def stop
|
155
|
+
C.glyr_signal_exit(to_native)
|
156
|
+
end
|
157
|
+
|
158
|
+
def to_native
|
159
|
+
@internal
|
160
|
+
end
|
161
|
+
|
162
|
+
private
|
163
|
+
def raise_if_error (value)
|
164
|
+
value = C::Error[value] unless value.is_a? Symbol
|
165
|
+
|
166
|
+
if value != :ok
|
167
|
+
raise C.glyr_strerror(value)
|
168
|
+
end
|
169
|
+
|
170
|
+
self
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
data/lib/glyr/result.rb
ADDED
@@ -0,0 +1,176 @@
|
|
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
|
data/lib/glyr/version.rb
ADDED
@@ -0,0 +1,17 @@
|
|
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
|
+
require 'glyr'
|
12
|
+
|
13
|
+
module Glyr
|
14
|
+
def self.version
|
15
|
+
'0.9.9'
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: glyr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.9
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- meh.
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: ffi
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: ffi-extra
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bitmap
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description:
|
63
|
+
email: meh@paranoici.org
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- README.md
|
69
|
+
- glyr.gemspec
|
70
|
+
- lib/glyr.rb
|
71
|
+
- lib/glyr/c.rb
|
72
|
+
- lib/glyr/c/functions.rb
|
73
|
+
- lib/glyr/c/types.rb
|
74
|
+
- lib/glyr/query.rb
|
75
|
+
- lib/glyr/result.rb
|
76
|
+
- lib/glyr/version.rb
|
77
|
+
homepage: http://github.com/meh/ruby-glyr
|
78
|
+
licenses: []
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 1.8.24
|
98
|
+
signing_key:
|
99
|
+
specification_version: 3
|
100
|
+
summary: Wrapper library for glyr.
|
101
|
+
test_files: []
|