mockspotify 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +27 -0
- data/Gemfile +4 -0
- data/Makefile.am +3 -0
- data/README.rst +55 -0
- data/Rakefile +16 -0
- data/autogen.sh +4 -0
- data/configure.ac +10 -0
- data/lib/mockspotify.rb +11 -0
- data/mockspotify.gemspec +18 -0
- data/src/Makefile.am +18 -0
- data/src/album.c +77 -0
- data/src/albumbrowse.c +77 -0
- data/src/artist.c +41 -0
- data/src/artistbrowse.c +110 -0
- data/src/error.c +12 -0
- data/src/extconf.rb +5 -0
- data/src/image.c +89 -0
- data/src/libmockspotify.h +168 -0
- data/src/link.c +77 -0
- data/src/playlist.c +165 -0
- data/src/search.c +128 -0
- data/src/session.c +73 -0
- data/src/track.c +130 -0
- data/src/user.c +69 -0
- data/src/util.c +11 -0
- data/src/util.h +12 -0
- data/test/mockspotify_spec.rb +12 -0
- metadata +73 -0
data/.gitignore
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
Makefile
|
2
|
+
Makefile.in
|
3
|
+
aclocal.m4
|
4
|
+
autom4te.cache/
|
5
|
+
config.guess
|
6
|
+
config.h
|
7
|
+
config.h.in
|
8
|
+
config.log
|
9
|
+
config.status
|
10
|
+
config.sub
|
11
|
+
configure
|
12
|
+
depcomp
|
13
|
+
install-sh
|
14
|
+
libtool
|
15
|
+
ltmain.sh
|
16
|
+
m4/
|
17
|
+
missing
|
18
|
+
src/.deps/
|
19
|
+
src/.libs/
|
20
|
+
src/*.o
|
21
|
+
src/*.la
|
22
|
+
src/*.lo
|
23
|
+
src/Makefile
|
24
|
+
src/Makefile.in
|
25
|
+
stamp-h1
|
26
|
+
*.bundle
|
27
|
+
pkg/
|
data/Gemfile
ADDED
data/Makefile.am
ADDED
data/README.rst
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
libmockspotify
|
2
|
+
==============
|
3
|
+
|
4
|
+
A mock of libspotify for use in development of language bindings.
|
5
|
+
|
6
|
+
This project was started in July 2011 with the goal of splitting out
|
7
|
+
pyspotify's mock of libspotify, so that it could be reused by the developers of
|
8
|
+
the Node.js and Ruby bindings for libspotify.
|
9
|
+
|
10
|
+
Coordination of the development efforts happens on GitHub and #spotify on
|
11
|
+
Freenode.
|
12
|
+
|
13
|
+
Note about my fork
|
14
|
+
------------------
|
15
|
+
To ease usage in my own development, I’ve turned this project into a
|
16
|
+
Ruby gem. This allows you to install it as a gem, and also allows you
|
17
|
+
to retrieve the path to the compiled binary.
|
18
|
+
|
19
|
+
Installing it as a gem:
|
20
|
+
|
21
|
+
::
|
22
|
+
|
23
|
+
gem install mockspotify
|
24
|
+
|
25
|
+
Using its’ API (one method):
|
26
|
+
|
27
|
+
::
|
28
|
+
|
29
|
+
require 'mockspotify'
|
30
|
+
MockSpotify.lib_path # => path/to/gem/src/libmockspotify.extension
|
31
|
+
|
32
|
+
You can then use this to bind this library using Ruby FFI:
|
33
|
+
|
34
|
+
::
|
35
|
+
|
36
|
+
require 'ffi'
|
37
|
+
require 'mockspotify'
|
38
|
+
|
39
|
+
module Spotify
|
40
|
+
extend FFI::Library
|
41
|
+
ffi_lib MockSpotify.lib_path
|
42
|
+
|
43
|
+
attach_function …, etc
|
44
|
+
end
|
45
|
+
|
46
|
+
Manual compilation
|
47
|
+
------------------
|
48
|
+
If you ever want to do it, here you go:
|
49
|
+
|
50
|
+
::
|
51
|
+
|
52
|
+
$ ./autogen.sh
|
53
|
+
$ ./configure
|
54
|
+
$ make
|
55
|
+
# make install
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
|
4
|
+
task :compile do
|
5
|
+
Dir.chdir('src') do
|
6
|
+
sh 'ruby extconf.rb'
|
7
|
+
sh 'make'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'rake/testtask'
|
12
|
+
Rake::TestTask.new do |t|
|
13
|
+
t.pattern = 'test/*_spec.rb'
|
14
|
+
end
|
15
|
+
|
16
|
+
task :test => :compile
|
data/autogen.sh
ADDED
data/configure.ac
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
AC_INIT([libmockspotify], [0.1], [http://github.com/mopidy/libmockspotify])
|
2
|
+
AM_INIT_AUTOMAKE([foreign -Wall -Werror])
|
3
|
+
|
4
|
+
AC_PROG_CC
|
5
|
+
AC_PROG_LIBTOOL
|
6
|
+
|
7
|
+
AC_CONFIG_MACRO_DIR([m4])
|
8
|
+
AC_CONFIG_HEADERS([config.h])
|
9
|
+
AC_CONFIG_FILES([Makefile src/Makefile])
|
10
|
+
AC_OUTPUT
|
data/lib/mockspotify.rb
ADDED
data/mockspotify.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/mockspotify', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "mockspotify"
|
6
|
+
gem.summary = %Q{A mock of libspotify for use in development of language bindings}
|
7
|
+
gem.homepage = "https://github.com/Burgestrand/libmockspotify"
|
8
|
+
gem.authors = ["Kim Burgestrand"]
|
9
|
+
gem.email = 'kim@burgestrand.se'
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split("\n")
|
12
|
+
gem.executables = []
|
13
|
+
gem.require_paths = ["lib", "src"]
|
14
|
+
gem.extensions << 'src/extconf.rb'
|
15
|
+
|
16
|
+
gem.version = MockSpotify::VERSION
|
17
|
+
gem.platform = Gem::Platform::RUBY
|
18
|
+
end
|
data/src/Makefile.am
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
lib_LTLIBRARIES = libmockspotify.la
|
2
|
+
include_HEADERS = libmockspotify.h
|
3
|
+
|
4
|
+
AM_CFLAGS = -Wall
|
5
|
+
|
6
|
+
libmockspotify_la_SOURCES = album.c \
|
7
|
+
albumbrowse.c \
|
8
|
+
artist.c \
|
9
|
+
artistbrowse.c \
|
10
|
+
error.c \
|
11
|
+
image.c \
|
12
|
+
link.c \
|
13
|
+
playlist.c \
|
14
|
+
search.c \
|
15
|
+
session.c \
|
16
|
+
track.c \
|
17
|
+
user.c \
|
18
|
+
util.c
|
data/src/album.c
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
#include <stdlib.h>
|
2
|
+
#include <string.h>
|
3
|
+
#include "libmockspotify.h"
|
4
|
+
|
5
|
+
/*** MockSpotify API ***/
|
6
|
+
|
7
|
+
sp_album *
|
8
|
+
mocksp_album_create(char *name, sp_artist *artist, int year, byte * cover,
|
9
|
+
int type, int loaded, int available)
|
10
|
+
{
|
11
|
+
sp_album *a;
|
12
|
+
|
13
|
+
a = malloc(sizeof(sp_album));
|
14
|
+
memset(a, 0, sizeof(sp_album));
|
15
|
+
strcpy(a->name, name);
|
16
|
+
a->artist = artist;
|
17
|
+
a->year = year;
|
18
|
+
memcpy(a->cover, cover, 20);
|
19
|
+
a->type = type;
|
20
|
+
a->loaded = loaded;
|
21
|
+
a->available = available;
|
22
|
+
return a;
|
23
|
+
}
|
24
|
+
|
25
|
+
/*** Spotify API ***/
|
26
|
+
|
27
|
+
void
|
28
|
+
sp_album_add_ref(sp_album *a)
|
29
|
+
{
|
30
|
+
}
|
31
|
+
|
32
|
+
void
|
33
|
+
sp_album_release(sp_album *a)
|
34
|
+
{
|
35
|
+
}
|
36
|
+
|
37
|
+
bool
|
38
|
+
sp_album_is_loaded(sp_album *a)
|
39
|
+
{
|
40
|
+
return a->loaded;
|
41
|
+
}
|
42
|
+
|
43
|
+
bool
|
44
|
+
sp_album_is_available(sp_album *a)
|
45
|
+
{
|
46
|
+
return a->available;
|
47
|
+
}
|
48
|
+
|
49
|
+
sp_artist *
|
50
|
+
sp_album_artist(sp_album *a)
|
51
|
+
{
|
52
|
+
return a->artist;
|
53
|
+
}
|
54
|
+
|
55
|
+
const byte *
|
56
|
+
sp_album_cover(sp_album *a)
|
57
|
+
{
|
58
|
+
return a->cover;
|
59
|
+
}
|
60
|
+
|
61
|
+
const char *
|
62
|
+
sp_album_name(sp_album *a)
|
63
|
+
{
|
64
|
+
return a->name;
|
65
|
+
}
|
66
|
+
|
67
|
+
int
|
68
|
+
sp_album_year(sp_album *a)
|
69
|
+
{
|
70
|
+
return a->year;
|
71
|
+
}
|
72
|
+
|
73
|
+
sp_albumtype
|
74
|
+
sp_album_type(sp_album *a)
|
75
|
+
{
|
76
|
+
return a->type;
|
77
|
+
}
|
data/src/albumbrowse.c
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
#include <stdlib.h>
|
2
|
+
#include <string.h>
|
3
|
+
#include "libmockspotify.h"
|
4
|
+
|
5
|
+
/*** MockSpotify API ***/
|
6
|
+
|
7
|
+
sp_albumbrowse *
|
8
|
+
mocksp_albumbrowse_create(sp_album *album, bool loaded)
|
9
|
+
{
|
10
|
+
sp_albumbrowse *ab;
|
11
|
+
|
12
|
+
ab = malloc(sizeof(sp_albumbrowse));
|
13
|
+
ab->loaded = loaded;
|
14
|
+
ab->album = album;
|
15
|
+
return ab;
|
16
|
+
}
|
17
|
+
|
18
|
+
/*** Spotify API ***/
|
19
|
+
|
20
|
+
void
|
21
|
+
sp_albumbrowse_add_ref(sp_albumbrowse *ab)
|
22
|
+
{
|
23
|
+
}
|
24
|
+
|
25
|
+
void
|
26
|
+
sp_albumbrowse_release(sp_albumbrowse *ab)
|
27
|
+
{
|
28
|
+
}
|
29
|
+
|
30
|
+
sp_track *
|
31
|
+
sp_albumbrowse_track(sp_albumbrowse *ab, int index)
|
32
|
+
{
|
33
|
+
sp_track *track;
|
34
|
+
|
35
|
+
switch (index) {
|
36
|
+
case 0:
|
37
|
+
track = mocksp_track_create("foo", 1, &(ab->album->artist), ab->album,
|
38
|
+
123, 0, 1, 1, SP_ERROR_OK, 1);
|
39
|
+
break;
|
40
|
+
case 1:
|
41
|
+
track = mocksp_track_create("bar", 1, &(ab->album->artist), ab->album,
|
42
|
+
123, 0, 1, 2, SP_ERROR_OK, 1);
|
43
|
+
break;
|
44
|
+
case 2:
|
45
|
+
track = mocksp_track_create("baz", 1, &(ab->album->artist), ab->album,
|
46
|
+
123, 0, 1, 3, SP_ERROR_OK, 1);
|
47
|
+
break;
|
48
|
+
default:
|
49
|
+
track = NULL;
|
50
|
+
break;
|
51
|
+
}
|
52
|
+
return track;
|
53
|
+
}
|
54
|
+
|
55
|
+
int
|
56
|
+
sp_albumbrowse_num_tracks(sp_albumbrowse *ab)
|
57
|
+
{
|
58
|
+
return 3;
|
59
|
+
}
|
60
|
+
|
61
|
+
bool
|
62
|
+
sp_albumbrowse_is_loaded(sp_albumbrowse *ab)
|
63
|
+
{
|
64
|
+
return ab->loaded;
|
65
|
+
}
|
66
|
+
|
67
|
+
sp_albumbrowse *
|
68
|
+
sp_albumbrowse_create(sp_session *s, sp_album *a,
|
69
|
+
albumbrowse_complete_cb cb, void *userdata)
|
70
|
+
{
|
71
|
+
sp_albumbrowse *ab;
|
72
|
+
|
73
|
+
ab = mocksp_albumbrowse_create(a, 1);
|
74
|
+
if (cb)
|
75
|
+
cb(ab, userdata);
|
76
|
+
return ab;
|
77
|
+
}
|
data/src/artist.c
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
#include <stdlib.h>
|
2
|
+
#include <string.h>
|
3
|
+
#include "libmockspotify.h"
|
4
|
+
|
5
|
+
/*** MockSpotify API ***/
|
6
|
+
|
7
|
+
sp_artist *
|
8
|
+
mocksp_artist_create(const char *name, int loaded)
|
9
|
+
{
|
10
|
+
sp_artist *a;
|
11
|
+
|
12
|
+
a = malloc(sizeof(sp_artist));
|
13
|
+
memset(a, 0, sizeof(sp_artist));
|
14
|
+
strcpy(a->name, name);
|
15
|
+
a->loaded = loaded;
|
16
|
+
return a;
|
17
|
+
}
|
18
|
+
|
19
|
+
/*** Spotify API ***/
|
20
|
+
|
21
|
+
void
|
22
|
+
sp_artist_add_ref(sp_artist *a)
|
23
|
+
{
|
24
|
+
}
|
25
|
+
|
26
|
+
const char *
|
27
|
+
sp_artist_name(sp_artist *a)
|
28
|
+
{
|
29
|
+
return a->name;
|
30
|
+
}
|
31
|
+
|
32
|
+
bool
|
33
|
+
sp_artist_is_loaded(sp_artist *a)
|
34
|
+
{
|
35
|
+
return a->loaded;
|
36
|
+
}
|
37
|
+
|
38
|
+
void
|
39
|
+
sp_artist_release(sp_artist *a)
|
40
|
+
{
|
41
|
+
}
|
data/src/artistbrowse.c
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
#include <stdlib.h>
|
2
|
+
#include "libmockspotify.h"
|
3
|
+
|
4
|
+
/*** MockSpotify API ***/
|
5
|
+
|
6
|
+
sp_artistbrowse *
|
7
|
+
mocksp_artistbrowse_create(sp_artist * artist, bool loaded)
|
8
|
+
{
|
9
|
+
sp_artistbrowse *ab;
|
10
|
+
|
11
|
+
ab = malloc(sizeof(sp_artistbrowse));
|
12
|
+
ab->loaded = loaded;
|
13
|
+
ab->artist = artist;
|
14
|
+
return ab;
|
15
|
+
}
|
16
|
+
|
17
|
+
/*** Spotify API ***/
|
18
|
+
|
19
|
+
void
|
20
|
+
sp_artistbrowse_add_ref(sp_artistbrowse * ab)
|
21
|
+
{
|
22
|
+
}
|
23
|
+
|
24
|
+
void
|
25
|
+
sp_artistbrowse_release(sp_artistbrowse * ab)
|
26
|
+
{
|
27
|
+
}
|
28
|
+
|
29
|
+
sp_artistbrowse *
|
30
|
+
sp_artistbrowse_create(sp_session * s, sp_artist * a,
|
31
|
+
artistbrowse_complete_cb cb, void *userdata)
|
32
|
+
{
|
33
|
+
sp_artistbrowse *ab;
|
34
|
+
|
35
|
+
ab = mocksp_artistbrowse_create(a, 1);
|
36
|
+
if (cb)
|
37
|
+
cb(ab, userdata);
|
38
|
+
return ab;
|
39
|
+
}
|
40
|
+
|
41
|
+
sp_track *
|
42
|
+
sp_artistbrowse_track(sp_artistbrowse * ab, int index)
|
43
|
+
{
|
44
|
+
sp_album *album;
|
45
|
+
sp_track *track;
|
46
|
+
|
47
|
+
album = mocksp_album_create("fool-album", ab->artist, 2001,
|
48
|
+
(byte *) "01234567890123456789", 1, 1, 1);
|
49
|
+
switch (index) {
|
50
|
+
case 0:
|
51
|
+
track = mocksp_track_create("foo", 1, &(album->artist), album,
|
52
|
+
123, 0, 1, 1, SP_ERROR_OK, 1);
|
53
|
+
break;
|
54
|
+
case 1:
|
55
|
+
track = mocksp_track_create("bar", 1, &(album->artist), album,
|
56
|
+
123, 0, 1, 2, SP_ERROR_OK, 1);
|
57
|
+
break;
|
58
|
+
case 2:
|
59
|
+
track = mocksp_track_create("baz", 1, &(album->artist), album,
|
60
|
+
123, 0, 1, 3, SP_ERROR_OK, 1);
|
61
|
+
break;
|
62
|
+
default:
|
63
|
+
track = NULL;
|
64
|
+
break;
|
65
|
+
}
|
66
|
+
return track;
|
67
|
+
}
|
68
|
+
|
69
|
+
sp_album *
|
70
|
+
sp_artistbrowse_album(sp_artistbrowse * ab, int index)
|
71
|
+
{
|
72
|
+
sp_album *album;
|
73
|
+
|
74
|
+
switch (index) {
|
75
|
+
case 0:
|
76
|
+
album = mocksp_album_create("foo", ab->artist, 2001,
|
77
|
+
(byte *) "01234567890123456789", 1, 1, 1);
|
78
|
+
break;
|
79
|
+
case 1:
|
80
|
+
album = mocksp_album_create("bar", ab->artist, 2002,
|
81
|
+
(byte *) "01234567890123456789", 1, 1, 1);
|
82
|
+
break;
|
83
|
+
case 2:
|
84
|
+
album = mocksp_album_create("baz", ab->artist, 2003,
|
85
|
+
(byte *) "01234567890123456789", 1, 1, 1);
|
86
|
+
break;
|
87
|
+
default:
|
88
|
+
album = NULL;
|
89
|
+
break;
|
90
|
+
}
|
91
|
+
return album;
|
92
|
+
}
|
93
|
+
|
94
|
+
int
|
95
|
+
sp_artistbrowse_num_albums(sp_artistbrowse * ab)
|
96
|
+
{
|
97
|
+
return 3;
|
98
|
+
}
|
99
|
+
|
100
|
+
int
|
101
|
+
sp_artistbrowse_num_tracks(sp_artistbrowse * ab)
|
102
|
+
{
|
103
|
+
return 3;
|
104
|
+
}
|
105
|
+
|
106
|
+
bool
|
107
|
+
sp_artistbrowse_is_loaded(sp_artistbrowse * ab)
|
108
|
+
{
|
109
|
+
return ab->loaded;
|
110
|
+
}
|
data/src/error.c
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#include <stdio.h>
|
2
|
+
#include <stdlib.h>
|
3
|
+
#include "libmockspotify.h"
|
4
|
+
|
5
|
+
/*** MockSpotify API ***/
|
6
|
+
const char*
|
7
|
+
sp_error_message(sp_error error)
|
8
|
+
{
|
9
|
+
char *buff = malloc(20 * sizeof(char));
|
10
|
+
sprintf(buff, "sp_error: %d", error);
|
11
|
+
return buff;
|
12
|
+
}
|
data/src/extconf.rb
ADDED
data/src/image.c
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
#include "libmockspotify.h"
|
2
|
+
|
3
|
+
/*** MockSpotify API ***/
|
4
|
+
sp_image*
|
5
|
+
mocksp_image_create(const byte image_id[20], sp_imageformat format, size_t data_size, byte *data, sp_error error)
|
6
|
+
{
|
7
|
+
sp_image *image = ALLOC(sp_image);
|
8
|
+
memcpy(image->image_id, image_id, 20);
|
9
|
+
image->format = format;
|
10
|
+
image->data_size = data_size;
|
11
|
+
image->data = ALLOC_N(byte, data_size + 1);
|
12
|
+
memcpy(image->data, data, data_size);
|
13
|
+
image->error = error;
|
14
|
+
return image;
|
15
|
+
}
|
16
|
+
|
17
|
+
/*** Spotify API ***/
|
18
|
+
|
19
|
+
sp_image*
|
20
|
+
sp_image_create_from_link(sp_session *session, sp_link *l)
|
21
|
+
{
|
22
|
+
byte *real_id = l->data + strlen("spotify:image:");
|
23
|
+
byte *image_id = ALLOC_N(byte, 20);
|
24
|
+
memcpy(image_id, real_id, 20);
|
25
|
+
return mocksp_image_create(image_id, SP_IMAGE_FORMAT_JPEG, 0, NULL, SP_ERROR_OK);
|
26
|
+
}
|
27
|
+
|
28
|
+
void
|
29
|
+
sp_image_add_ref(sp_image *image)
|
30
|
+
{
|
31
|
+
}
|
32
|
+
|
33
|
+
void
|
34
|
+
sp_image_release(sp_image *image)
|
35
|
+
{
|
36
|
+
}
|
37
|
+
|
38
|
+
bool
|
39
|
+
sp_image_is_loaded(sp_image *i)
|
40
|
+
{
|
41
|
+
return sp_image_error(i) == SP_ERROR_OK;
|
42
|
+
}
|
43
|
+
|
44
|
+
sp_imageformat
|
45
|
+
sp_image_format(sp_image *i)
|
46
|
+
{
|
47
|
+
return i->format;
|
48
|
+
}
|
49
|
+
|
50
|
+
sp_error
|
51
|
+
sp_image_error(sp_image *i)
|
52
|
+
{
|
53
|
+
return i->error;
|
54
|
+
}
|
55
|
+
|
56
|
+
const void *
|
57
|
+
sp_image_data(sp_image *i, size_t *t)
|
58
|
+
{
|
59
|
+
*t = i->data_size;
|
60
|
+
return i->data;
|
61
|
+
}
|
62
|
+
|
63
|
+
sp_image *
|
64
|
+
sp_image_create(sp_session *session, const byte image_id[20])
|
65
|
+
{
|
66
|
+
sp_image *image = ALLOC(sp_image);
|
67
|
+
memcpy(image->image_id, image_id, 20);
|
68
|
+
return image;
|
69
|
+
}
|
70
|
+
|
71
|
+
const byte*
|
72
|
+
sp_image_image_id(sp_image *i)
|
73
|
+
{
|
74
|
+
return i->image_id;
|
75
|
+
}
|
76
|
+
|
77
|
+
void
|
78
|
+
sp_image_add_load_callback(sp_image *i, image_loaded_cb *callback,
|
79
|
+
void *userdata)
|
80
|
+
{
|
81
|
+
/* TODO */
|
82
|
+
}
|
83
|
+
|
84
|
+
void
|
85
|
+
sp_image_remove_load_callback(sp_image *i, image_loaded_cb *callback,
|
86
|
+
void *userdata)
|
87
|
+
{
|
88
|
+
/* TODO */
|
89
|
+
}
|