rbpod 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +66 -44
- data/Rakefile +9 -5
- data/ext/rbpod/collection.c +45 -14
- data/ext/rbpod/database.c +75 -34
- data/ext/rbpod/device.c +104 -21
- data/ext/rbpod/device.h +0 -2
- data/ext/rbpod/playlist.c +95 -11
- data/ext/rbpod/playlist_collection.c +43 -21
- data/ext/rbpod/rbpod.c +19 -0
- data/ext/rbpod/rbpod.h +2 -0
- data/ext/rbpod/track.c +88 -8
- data/ext/rbpod/track_collection.c +12 -6
- data/lib/rbpod/version.rb +2 -2
- data/spec/collection_spec.rb +2 -2
- data/spec/database_spec.rb +2 -12
- metadata +4 -4
data/ext/rbpod/device.c
CHANGED
@@ -2,42 +2,74 @@
|
|
2
2
|
|
3
3
|
#include "rbpod.h"
|
4
4
|
#include "device.h"
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
#include "database.h"
|
6
|
+
|
7
|
+
/*
|
8
|
+
* call-seq:
|
9
|
+
* supports_chapter_images?() -> Boolean
|
10
|
+
*
|
11
|
+
* Returns true of false if the device supports chapter images.
|
12
|
+
*/
|
11
13
|
static VALUE rbpod_device_chapter_image_support_p(VALUE self)
|
12
14
|
{
|
13
15
|
Itdb_Device *device = TYPED_DATA_PTR(self, Itdb_Device);
|
14
16
|
return BooleanValue(itdb_device_supports_chapter_image(device));
|
15
17
|
}
|
16
18
|
|
19
|
+
/*
|
20
|
+
* call-seq:
|
21
|
+
* supports_podcasts?() -> Boolean
|
22
|
+
*
|
23
|
+
* Returns true of false if the device supports podcasts.
|
24
|
+
*/
|
17
25
|
static VALUE rbpod_device_podcast_support_p(VALUE self)
|
18
26
|
{
|
19
27
|
Itdb_Device *device = TYPED_DATA_PTR(self, Itdb_Device);
|
20
28
|
return BooleanValue(itdb_device_supports_podcast(device));
|
21
29
|
}
|
22
30
|
|
31
|
+
/*
|
32
|
+
* call-seq:
|
33
|
+
* supports_artwork?() -> Boolean
|
34
|
+
*
|
35
|
+
* Returns true of false if the device supports artwork.
|
36
|
+
*/
|
23
37
|
static VALUE rbpod_device_artwork_support_p(VALUE self)
|
24
38
|
{
|
25
39
|
Itdb_Device *device = TYPED_DATA_PTR(self, Itdb_Device);
|
26
40
|
return BooleanValue(itdb_device_supports_artwork(device));
|
27
41
|
}
|
28
42
|
|
43
|
+
/*
|
44
|
+
* call-seq:
|
45
|
+
* supports_videos?() -> Boolean
|
46
|
+
*
|
47
|
+
* Returns true of false if the device supports videos.
|
48
|
+
*/
|
29
49
|
static VALUE rbpod_device_video_support_p(VALUE self)
|
30
50
|
{
|
31
51
|
Itdb_Device *device = TYPED_DATA_PTR(self, Itdb_Device);
|
32
52
|
return BooleanValue(itdb_device_supports_video(device));
|
33
53
|
}
|
34
54
|
|
55
|
+
/*
|
56
|
+
* call-seq:
|
57
|
+
* supports_photos?() -> Boolean
|
58
|
+
*
|
59
|
+
* Returns true of false if the device supports photos.
|
60
|
+
*/
|
35
61
|
static VALUE rbpod_device_photo_support_p(VALUE self)
|
36
62
|
{
|
37
63
|
Itdb_Device *device = TYPED_DATA_PTR(self, Itdb_Device);
|
38
64
|
return BooleanValue(itdb_device_supports_photo(device));
|
39
65
|
}
|
40
66
|
|
67
|
+
/*
|
68
|
+
* call-seq:
|
69
|
+
* model_name() -> String
|
70
|
+
*
|
71
|
+
* Returns the model name of the device.
|
72
|
+
*/
|
41
73
|
static VALUE rbpod_device_model_name_get(VALUE self)
|
42
74
|
{
|
43
75
|
Itdb_Device *device = TYPED_DATA_PTR(self, Itdb_Device);
|
@@ -45,6 +77,12 @@ static VALUE rbpod_device_model_name_get(VALUE self)
|
|
45
77
|
return rb_str_new2(itdb_info_get_ipod_model_name_string(info->ipod_model));
|
46
78
|
}
|
47
79
|
|
80
|
+
/*
|
81
|
+
* call-seq:
|
82
|
+
* model_number() -> String
|
83
|
+
*
|
84
|
+
* Returns the model number of the device.
|
85
|
+
*/
|
48
86
|
static VALUE rbpod_device_model_number_get(VALUE self)
|
49
87
|
{
|
50
88
|
Itdb_Device *device = TYPED_DATA_PTR(self, Itdb_Device);
|
@@ -52,6 +90,12 @@ static VALUE rbpod_device_model_number_get(VALUE self)
|
|
52
90
|
return rb_str_new2(info->model_number);
|
53
91
|
}
|
54
92
|
|
93
|
+
/*
|
94
|
+
* call-seq:
|
95
|
+
* generation() -> String
|
96
|
+
*
|
97
|
+
* Returns the generation of the device.
|
98
|
+
*/
|
55
99
|
static VALUE rbpod_device_generation_get(VALUE self)
|
56
100
|
{
|
57
101
|
Itdb_Device *device = TYPED_DATA_PTR(self, Itdb_Device);
|
@@ -59,6 +103,12 @@ static VALUE rbpod_device_generation_get(VALUE self)
|
|
59
103
|
return rb_str_new2(itdb_info_get_ipod_generation_string(info->ipod_generation));
|
60
104
|
}
|
61
105
|
|
106
|
+
/*
|
107
|
+
* call-seq:
|
108
|
+
* capacity() -> Float
|
109
|
+
*
|
110
|
+
* Returns the capacity of the device in gigabytes (GB).
|
111
|
+
*/
|
62
112
|
static VALUE rbpod_device_capacity_get(VALUE self)
|
63
113
|
{
|
64
114
|
Itdb_Device *device = TYPED_DATA_PTR(self, Itdb_Device);
|
@@ -66,6 +116,12 @@ static VALUE rbpod_device_capacity_get(VALUE self)
|
|
66
116
|
return DBL2NUM(info->capacity);
|
67
117
|
}
|
68
118
|
|
119
|
+
/*
|
120
|
+
* call-seq:
|
121
|
+
* uuid() -> String
|
122
|
+
*
|
123
|
+
* Returns the UUID of the device.
|
124
|
+
*/
|
69
125
|
static VALUE rbpod_device_uuid_get(VALUE self)
|
70
126
|
{
|
71
127
|
Itdb_Device *device = TYPED_DATA_PTR(self, Itdb_Device);
|
@@ -73,6 +129,12 @@ static VALUE rbpod_device_uuid_get(VALUE self)
|
|
73
129
|
return (uuid == NULL) ? Qnil : rb_str_new2(uuid);
|
74
130
|
}
|
75
131
|
|
132
|
+
/*
|
133
|
+
* call-seq:
|
134
|
+
* [](key) -> String
|
135
|
+
*
|
136
|
+
* Returns the SysInfo entry for the given key, or nil.
|
137
|
+
*/
|
76
138
|
static VALUE rbpod_device_sysinfo_get(VALUE self, VALUE key)
|
77
139
|
{
|
78
140
|
Itdb_Device *device = TYPED_DATA_PTR(self, Itdb_Device);
|
@@ -87,6 +149,12 @@ static VALUE rbpod_device_sysinfo_get(VALUE self, VALUE key)
|
|
87
149
|
|
88
150
|
}
|
89
151
|
|
152
|
+
/*
|
153
|
+
* call-seq:
|
154
|
+
* []=(key, value) -> nil
|
155
|
+
*
|
156
|
+
* Sets the given SysInfo entry to a value and returns nil.
|
157
|
+
*/
|
90
158
|
static VALUE rbpod_device_sysinfo_set(VALUE self, VALUE key, VALUE value)
|
91
159
|
{
|
92
160
|
Itdb_Device *device = TYPED_DATA_PTR(self, Itdb_Device);
|
@@ -100,6 +168,12 @@ static VALUE rbpod_device_sysinfo_set(VALUE self, VALUE key, VALUE value)
|
|
100
168
|
return Qnil;
|
101
169
|
}
|
102
170
|
|
171
|
+
/*
|
172
|
+
* call-seq:
|
173
|
+
* save!() -> nil
|
174
|
+
*
|
175
|
+
* Writes the SysInfo data back to the device. Call this if you change any entries.
|
176
|
+
*/
|
103
177
|
static VALUE rbpod_device_sysinfo_save(VALUE self)
|
104
178
|
{
|
105
179
|
Itdb_Device *device = TYPED_DATA_PTR(self, Itdb_Device);
|
@@ -112,20 +186,32 @@ static VALUE rbpod_device_sysinfo_save(VALUE self)
|
|
112
186
|
return Qnil;
|
113
187
|
}
|
114
188
|
|
115
|
-
|
189
|
+
/*
|
190
|
+
* call-seq:
|
191
|
+
* initialize(database) -> RbPod::Device
|
192
|
+
*
|
193
|
+
* Creates an RbPod::Device for a given RbPod::Database. You shouldn't have to call this.
|
194
|
+
*/
|
195
|
+
static VALUE rbpod_device_initialize(VALUE self, VALUE database)
|
116
196
|
{
|
117
|
-
|
118
|
-
return self;
|
119
|
-
}
|
197
|
+
Itdb_iTunesDB *_database = TYPED_DATA_PTR(database, Itdb_iTunesDB);
|
120
198
|
|
121
|
-
|
122
|
-
{
|
123
|
-
|
124
|
-
|
199
|
+
/* Make sure we were given an instance of a RbPod::Database. */
|
200
|
+
if (rb_class_of(database) != cRbPodDatabase) {
|
201
|
+
rb_raise(eRbPodError, "Given database must be an instance of RbPod::Database: %s", StringValueCStr(database));
|
202
|
+
return Qnil;
|
203
|
+
}
|
125
204
|
|
126
|
-
|
127
|
-
{
|
128
|
-
|
205
|
+
/* The database pointer and it's device should both be non-NULL. */
|
206
|
+
if (_database == NULL || _database->device == NULL) {
|
207
|
+
rb_raise(eRbPodError, "Given database and/or device was NULL.");
|
208
|
+
return Qnil;
|
209
|
+
}
|
210
|
+
|
211
|
+
/* Attach our data pointer to this database's backing device. */
|
212
|
+
DATA_PTR(self) = _database->device;
|
213
|
+
|
214
|
+
return self;
|
129
215
|
}
|
130
216
|
|
131
217
|
void Init_rbpod_device(void)
|
@@ -135,10 +221,7 @@ void Init_rbpod_device(void)
|
|
135
221
|
#endif
|
136
222
|
cRbPodDevice = rb_define_class_under(mRbPod, "Device", rb_cObject);
|
137
223
|
|
138
|
-
|
139
|
-
|
140
|
-
/* We don't want to explicitly create these, so mark the constructor as private. */
|
141
|
-
rb_define_private_method(cRbPodDevice, "initialize", rbpod_device_initialize, 0);
|
224
|
+
rb_define_method(cRbPodDevice, "initialize", rbpod_device_initialize, 1);
|
142
225
|
|
143
226
|
rb_define_method(cRbPodDevice, "[]", rbpod_device_sysinfo_get, 1);
|
144
227
|
rb_define_method(cRbPodDevice, "[]=", rbpod_device_sysinfo_set, 2);
|
data/ext/rbpod/device.h
CHANGED
data/ext/rbpod/playlist.c
CHANGED
@@ -4,73 +4,152 @@
|
|
4
4
|
#include "playlist.h"
|
5
5
|
#include "track_collection.h"
|
6
6
|
|
7
|
+
/*
|
8
|
+
* call-seq:
|
9
|
+
* is_podcast_playlist?() -> Boolean
|
10
|
+
*
|
11
|
+
* Returns true or false if this playlist is the podcast-only playlist.
|
12
|
+
*/
|
7
13
|
static VALUE rbpod_playlist_podcast_p(VALUE self)
|
8
14
|
{
|
9
15
|
Itdb_Playlist *playlist = TYPED_DATA_PTR(self, Itdb_Playlist);
|
10
16
|
return BooleanValue(itdb_playlist_is_podcasts(playlist));
|
11
17
|
}
|
12
18
|
|
19
|
+
/*
|
20
|
+
* call-seq:
|
21
|
+
* is_master_playlist?() -> Boolean
|
22
|
+
*
|
23
|
+
* Returns true or false if this playlist is the master playlist.
|
24
|
+
*/
|
13
25
|
static VALUE rbpod_playlist_master_p(VALUE self)
|
14
26
|
{
|
15
27
|
Itdb_Playlist *playlist = TYPED_DATA_PTR(self, Itdb_Playlist);
|
16
28
|
return BooleanValue(itdb_playlist_is_mpl(playlist));
|
17
29
|
}
|
18
30
|
|
31
|
+
/*
|
32
|
+
* call-seq:
|
33
|
+
* is_smart_playlist?() -> Boolean
|
34
|
+
*
|
35
|
+
* Returns true or false if this playlist is a smart playlist.
|
36
|
+
*/
|
19
37
|
static VALUE rbpod_playlist_smart_p(VALUE self)
|
20
38
|
{
|
21
39
|
Itdb_Playlist *playlist = TYPED_DATA_PTR(self, Itdb_Playlist);
|
22
40
|
return BooleanValue(playlist->is_spl);
|
23
41
|
}
|
24
42
|
|
43
|
+
/*
|
44
|
+
* call-seq:
|
45
|
+
* timestamp() -> Time
|
46
|
+
* created_on() -> Time
|
47
|
+
*
|
48
|
+
* Returns a Time object representing the time that this playlist was created.
|
49
|
+
*/
|
25
50
|
static VALUE rbpod_playlist_timestamp_get(VALUE self)
|
26
51
|
{
|
27
52
|
Itdb_Playlist *playlist = TYPED_DATA_PTR(self, Itdb_Playlist);
|
28
53
|
return rb_funcall(rb_cTime, rb_intern("at"), 1, INT2NUM(playlist->timestamp));
|
29
54
|
}
|
30
55
|
|
31
|
-
|
56
|
+
/*
|
57
|
+
* call-seq:
|
58
|
+
* shuffle!() -> nil
|
59
|
+
*
|
60
|
+
* Shuffles the tracks in this playlist in place.
|
61
|
+
*/
|
62
|
+
static VALUE rbpod_playlist_shuffle_bang(VALUE self)
|
32
63
|
{
|
33
64
|
Itdb_Playlist *playlist = TYPED_DATA_PTR(self, Itdb_Playlist);
|
34
65
|
itdb_playlist_randomize(playlist);
|
35
66
|
return Qnil;
|
36
67
|
}
|
37
68
|
|
69
|
+
/*
|
70
|
+
* call-seq:
|
71
|
+
* tracks() -> RbPod::Collection
|
72
|
+
*
|
73
|
+
* Returns a collection of the tracks in this playlist.
|
74
|
+
*/
|
38
75
|
static VALUE rbpod_playlist_tracks_get(VALUE self)
|
39
76
|
{
|
40
77
|
Itdb_Playlist *playlist = TYPED_DATA_PTR(self, Itdb_Playlist);
|
41
78
|
return rbpod_track_collection_create(self, playlist->members);
|
42
79
|
}
|
43
80
|
|
81
|
+
/*
|
82
|
+
* call-seq:
|
83
|
+
* length() -> Integer
|
84
|
+
*
|
85
|
+
* Returns the total number of tracks in this playlist.
|
86
|
+
*/
|
44
87
|
static VALUE rbpod_playlist_length_get(VALUE self)
|
45
88
|
{
|
46
89
|
Itdb_Playlist *playlist = TYPED_DATA_PTR(self, Itdb_Playlist);
|
47
90
|
return INT2NUM(itdb_playlist_tracks_number(playlist));
|
48
91
|
}
|
49
92
|
|
93
|
+
/*
|
94
|
+
* call-seq:
|
95
|
+
* name() -> String
|
96
|
+
*
|
97
|
+
* Returns the name of this playlist.
|
98
|
+
*/
|
50
99
|
static VALUE rbpod_playlist_name_get(VALUE self)
|
51
100
|
{
|
52
101
|
Itdb_Playlist *playlist = TYPED_DATA_PTR(self, Itdb_Playlist);
|
53
102
|
return rb_str_new2(playlist->name);
|
54
103
|
}
|
55
104
|
|
105
|
+
/*
|
106
|
+
* call-seq:
|
107
|
+
* <=>(other) -> Integer
|
108
|
+
*
|
109
|
+
* Compares two playlists based on their names.
|
110
|
+
*/
|
111
|
+
static VALUE rbpod_playlist_compare(VALUE self, VALUE other)
|
112
|
+
{
|
113
|
+
VALUE this_playlist_name, other_playlist_name;
|
114
|
+
|
115
|
+
if (rb_class_of(other) != cRbPodPlaylist) {
|
116
|
+
rb_raise(eRbPodError, "Can't compare a Playlist with %s", StringValueCStr(other));
|
117
|
+
return Qnil;
|
118
|
+
}
|
119
|
+
|
120
|
+
this_playlist_name = rbpod_playlist_name_get(self);
|
121
|
+
other_playlist_name = rbpod_playlist_name_get(other);
|
122
|
+
|
123
|
+
return rb_str_cmp(this_playlist_name, other_playlist_name);
|
124
|
+
}
|
125
|
+
|
126
|
+
/*
|
127
|
+
* call-seq:
|
128
|
+
* id() -> Fixnum
|
129
|
+
*
|
130
|
+
* Returns the internal ID number for this playlist. Do not use this method.
|
131
|
+
*/
|
56
132
|
static VALUE rbpod_playlist_id_get(VALUE self)
|
57
133
|
{
|
58
134
|
Itdb_Playlist *playlist = TYPED_DATA_PTR(self, Itdb_Playlist);
|
59
135
|
return INT2NUM(playlist->id);
|
60
136
|
}
|
61
137
|
|
138
|
+
/*
|
139
|
+
* call-seq:
|
140
|
+
* initialize(name, is_smart_playlist) -> RbPod::Playlist
|
141
|
+
*
|
142
|
+
* Creates a detached playlist. (Not managed by the database.)
|
143
|
+
*/
|
62
144
|
static VALUE rbpod_playlist_initialize(VALUE self, VALUE playlist_name, VALUE smart_playlist)
|
63
145
|
{
|
64
146
|
Itdb_Playlist *playlist = TYPED_DATA_PTR(self, Itdb_Playlist);
|
65
147
|
gchar *_playlist_name = StringValueCStr(playlist_name);
|
66
148
|
|
67
|
-
/* Kill off the dummy playlist. */
|
68
149
|
itdb_playlist_free(playlist);
|
69
150
|
|
70
|
-
/* Create a new playlist based on the values provided. */
|
71
151
|
playlist = itdb_playlist_new(_playlist_name, (smart_playlist == Qtrue) ? TRUE : FALSE);
|
72
152
|
|
73
|
-
/* Store the new playlist. */
|
74
153
|
DATA_PTR(self) = playlist;
|
75
154
|
|
76
155
|
return self;
|
@@ -97,7 +176,7 @@ static VALUE rbpod_playlist_allocate(VALUE self)
|
|
97
176
|
void Init_rbpod_playlist(void)
|
98
177
|
{
|
99
178
|
#if RDOC_CAN_PARSE_DOCUMENTATION
|
100
|
-
|
179
|
+
mRbPod = rb_define_module("RbPod");
|
101
180
|
#endif
|
102
181
|
cRbPodPlaylist = rb_define_class_under(mRbPod, "Playlist", rb_cObject);
|
103
182
|
|
@@ -105,16 +184,21 @@ void Init_rbpod_playlist(void)
|
|
105
184
|
|
106
185
|
rb_define_method(cRbPodPlaylist, "initialize", rbpod_playlist_initialize, 2);
|
107
186
|
|
108
|
-
|
187
|
+
rb_define_private_method(cRbPodPlaylist, "id", rbpod_playlist_id_get, 0);
|
188
|
+
|
189
|
+
rb_define_method(cRbPodPlaylist, "<=>", rbpod_playlist_compare, 1);
|
190
|
+
|
109
191
|
rb_define_method(cRbPodPlaylist, "name", rbpod_playlist_name_get, 0);
|
110
192
|
rb_define_method(cRbPodPlaylist, "length", rbpod_playlist_length_get, 0);
|
111
193
|
rb_define_method(cRbPodPlaylist, "tracks", rbpod_playlist_tracks_get, 0);
|
112
|
-
rb_define_method(cRbPodPlaylist, "shuffle!",
|
113
|
-
rb_define_method(cRbPodPlaylist, "
|
194
|
+
rb_define_method(cRbPodPlaylist, "shuffle!", rbpod_playlist_shuffle_bang, 0);
|
195
|
+
rb_define_method(cRbPodPlaylist, "timestamp", rbpod_playlist_timestamp_get, 0);
|
196
|
+
|
197
|
+
rb_define_alias(cRbPodPlaylist, "created_on", "timestamp");
|
114
198
|
|
115
|
-
rb_define_method(cRbPodPlaylist, "
|
116
|
-
rb_define_method(cRbPodPlaylist, "
|
117
|
-
rb_define_method(cRbPodPlaylist, "
|
199
|
+
rb_define_method(cRbPodPlaylist, "is_smart_playlist?", rbpod_playlist_smart_p, 0);
|
200
|
+
rb_define_method(cRbPodPlaylist, "is_master_playlist?", rbpod_playlist_master_p, 0);
|
201
|
+
rb_define_method(cRbPodPlaylist, "is_podcast_playlist?", rbpod_playlist_podcast_p, 0);
|
118
202
|
|
119
203
|
return;
|
120
204
|
}
|
@@ -5,56 +5,77 @@
|
|
5
5
|
#include "collection.h"
|
6
6
|
#include "playlist_collection.h"
|
7
7
|
|
8
|
-
|
8
|
+
/*
|
9
|
+
* call-seq:
|
10
|
+
* database() -> RbPod::Database
|
11
|
+
*
|
12
|
+
* The database from which this collection of playlists is attached to.
|
13
|
+
*/
|
14
|
+
static VALUE rbpod_playlist_collection_database(VALUE self)
|
9
15
|
{
|
10
|
-
return rb_iv_get(self, "@
|
16
|
+
return rb_iv_get(self, "@database");
|
11
17
|
}
|
12
18
|
|
19
|
+
/*
|
20
|
+
* call-seq:
|
21
|
+
* [](index) -> RbPod::Playlist
|
22
|
+
* [](name) -> RbPod::Playlist
|
23
|
+
*
|
24
|
+
* Returns a playlist by either position or name in the collection, or nil if it wasn't found.
|
25
|
+
*/
|
13
26
|
static VALUE rbpod_playlist_collection_get(VALUE self, VALUE key)
|
14
27
|
{
|
15
|
-
VALUE parent =
|
28
|
+
VALUE parent = rbpod_playlist_collection_database(self);
|
16
29
|
Itdb_iTunesDB *database = TYPED_DATA_PTR(parent, Itdb_iTunesDB);
|
17
30
|
Itdb_Playlist *playlist = NULL;
|
31
|
+
int key_type = TYPE(key);
|
18
32
|
|
19
|
-
|
20
|
-
case T_SYMBOL:
|
21
|
-
case T_STRING:
|
33
|
+
if (key_type == T_SYMBOL || key_type == T_STRING) {
|
22
34
|
playlist = itdb_playlist_by_name(database, StringValueCStr(key));
|
23
|
-
|
24
|
-
case T_FIXNUM:
|
25
|
-
playlist = itdb_playlist_by_nr(database, FIX2INT(key));
|
26
|
-
break;
|
35
|
+
return Data_Wrap_Struct(cRbPodPlaylist, NULL, NULL, (void *) playlist);
|
27
36
|
}
|
28
37
|
|
29
|
-
if (
|
30
|
-
|
38
|
+
if (key_type == T_FIXNUM) {
|
39
|
+
playlist = itdb_playlist_by_nr(database, FIX2INT(key));
|
40
|
+
return Data_Wrap_Struct(cRbPodPlaylist, NULL, NULL, (void *) playlist);
|
31
41
|
}
|
32
42
|
|
33
|
-
return
|
43
|
+
return Qnil;
|
34
44
|
}
|
35
45
|
|
36
|
-
|
46
|
+
/*
|
47
|
+
* call-seq:
|
48
|
+
* podcast() -> RbPod::Playlist
|
49
|
+
*
|
50
|
+
* Returns the podcast playlist in this collection.
|
51
|
+
*/
|
52
|
+
static VALUE rbpod_playlist_collection_podcast_get(VALUE self)
|
37
53
|
{
|
38
|
-
VALUE parent =
|
54
|
+
VALUE parent = rbpod_playlist_collection_database(self);
|
39
55
|
Itdb_iTunesDB *database = TYPED_DATA_PTR(parent, Itdb_iTunesDB);
|
40
56
|
Itdb_Playlist *podcasts = itdb_playlist_podcasts(database);
|
41
57
|
return Data_Wrap_Struct(cRbPodPlaylist, NULL, NULL, (void *) podcasts);
|
42
58
|
}
|
43
59
|
|
60
|
+
/*
|
61
|
+
* call-seq:
|
62
|
+
* master() -> RbPod::Playlist
|
63
|
+
*
|
64
|
+
* Returns the master playlist in this collection.
|
65
|
+
*/
|
44
66
|
static VALUE rbpod_playlist_collection_master_get(VALUE self)
|
45
67
|
{
|
46
|
-
VALUE parent =
|
68
|
+
VALUE parent = rbpod_playlist_collection_database(self);
|
47
69
|
Itdb_iTunesDB *database = TYPED_DATA_PTR(parent, Itdb_iTunesDB);
|
48
70
|
Itdb_Playlist *master = itdb_playlist_mpl(database);
|
49
71
|
return Data_Wrap_Struct(cRbPodPlaylist, NULL, NULL, (void *) master);
|
50
72
|
}
|
51
73
|
|
52
|
-
inline VALUE rbpod_playlist_collection_create(VALUE
|
74
|
+
inline VALUE rbpod_playlist_collection_create(VALUE database, GList *items)
|
53
75
|
{
|
54
76
|
VALUE collection = rbpod_collection_create(items, cRbPodPlaylist);
|
55
77
|
rb_extend_object(collection, mRbPodPlaylistCollection);
|
56
|
-
|
57
|
-
rb_iv_set(collection, "@parent", parent);
|
78
|
+
rb_iv_set(collection, "@database", database);
|
58
79
|
return collection;
|
59
80
|
}
|
60
81
|
|
@@ -63,12 +84,13 @@ void Init_rbpod_playlist_collection(void)
|
|
63
84
|
#if RDOC_CAN_PARSE_DOCUMENTATION
|
64
85
|
mRbPod = rb_define_module("RbPod");
|
65
86
|
#endif
|
87
|
+
/* This module extends any collection of playlists at runtime. */
|
66
88
|
mRbPodPlaylistCollection = rb_define_module_under(mRbPod, "PlaylistCollection");
|
67
89
|
|
68
|
-
|
90
|
+
rb_define_method(mRbPodPlaylistCollection, "database", rbpod_playlist_collection_database, 0);
|
69
91
|
|
70
92
|
rb_define_method(mRbPodPlaylistCollection, "master", rbpod_playlist_collection_master_get, 0);
|
71
|
-
rb_define_method(mRbPodPlaylistCollection, "
|
93
|
+
rb_define_method(mRbPodPlaylistCollection, "podcast", rbpod_playlist_collection_podcast_get, 0);
|
72
94
|
|
73
95
|
rb_define_method(mRbPodPlaylistCollection, "[]", rbpod_playlist_collection_get, 1);
|
74
96
|
|
data/ext/rbpod/rbpod.c
CHANGED
@@ -23,6 +23,7 @@ VALUE mRbPodPlaylistCollection;
|
|
23
23
|
VALUE cRbPodTrack;
|
24
24
|
VALUE mRbPodTrackCollection;
|
25
25
|
|
26
|
+
VALUE rb_cPathname;
|
26
27
|
|
27
28
|
inline VALUE rbpod_raise_error(GError *error)
|
28
29
|
{
|
@@ -37,12 +38,28 @@ inline VALUE rbpod_raise_error(GError *error)
|
|
37
38
|
return Qnil;
|
38
39
|
}
|
39
40
|
|
41
|
+
/*
|
42
|
+
* call-seq:
|
43
|
+
* RbPod(mount_point) -> RbPod::Database
|
44
|
+
*
|
45
|
+
* A shortcut for creating an RbPod::Database instance from a mount point.
|
46
|
+
*
|
47
|
+
*/
|
48
|
+
static VALUE rbpod_load_database(VALUE self, VALUE mount_point)
|
49
|
+
{
|
50
|
+
return rb_class_new_instance(1, &mount_point, cRbPodDatabase);
|
51
|
+
}
|
52
|
+
|
40
53
|
void Init_rbpod(void)
|
41
54
|
{
|
55
|
+
/* This is the wrapper for all RbPod related classes. */
|
42
56
|
mRbPod = rb_define_module("RbPod");
|
43
57
|
|
58
|
+
/* This is a generic subclass of RuntimeError for RbPod-specific errors.*/
|
44
59
|
eRbPodError = rb_define_class_under(mRbPod, "Error", rb_eRuntimeError);
|
45
60
|
|
61
|
+
rb_cPathname = rb_const_get(rb_cObject, rb_intern("Pathname"));
|
62
|
+
|
46
63
|
Init_rbpod_database();
|
47
64
|
Init_rbpod_device();
|
48
65
|
Init_rbpod_collection();
|
@@ -51,6 +68,8 @@ void Init_rbpod(void)
|
|
51
68
|
Init_rbpod_track();
|
52
69
|
Init_rbpod_track_collection();
|
53
70
|
|
71
|
+
rb_define_global_function("RbPod", rbpod_load_database, 1);
|
72
|
+
|
54
73
|
return;
|
55
74
|
}
|
56
75
|
|