| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package WebService::8tracks::Session; |
|
2
|
3
|
|
|
3
|
|
16
|
use Any::Moose; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
90
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=pod |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
WebService::8tracks::Session - 8tracks mix playing session |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $session = $api->create_session($mix_id); # start playing mix |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# to start playing |
|
15
|
|
|
|
|
|
|
my $res = $session->play; |
|
16
|
|
|
|
|
|
|
my $media_url = $res->{set}->{track}->{url}; |
|
17
|
|
|
|
|
|
|
... |
|
18
|
|
|
|
|
|
|
# to play next track |
|
19
|
|
|
|
|
|
|
$res = $session->next; |
|
20
|
|
|
|
|
|
|
... |
|
21
|
|
|
|
|
|
|
# to skip a track |
|
22
|
|
|
|
|
|
|
$res = $session->skip; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
if ($res->{set}->{at_end}) { |
|
25
|
|
|
|
|
|
|
# played all tracks, does not contain URL |
|
26
|
|
|
|
|
|
|
... |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
has 'api', ( |
|
32
|
|
|
|
|
|
|
is => 'rw', |
|
33
|
|
|
|
|
|
|
isa => 'WebService::8tracks', |
|
34
|
|
|
|
|
|
|
required => 1, |
|
35
|
|
|
|
|
|
|
); |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
has 'mix_id', ( |
|
38
|
|
|
|
|
|
|
is => 'rw', |
|
39
|
|
|
|
|
|
|
isa => 'Str', |
|
40
|
|
|
|
|
|
|
required => 1, |
|
41
|
|
|
|
|
|
|
); |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
has 'play_token', ( |
|
44
|
|
|
|
|
|
|
is => 'rw', |
|
45
|
|
|
|
|
|
|
isa => 'Str', |
|
46
|
|
|
|
|
|
|
required => 1, |
|
47
|
|
|
|
|
|
|
); |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
has '_started', ( |
|
50
|
|
|
|
|
|
|
is => 'rw', |
|
51
|
|
|
|
|
|
|
isa => 'Bool', |
|
52
|
|
|
|
|
|
|
default => 0, |
|
53
|
|
|
|
|
|
|
); |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
has 'at_beginning', ( |
|
56
|
|
|
|
|
|
|
is => 'rw', |
|
57
|
|
|
|
|
|
|
isa => 'Bool', |
|
58
|
|
|
|
|
|
|
default => 0, |
|
59
|
|
|
|
|
|
|
); |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
has 'at_end', ( |
|
62
|
|
|
|
|
|
|
is => 'rw', |
|
63
|
|
|
|
|
|
|
isa => 'Bool', |
|
64
|
|
|
|
|
|
|
default => 0, |
|
65
|
|
|
|
|
|
|
); |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
68
|
|
|
|
|
|
|
|
|
69
|
3
|
|
|
3
|
|
1489
|
no Any::Moose; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
12
|
|
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub update_status { |
|
72
|
10
|
|
|
10
|
0
|
16
|
my ($self, $res) = @_; |
|
73
|
|
|
|
|
|
|
|
|
74
|
10
|
|
|
|
|
18
|
foreach (qw(at_beginning at_end)) { |
|
75
|
20
|
100
|
|
|
|
231
|
$self->$_(!!$res->{set}->{$_}) if defined $res->{set}->{$_}; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub execute { |
|
80
|
10
|
|
|
10
|
0
|
18
|
my ($self, $command) = @_; |
|
81
|
|
|
|
|
|
|
|
|
82
|
10
|
|
|
|
|
96
|
my $res = $self->api->request_api( |
|
83
|
|
|
|
|
|
|
GET => "sets/$self->{play_token}/$command", |
|
84
|
|
|
|
|
|
|
{ mix_id => $self->mix_id }, |
|
85
|
|
|
|
|
|
|
); |
|
86
|
10
|
|
|
|
|
36
|
$self->update_status($res); |
|
87
|
10
|
|
|
|
|
100
|
return $res; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 METHODS |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=over 4 |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=item play |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
my $res = $session->play; |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Start playing. |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub play { |
|
103
|
1
|
|
|
1
|
1
|
6
|
my $self = shift; |
|
104
|
1
|
|
|
|
|
6
|
$self->_started(1); |
|
105
|
1
|
|
|
|
|
4
|
return $self->execute('play'); |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item next |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
my $res = $session->next; |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Go to next track. Calls play() if playing is not started. |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub next { |
|
117
|
6
|
|
|
6
|
1
|
101
|
my $self = shift; |
|
118
|
6
|
50
|
|
|
|
27
|
if ($self->_started) { |
|
119
|
6
|
|
|
|
|
16
|
return $self->execute('next'); |
|
120
|
|
|
|
|
|
|
} else { |
|
121
|
0
|
|
|
|
|
0
|
$self->_started(1); |
|
122
|
0
|
|
|
|
|
0
|
return $self->execute('play'); |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item skip |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
my $res = $session->skip; |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Skip to next track. |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=back |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub skip { |
|
137
|
3
|
|
|
3
|
1
|
48
|
my $self = shift; |
|
138
|
3
|
|
|
|
|
10
|
return $self->execute('skip'); |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
1; |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
__END__ |