-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProtocolHandler.pm
More file actions
75 lines (52 loc) · 1.4 KB
/
ProtocolHandler.pm
File metadata and controls
75 lines (52 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package Plugins::LastMix::ProtocolHandler;
use strict;
use URI;
use URI::QueryParam;
use Plugins::LastMix::LFM;
sub overridePlayback {
my ( $class, $client, $url ) = @_;
return unless $client;
if ( Slim::Player::Source::streamingSongIndex($client) ) {
# don't start immediately if we're part of a playlist and previous track isn't done playing
return if $client->controller()->playingSongDuration()
}
my ($command) = $url =~ m{^lastmix://(play|add)\?};
return unless $command;
my $uri = URI->new($url);
my $params = $uri->query_form_hash;
my $cmd = ['lastmix', $command];
push @$cmd, 'dstm:1' if $params->{dstm};
if (my $artist = $params->{artist}) {
push @$cmd, "artist:$artist";
}
elsif (my $tags = $params->{tags}) {
push @$cmd, "tags:$tags";
}
else {
return;
}
$client->execute($cmd);
return 1;
}
sub canDirectStream { 0 }
sub contentType { 'lmx' }
sub isRemote { 0 }
sub getMetadataFor {
my ( $class, $client, $url ) = @_;
return unless $client && $url;
my $title = $client->string('PLUGIN_LASTMIX_NAME');
if ( my ($arguments) = $url =~ m{lastmix://(?:play|add|tags)\?.*(?:tags|artist)=(.*)} ) {
$title .= ' (' . join(', ', map {
s/^\s+|\s+$//g;
ucfirst(URI::Escape::uri_unescape($_))
} split(',', $arguments)) . ')';
}
return {
title => $title,
cover => $class->getIcon(),
};
}
sub getIcon {
return Plugins::LastMix::Plugin->_pluginDataFor('icon');
}
1;