rbpod 0.0.3 → 0.0.4
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 +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/track.c
CHANGED
@@ -3,48 +3,121 @@
|
|
3
3
|
#include "rbpod.h"
|
4
4
|
#include "track.h"
|
5
5
|
|
6
|
+
/*
|
7
|
+
* call-seq:
|
8
|
+
* transferred?() -> Boolean
|
9
|
+
*
|
10
|
+
* Returns true or false if this track has been transferred to the device.
|
11
|
+
*/
|
6
12
|
static VALUE rbpod_track_transferred_p(VALUE self)
|
7
13
|
{
|
8
14
|
Itdb_Track *track = TYPED_DATA_PTR(self, Itdb_Track);
|
9
15
|
return BooleanValue(track->transferred);
|
10
16
|
}
|
11
17
|
|
12
|
-
|
18
|
+
/*
|
19
|
+
* call-seq:
|
20
|
+
* path() -> String
|
21
|
+
*
|
22
|
+
* Returns the full path to the file backing this track on the device.
|
23
|
+
*/
|
24
|
+
static VALUE rbpod_track_path_get(VALUE self)
|
13
25
|
{
|
14
26
|
Itdb_Track *track = TYPED_DATA_PTR(self, Itdb_Track);
|
15
|
-
|
27
|
+
VALUE mount_point, path_parts, file_path, full_path;
|
28
|
+
Itdb_iTunesDB *database = track->itdb;
|
29
|
+
const gchar *ipod_path = NULL;
|
30
|
+
|
31
|
+
/* Never hurts to be careful, right? */
|
32
|
+
if (database == NULL || track->ipod_path == NULL) {
|
33
|
+
return Qnil;
|
34
|
+
}
|
35
|
+
|
36
|
+
/* Skip the prepended directory separator. */
|
37
|
+
ipod_path = (const gchar *) &track->ipod_path[1];
|
38
|
+
|
39
|
+
/* Extract the iPod mount point from the database pointer. */
|
40
|
+
mount_point = rb_str_new2(itdb_get_mountpoint(database));
|
41
|
+
|
42
|
+
/* Split the track's ipod_path by ':' character. */
|
43
|
+
path_parts = rb_str_split(rb_str_new2(ipod_path), ":");
|
44
|
+
|
45
|
+
/* Use File.join to rejoin the path safely. */
|
46
|
+
file_path = rb_funcall2(rb_cFile, rb_intern("join"), 1, &path_parts);
|
47
|
+
|
48
|
+
/* Retrieve the expanded absolute path name. */
|
49
|
+
full_path = rb_file_expand_path(file_path, mount_point);
|
50
|
+
|
51
|
+
/* Return a Pathname instance for the resolved path. */
|
52
|
+
return rb_class_new_instance(1, &full_path, rb_cPathname);
|
16
53
|
}
|
17
54
|
|
18
|
-
|
55
|
+
/*
|
56
|
+
* call-seq:
|
57
|
+
* type() -> String
|
58
|
+
*
|
59
|
+
* Returns a human-readable string describing the content of the track.
|
60
|
+
*/
|
61
|
+
static VALUE rbpod_track_type_get(VALUE self)
|
19
62
|
{
|
20
63
|
Itdb_Track *track = TYPED_DATA_PTR(self, Itdb_Track);
|
21
64
|
return rb_str_new2(track->filetype);
|
22
65
|
}
|
23
66
|
|
67
|
+
/*
|
68
|
+
* call-seq:
|
69
|
+
* artist() -> String
|
70
|
+
*
|
71
|
+
* Returns the artist for the track.
|
72
|
+
*/
|
24
73
|
static VALUE rbpod_track_artist_get(VALUE self)
|
25
74
|
{
|
26
75
|
Itdb_Track *track = TYPED_DATA_PTR(self, Itdb_Track);
|
27
76
|
return rb_str_new2(track->artist);
|
28
77
|
}
|
29
78
|
|
79
|
+
/*
|
80
|
+
* call-seq:
|
81
|
+
* album() -> String
|
82
|
+
*
|
83
|
+
* Returns the album for the track.
|
84
|
+
*/
|
30
85
|
static VALUE rbpod_track_album_get(VALUE self)
|
31
86
|
{
|
32
87
|
Itdb_Track *track = TYPED_DATA_PTR(self, Itdb_Track);
|
33
88
|
return rb_str_new2(track->album);
|
34
89
|
}
|
35
90
|
|
91
|
+
/*
|
92
|
+
* call-seq:
|
93
|
+
* title() -> String
|
94
|
+
*
|
95
|
+
* Returns the title of the track.
|
96
|
+
*/
|
36
97
|
static VALUE rbpod_track_title_get(VALUE self)
|
37
98
|
{
|
38
99
|
Itdb_Track *track = TYPED_DATA_PTR(self, Itdb_Track);
|
39
100
|
return rb_str_new2(track->title);
|
40
101
|
}
|
41
102
|
|
103
|
+
/*
|
104
|
+
* call-seq:
|
105
|
+
* id() -> Fixnum
|
106
|
+
*
|
107
|
+
* Returns the internal ID number for this track. Do not use this method.
|
108
|
+
*/
|
42
109
|
static VALUE rbpod_track_id_get(VALUE self)
|
43
110
|
{
|
44
111
|
Itdb_Track *track = TYPED_DATA_PTR(self, Itdb_Track);
|
45
|
-
return
|
112
|
+
return INT2NUM(track->id);
|
46
113
|
}
|
47
114
|
|
115
|
+
/*
|
116
|
+
* call-seq:
|
117
|
+
* initialize() -> RbPod::Track
|
118
|
+
*
|
119
|
+
* Creates a detached track. (Not managed by a database.)
|
120
|
+
*/
|
48
121
|
static VALUE rbpod_track_initialize(VALUE self)
|
49
122
|
{
|
50
123
|
return self;
|
@@ -52,7 +125,13 @@ static VALUE rbpod_track_initialize(VALUE self)
|
|
52
125
|
|
53
126
|
static void rbpod_track_deallocate(void *handle)
|
54
127
|
{
|
55
|
-
|
128
|
+
Itdb_Track *track = (Itdb_Track *) handle;
|
129
|
+
|
130
|
+
/* Don't free tracks that are assigned to a playlist/database. */
|
131
|
+
if (track->itdb == NULL || track->id == 0) {
|
132
|
+
itdb_track_free((Itdb_Track *) handle);
|
133
|
+
}
|
134
|
+
|
56
135
|
return;
|
57
136
|
}
|
58
137
|
|
@@ -73,12 +152,13 @@ void Init_rbpod_track(void)
|
|
73
152
|
|
74
153
|
rb_define_method(cRbPodTrack, "initialize", rbpod_track_initialize, 0);
|
75
154
|
|
76
|
-
|
155
|
+
rb_define_private_method(cRbPodTrack, "id", rbpod_track_id_get, 0);
|
156
|
+
|
77
157
|
rb_define_method(cRbPodTrack, "title", rbpod_track_title_get, 0);
|
78
158
|
rb_define_method(cRbPodTrack, "album", rbpod_track_album_get, 0);
|
79
159
|
rb_define_method(cRbPodTrack, "artist", rbpod_track_artist_get, 0);
|
80
|
-
rb_define_method(cRbPodTrack, "
|
81
|
-
rb_define_method(cRbPodTrack, "
|
160
|
+
rb_define_method(cRbPodTrack, "type", rbpod_track_type_get, 0);
|
161
|
+
rb_define_method(cRbPodTrack, "path", rbpod_track_path_get, 0);
|
82
162
|
|
83
163
|
rb_define_method(cRbPodTrack, "transferred?", rbpod_track_transferred_p, 0);
|
84
164
|
|
@@ -5,17 +5,22 @@
|
|
5
5
|
#include "collection.h"
|
6
6
|
#include "track_collection.h"
|
7
7
|
|
8
|
-
|
8
|
+
/*
|
9
|
+
* call-seq:
|
10
|
+
* playlist() -> RbPod::Playlist
|
11
|
+
*
|
12
|
+
* The playlist from which this collection of tracks is attached to.
|
13
|
+
*/
|
14
|
+
static VALUE rbpod_track_collection_playlist(VALUE self)
|
9
15
|
{
|
10
|
-
return rb_iv_get(self, "@
|
16
|
+
return rb_iv_get(self, "@pkaylist");
|
11
17
|
}
|
12
18
|
|
13
|
-
inline VALUE rbpod_track_collection_create(VALUE
|
19
|
+
inline VALUE rbpod_track_collection_create(VALUE playlist, GList *items)
|
14
20
|
{
|
15
21
|
VALUE collection = rbpod_collection_create(items, cRbPodTrack);
|
16
22
|
rb_extend_object(collection, mRbPodTrackCollection);
|
17
|
-
|
18
|
-
rb_iv_set(collection, "@parent", parent);
|
23
|
+
rb_iv_set(collection, "@playlist", playlist);
|
19
24
|
return collection;
|
20
25
|
}
|
21
26
|
|
@@ -24,9 +29,10 @@ void Init_rbpod_track_collection(void)
|
|
24
29
|
#if RDOC_CAN_PARSE_DOCUMENTATION
|
25
30
|
mRbPod = rb_define_module("RbPod");
|
26
31
|
#endif
|
32
|
+
/* This module extends any collection of tracks at runtime. */
|
27
33
|
mRbPodTrackCollection = rb_define_module_under(mRbPod, "TrackCollection");
|
28
34
|
|
29
|
-
|
35
|
+
rb_define_method(mRbPodTrackCollection, "playlist", rbpod_track_collection_playlist, 0);
|
30
36
|
|
31
37
|
return;
|
32
38
|
}
|
data/lib/rbpod/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module RbPod
|
2
|
-
VERSION = "0.0.
|
1
|
+
module RbPod # :nodoc:
|
2
|
+
VERSION = "0.0.4" # :nodoc:
|
3
3
|
end
|
data/spec/collection_spec.rb
CHANGED
@@ -17,8 +17,8 @@ describe RbPod::Collection do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
describe '#each' do
|
20
|
-
it 'should yield to a block and return
|
21
|
-
@collection.each(&@block).
|
20
|
+
it 'should yield to a block and return itself' do
|
21
|
+
@collection.each(&@block).should_not be_nil
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'should return an Enumerator without a block' do
|
data/spec/database_spec.rb
CHANGED
@@ -52,7 +52,7 @@ describe RbPod::Database do
|
|
52
52
|
|
53
53
|
describe '#mountpoint' do
|
54
54
|
it 'should match the mount point it was loaded from' do
|
55
|
-
@database.mountpoint.should == @directory
|
55
|
+
@database.mountpoint.to_s.should == @directory
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -74,16 +74,6 @@ describe RbPod::Database do
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
describe '#tracks' do
|
78
|
-
it 'should return a collection' do
|
79
|
-
@database.tracks.should be_instance_of(RbPod::Collection)
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'should have an empty set of tracks' do
|
83
|
-
@database.tracks.length.should == 0
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
77
|
describe '#playlists' do
|
88
78
|
it 'should return a collection' do
|
89
79
|
@database.playlists.should be_instance_of(RbPod::Collection)
|
@@ -91,7 +81,7 @@ describe RbPod::Database do
|
|
91
81
|
|
92
82
|
it 'should have a single master playlist' do
|
93
83
|
@database.playlists.length.should eq(1)
|
94
|
-
@database.playlists.first.should
|
84
|
+
@database.playlists.first.is_master_playlist?.should be_true
|
95
85
|
end
|
96
86
|
end
|
97
87
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbpod
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
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: 2013-11-
|
12
|
+
date: 2013-11-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -165,7 +165,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
165
165
|
version: '0'
|
166
166
|
segments:
|
167
167
|
- 0
|
168
|
-
hash:
|
168
|
+
hash: 1001961729
|
169
169
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
170
170
|
none: false
|
171
171
|
requirements:
|
@@ -174,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
174
174
|
version: '0'
|
175
175
|
segments:
|
176
176
|
- 0
|
177
|
-
hash:
|
177
|
+
hash: 1001961729
|
178
178
|
requirements:
|
179
179
|
- libgpod-1.0
|
180
180
|
rubyforge_project:
|