Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions Buffered.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ sub new {
my $self = $class->SUPER::new(@_);
my $v = ${*$self}{'_mixcloud'} = {};

# HTTP headers have now been acquired in a blocking way by the above, we can
# HTTP headers have now been acquired in a blocking way by the above, we can
# now enable fast download of body to a file from which we'll read further data
# but the switch of socket handler can only be done within _sysread otherwise
# we will timeout when there is a pipeline with a callback
if (Slim::Utils::Misc->can('getTempDir')) {
# we will timeout when there is a pipeline with a callback
if (Slim::Utils::Misc->can('getTempDir')) {
$v->{'fh'} = File::Temp->new( DIR => Slim::Utils::Misc::getTempDir() );
} else {
$v->{'fh'} = File::Temp->new;
}
open $v->{'rfh'}, '<', $v->{'fh'}->filename;
binmode($v->{'rfh'});

main::INFOLOG && $log->info("Using Mixcloud's own Buffered service for $_[0]->{'url'}");

return $self;
}

Expand All @@ -40,10 +40,10 @@ sub close {
my $v = ${*$self}{'_mixcloud'};

# clean buffer file and all handlers
Slim::Networking::Select::removeRead($self);
Slim::Networking::Select::removeRead($self);
$v->{'rfh'}->close;
delete $v->{'fh'};

$self->SUPER::close(@_);
}

Expand All @@ -53,17 +53,17 @@ sub close {
sub _sysread {
my $self = $_[0];
my $v = ${*$self}{'_mixcloud'};

# we are not ready to read body yet, read socket directly
return $self->SUPER::_sysread($_[1], $_[2], $_[3]) unless $v->{'rfh'};

# first, try to read from buffer file
my $readLength = $v->{'rfh'}->read($_[1], $_[2], $_[3]);
return $readLength if $readLength;

# assume that close() will be called for cleanup
return 0 if $v->{'done'};

# empty file but not done yet, try to read directly
$readLength = $self->SUPER::_sysread($_[1], $_[2], $_[3]);

Expand All @@ -73,7 +73,7 @@ sub _sysread {
Slim::Networking::Select::addRead($self, \&saveStream);
return $readLength;
}

# use EINTR because EWOULDBLOCK (although faster) may overwrite our addRead()
$! = EINTR;
return undef;
Expand All @@ -82,15 +82,15 @@ sub _sysread {
sub saveStream {
my $self = shift;
my $v = ${*$self}{'_mixcloud'};

my $bytes = $self->SUPER::_sysread(my $data, 32768);
return unless defined $bytes;

if ($bytes) {
syswrite($v->{'fh'}, $data);
$v->{'rfh'}->seek(0, 1);
$v->{'rfh'}->seek(0, 1);
} else {
Slim::Networking::Select::removeRead($self);
$v->{'done'} = 1;
Slim::Networking::Select::removeRead($self);
$v->{'done'} = 1;
}
}
}
14 changes: 2 additions & 12 deletions HTML/EN/plugins/MixCloud/settings/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,14 @@
[% WRAPPER setting title="PLUGIN_MIXCLOUD_APIKEY" desc="PLUGIN_MIXCLOUD_APIKEY_DESC" %]
<input type="text" class="stdedit" name="pref_apiKey" value="[% prefs.apiKey %]" size="40" />
<br/>
<a target="_blank" href="https://danielvijge.github.io/lms_mixcloud/app.html">Get your apiKey for Mixcloud at mixcloud.com</a>
<a target="_blank" href="https://danielvijge.github.io/lms_mixcloud/app.html">[% 'PLUGIN_MIXCLOUD_APIKEY_LINK' | getstring %]</a>
[% END %]

[% IF prefs.exists('pref_playformat') %]
[% WRAPPER setting title="PLUGIN_MIXCLOUD_PLAYMETHOD" desc="PLUGIN_MIXCLOUD_PLAYMETHOD_DESC" %]
<select name="pref_playformat" class="stdedit">
<option[% IF prefs.playformat == 'mp4' %] selected[% END %] value="mp4">Always use MP4 format</option>
<option[% IF prefs.playformat == 'mp3' %] selected[% END %] value="mp3">Use MP3 format if available</option>
</select>
[% END %]
[% END %]


[% IF prefs.exists('pref_useBuffered') %]
[% WRAPPER setting title="PLUGIN_MIXCLOUD_USEBUFFERED" desc="PLUGIN_MIXCLOUD_USEBUFFERED_DESC" %]
<input type="checkbox" [% IF prefs.pref_useBuffered %]checked="1" [% END %] class="stdedit" name="pref_useBuffered" id="useBuffered" value="1" />
[% END %]
[% END %]
[% END %]

[% WRAPPER setting title="PLUGIN_MIXCLOUD_HELPER_APPLICATION" desc="PLUGIN_MIXCLOUD_HELPER_APPLICATION_DESC" %]
<input type="radio" class="stdedit" name="pref_helper_application" id="helper_application_bundled" value="bundled"[% IF prefs.helper_application == 'bundled' %] checked="checked"[% END %] /><label for="helper_application_bundled">[% 'PLUGIN_MIXCLOUD_HELPER_APPLICATION_BUNDLED' | getstring %]</label><br/>
Expand Down
Loading